diff mbox

[API-NEXT,PATCHv2,1/4] api: rwlock: add trylock variants for rwlock and rwlock_recursive

Message ID 1457208633-1453-1-git-send-email-bill.fischofer@linaro.org
State Accepted
Commit 1906cf41fa2738c370b4371c1e8508e844f3f9e0
Headers show

Commit Message

Bill Fischofer March 5, 2016, 8:10 p.m. UTC
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(-)

Comments

Maxim Uvarov March 18, 2016, 2:18 p.m. UTC | #1
Petri, ok?

Maxim.

On 03/05/16 23:10, Bill Fischofer wrote:
> 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(-)
>
> diff --git a/include/odp/api/spec/rwlock.h b/include/odp/api/spec/rwlock.h
> index 54f426f..9ca8872 100644
> --- a/include/odp/api/spec/rwlock.h
> +++ b/include/odp/api/spec/rwlock.h
> @@ -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 avoid blocking when
> + * the lock is not 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 !0 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 permission to a reader/writer lock.
> + *
> + * @param rwlock Pointer to a reader/writer lock
> + *
> + * @retval  0 Lock was not available for write access
> + * @retval !0 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
> diff --git a/include/odp/api/spec/rwlock_recursive.h b/include/odp/api/spec/rwlock_recursive.h
> index 10b2f79..965fcc0 100644
> --- a/include/odp/api/spec/rwlock_recursive.h
> +++ b/include/odp/api/spec/rwlock_recursive.h
> @@ -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 avoid blocking when the lock
> + * is not 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 !0     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 !0     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
Maxim Uvarov March 21, 2016, 3:02 p.m. UTC | #2
Patch set merged,
Maxim.

On 03/18/16 17:30, Savolainen, Petri (Nokia - FI/Espoo) wrote:
> Reviewed-by: Petri Savolainen <petri.savolainen@nokia.com>
>
>
>> -----Original Message-----
>> From: lng-odp [mailto:lng-odp-bounces@lists.linaro.org] On Behalf Of EXT
>> Bill Fischofer
>> Sent: Saturday, March 05, 2016 10:11 PM
>> To: lng-odp@lists.linaro.org
>> Subject: [lng-odp] [API-NEXT PATCHv2 1/4] api: rwlock: add trylock
>> variants for rwlock and rwlock_recursive
>>
>> 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(-)
>>
>> diff --git a/include/odp/api/spec/rwlock.h b/include/odp/api/spec/rwlock.h
>> index 54f426f..9ca8872 100644
>> --- a/include/odp/api/spec/rwlock.h
>> +++ b/include/odp/api/spec/rwlock.h
>> @@ -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 avoid blocking when
>> + * the lock is not 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 !0 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 permission to a reader/writer lock.
>> + *
>> + * @param rwlock Pointer to a reader/writer lock
>> + *
>> + * @retval  0 Lock was not available for write access
>> + * @retval !0 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
>> diff --git a/include/odp/api/spec/rwlock_recursive.h
>> b/include/odp/api/spec/rwlock_recursive.h
>> index 10b2f79..965fcc0 100644
>> --- a/include/odp/api/spec/rwlock_recursive.h
>> +++ b/include/odp/api/spec/rwlock_recursive.h
>> @@ -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 avoid blocking when the lock
>> + * is not 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 !0     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 !0     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
>> --
>> 2.5.0
>>
>> _______________________________________________
>> lng-odp mailing list
>> lng-odp@lists.linaro.org
>> https://lists.linaro.org/mailman/listinfo/lng-odp
> _______________________________________________
> lng-odp mailing list
> lng-odp@lists.linaro.org
> https://lists.linaro.org/mailman/listinfo/lng-odp
Maxim Uvarov March 21, 2016, 3:40 p.m. UTC | #3
Patch set merged,
Maxim.

On 03/18/16 17:30, Savolainen, Petri (Nokia - FI/Espoo) wrote:
> Reviewed-by: Petri Savolainen <petri.savolainen@nokia.com>
>
>
>> -----Original Message-----
>> From: lng-odp [mailto:lng-odp-bounces@lists.linaro.org] On Behalf Of EXT
>> Bill Fischofer
>> Sent: Saturday, March 05, 2016 10:11 PM
>> To: lng-odp@lists.linaro.org
>> Subject: [lng-odp] [API-NEXT PATCHv2 1/4] api: rwlock: add trylock
>> variants for rwlock and rwlock_recursive
>>
>> 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(-)
>>
>> diff --git a/include/odp/api/spec/rwlock.h b/include/odp/api/spec/rwlock.h
>> index 54f426f..9ca8872 100644
>> --- a/include/odp/api/spec/rwlock.h
>> +++ b/include/odp/api/spec/rwlock.h
>> @@ -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 avoid blocking when
>> + * the lock is not 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 !0 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 permission to a reader/writer lock.
>> + *
>> + * @param rwlock Pointer to a reader/writer lock
>> + *
>> + * @retval  0 Lock was not available for write access
>> + * @retval !0 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
>> diff --git a/include/odp/api/spec/rwlock_recursive.h
>> b/include/odp/api/spec/rwlock_recursive.h
>> index 10b2f79..965fcc0 100644
>> --- a/include/odp/api/spec/rwlock_recursive.h
>> +++ b/include/odp/api/spec/rwlock_recursive.h
>> @@ -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 avoid blocking when the lock
>> + * is not 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 !0     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 !0     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
>> --
>> 2.5.0
>>
>> _______________________________________________
>> lng-odp mailing list
>> lng-odp@lists.linaro.org
>> https://lists.linaro.org/mailman/listinfo/lng-odp
> _______________________________________________
> lng-odp mailing list
> lng-odp@lists.linaro.org
> https://lists.linaro.org/mailman/listinfo/lng-odp
diff mbox

Patch

diff --git a/include/odp/api/spec/rwlock.h b/include/odp/api/spec/rwlock.h
index 54f426f..9ca8872 100644
--- a/include/odp/api/spec/rwlock.h
+++ b/include/odp/api/spec/rwlock.h
@@ -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 avoid blocking when
+ * the lock is not 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 !0 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 permission to a reader/writer lock.
+ *
+ * @param rwlock Pointer to a reader/writer lock
+ *
+ * @retval  0 Lock was not available for write access
+ * @retval !0 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
diff --git a/include/odp/api/spec/rwlock_recursive.h b/include/odp/api/spec/rwlock_recursive.h
index 10b2f79..965fcc0 100644
--- a/include/odp/api/spec/rwlock_recursive.h
+++ b/include/odp/api/spec/rwlock_recursive.h
@@ -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 avoid blocking when the lock
+ * is not 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 !0     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 !0     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