123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- #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))
|