[Beignet] Mutex Access in Kernel

Gao, Sanshan gss at mail.ustc.edu.cn
Fri May 1 01:19:34 PDT 2015


I want to access a structure variable by mutex, so I write three functions below.
I'm not sure whether atomic_dec(), in line 81, can ensure only one work-item grab this mutex lock, due to the return value.
If it's not OK, how can I correct it to implement mutex access? 
Thank you!


 71 void MutexInit(int* p)
 72 {
 73     *p = 1;
 74 }
 75
 76 void MutexLock(int* p)
 77 {
 78 MutexLock_start:
 79     if (1 == *p)
 80     {
 81         if (atomic_dec(p) == 1)
 82             return;
 83         else
 84             atomic_inc(p);
 85     }
 86     goto MutexLock_start;
 87 }
 88
 89 void MutexUnlock(int* p)
 90 {
 91     atomic_inc(p);
 92 }

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freedesktop.org/archives/beignet/attachments/20150501/7f2933c7/attachment.html>


More information about the Beignet mailing list