@@ -25,7 +25,8 @@ extern "C" {
* A reader/writer lock allows multiple simultaneous readers but only one
* writer at a time. A thread that wants write access will have to wait until
* there are no threads that want read access. This casues a risk for
- * starvation.
+ * starvation. The trylock variants can be used to return an indication
+ * of whether the lock and access mode was immediately available.
* @{
*/
@@ -50,6 +51,16 @@ void odp_rwlock_init(odp_rwlock_t *rwlock);
void odp_rwlock_read_lock(odp_rwlock_t *rwlock);
/**
+ * Try to acquire read permission to a reader/writer lock.
+ *
+ * $param rwlock Pointer to a reader/writer lock
+ *
+ * @retval 0 Lock was not available for read access
+ * @retval 1 Read access to lock acquired
+ */
+int odp_rwlock_read_trylock(odp_rwlock_t *rwlock);
+
+/**
* Release read permission on a reader/writer lock.
*
* @param rwlock Pointer to a reader/writer lock
@@ -64,6 +75,16 @@ void odp_rwlock_read_unlock(odp_rwlock_t *rwlock);
void odp_rwlock_write_lock(odp_rwlock_t *rwlock);
/**
+ * Try to acquire write permisssion to a reader/writer lock.
+ *
+ * @param rwlock Pointer to a reader/writer lock
+ *
+ * @retval 0 Lock was not available for write access
+ * @retval 1 Write access to lock acquired
+ */
+int odp_rwlock_write_trylock(odp_rwlock_t *rwlock);
+
+/**
* Release write permission on a reader/writer lock.
*
* @param rwlock Pointer to a reader/writer lock
@@ -35,6 +35,9 @@ extern "C" {
*
* ... but this is not supported.
* * read_lock(); write_lock(); write_unlock(); read_unlock();
+ *
+ * The trylock variants can be used to return an indication of whether the
+ * lock and access mode was immediately available.
* @{
*/
@@ -62,6 +65,16 @@ void odp_rwlock_recursive_init(odp_rwlock_recursive_t *lock);
void odp_rwlock_recursive_read_lock(odp_rwlock_recursive_t *lock);
/**
+ * Try to acquire recursive rwlock for reading
+ *
+ * @param lock Pointer to a lock
+ *
+ * @retval 0 Lock was not available for read access
+ * @retval 1 Read access to lock acquired
+ */
+int odp_rwlock_recursive_read_trylock(odp_rwlock_recursive_t *lock);
+
+/**
* Release recursive rwlock after reading
*
* @param lock Pointer to a lock
@@ -80,6 +93,16 @@ void odp_rwlock_recursive_read_unlock(odp_rwlock_recursive_t *lock);
void odp_rwlock_recursive_write_lock(odp_rwlock_recursive_t *lock);
/**
+ * Try to acquire recursive rwlock for writing
+ *
+ * @param lock Pointer to a lock
+ *
+ * @retval 0 Lock was not available for write access
+ * @retval 1 Write access to lock acquired
+ */
+int odp_rwlock_recursive_write_trylock(odp_rwlock_recursive_t *lock);
+
+/**
* Release recursive rwlock after writing
*
* @param lock Pointer to a lock
Add the following APIs: - odp_rwlock_read_trylock() - odp_rwlock_write_trylock() - odp_rwlock_recursive_read_trylock() - odp_rwlock_recursive_write_trylock() Suggested-by: Sorin Vultureanu <Sorin.Vultureanu@enea.com> Signed-off-by: Bill Fischofer <bill.fischofer@linaro.org> --- include/odp/api/spec/rwlock.h | 23 ++++++++++++++++++++++- include/odp/api/spec/rwlock_recursive.h | 23 +++++++++++++++++++++++ 2 files changed, 45 insertions(+), 1 deletion(-)