diff mbox

rfifolock: no need to get thread identifier when nesting

Message ID 1462871793-31561-1-git-send-email-xiecl.fnst@cn.fujitsu.com (mailing list archive)
State New, archived
Headers show

Commit Message

Changlong Xie May 10, 2016, 9:16 a.m. UTC
Signed-off-by: Changlong Xie <xiecl.fnst@cn.fujitsu.com>
---
 util/rfifolock.c | 2 ++
 1 file changed, 2 insertions(+)

Comments

Denis V. Lunev May 10, 2016, 9:38 a.m. UTC | #1
On 05/10/2016 12:16 PM, Changlong Xie wrote:
> Signed-off-by: Changlong Xie <xiecl.fnst@cn.fujitsu.com>
> ---
>   util/rfifolock.c | 2 ++
>   1 file changed, 2 insertions(+)
>
> diff --git a/util/rfifolock.c b/util/rfifolock.c
> index c22f5fe..f406cc1 100644
> --- a/util/rfifolock.c
> +++ b/util/rfifolock.c
> @@ -50,6 +50,7 @@ void rfifolock_lock(RFifoLock *r)
>   
>       if (r->nesting > 0 && qemu_thread_is_self(&r->owner_thread)) {
>           r->tail--; /* put ticket back, we're nesting */
> +        goto out;
>       } else {
>           while (ticket != r->head) {
>               /* Invoke optional contention callback */
> @@ -61,6 +62,7 @@ void rfifolock_lock(RFifoLock *r)
>       }
>   
>       qemu_thread_get_self(&r->owner_thread);
> +out:
>       r->nesting++;
>       qemu_mutex_unlock(&r->lock);
>   }
it would be better to put
     qemu_thread_get_self(&r->owner_thread);
2 lines up and avoid unnecessary goto
Changlong Xie May 10, 2016, 9:54 a.m. UTC | #2
On 05/10/2016 05:38 PM, Denis V. Lunev wrote:
> On 05/10/2016 12:16 PM, Changlong Xie wrote:
>> Signed-off-by: Changlong Xie <xiecl.fnst@cn.fujitsu.com>
>> ---
>>   util/rfifolock.c | 2 ++
>>   1 file changed, 2 insertions(+)
>>
>> diff --git a/util/rfifolock.c b/util/rfifolock.c
>> index c22f5fe..f406cc1 100644
>> --- a/util/rfifolock.c
>> +++ b/util/rfifolock.c
>> @@ -50,6 +50,7 @@ void rfifolock_lock(RFifoLock *r)
>>       if (r->nesting > 0 && qemu_thread_is_self(&r->owner_thread)) {
>>           r->tail--; /* put ticket back, we're nesting */
>> +        goto out;
>>       } else {
>>           while (ticket != r->head) {
>>               /* Invoke optional contention callback */
>> @@ -61,6 +62,7 @@ void rfifolock_lock(RFifoLock *r)
>>       }
>>       qemu_thread_get_self(&r->owner_thread);
>> +out:
>>       r->nesting++;
>>       qemu_mutex_unlock(&r->lock);
>>   }
> it would be better to put
>      qemu_thread_get_self(&r->owner_thread);
> 2 lines up and avoid unnecessary goto

Yes, it's a better choice, will send out v2

Thanks
	-Xie
>
>
>
diff mbox

Patch

diff --git a/util/rfifolock.c b/util/rfifolock.c
index c22f5fe..f406cc1 100644
--- a/util/rfifolock.c
+++ b/util/rfifolock.c
@@ -50,6 +50,7 @@  void rfifolock_lock(RFifoLock *r)
 
     if (r->nesting > 0 && qemu_thread_is_self(&r->owner_thread)) {
         r->tail--; /* put ticket back, we're nesting */
+        goto out;
     } else {
         while (ticket != r->head) {
             /* Invoke optional contention callback */
@@ -61,6 +62,7 @@  void rfifolock_lock(RFifoLock *r)
     }
 
     qemu_thread_get_self(&r->owner_thread);
+out:
     r->nesting++;
     qemu_mutex_unlock(&r->lock);
 }