1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 |
- #include <atomic.h>
- static inline void
- __generic_mutex_lock (int *mutex)
- {
- unsigned int v;
-
- if (atomic_bit_test_set (mutex, 31) == 0)
- return;
- atomic_increment (mutex);
- while (1)
- {
- if (atomic_bit_test_set (mutex, 31) == 0)
- {
- atomic_decrement (mutex);
- return;
- }
-
- v = *mutex;
- if (v >= 0)
- continue;
- lll_futex_wait (mutex, v,
-
- LLL_SHARED);
- }
- }
- static inline void
- __generic_mutex_unlock (int *mutex)
- {
-
- if (atomic_add_zero (mutex, 0x80000000))
- return;
-
- lll_futex_wake (mutex, 1,
-
- LLL_SHARED);
- }
- #define lll_mutex_lock(futex) __generic_mutex_lock (&(futex))
- #define lll_mutex_unlock(futex) __generic_mutex_unlock (&(futex))
|