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 }
_______________________________________________
Beignet mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/beignet