Lines Matching refs:mutex

21 #define MUTEX_TYPE(mutex)	((mutex)->flags & MUTEX_TYPE_BITS)
31 pthread_mutex_init(pthread_mutex_t* mutex, const pthread_mutexattr_t* _attr)
36 mutex->lock = 0;
37 mutex->owner = -1;
38 mutex->owner_count = 0;
39 mutex->flags = attr->type | (attr->process_shared ? MUTEX_FLAG_SHARED : 0);
46 pthread_mutex_destroy(pthread_mutex_t* mutex)
53 __pthread_mutex_lock(pthread_mutex_t* mutex, uint32 flags, bigtime_t timeout)
57 if (mutex->owner == thisThread) {
59 if (MUTEX_TYPE(mutex) == PTHREAD_MUTEX_RECURSIVE) {
60 if (mutex->owner_count == INT32_MAX)
63 mutex->owner_count++;
68 if (MUTEX_TYPE(mutex) == PTHREAD_MUTEX_ERRORCHECK
69 || MUTEX_TYPE(mutex) == PTHREAD_MUTEX_DEFAULT) {
76 const int32 oldValue = atomic_test_and_set((int32*)&mutex->lock, B_USER_MUTEX_LOCKED, 0);
81 if ((mutex->flags & MUTEX_FLAG_SHARED) != 0)
87 error = _kern_mutex_lock((int32*)&mutex->lock, NULL, flags, timeout);
94 // we have locked the mutex for the first time
95 assert(mutex->owner == -1);
96 mutex->owner = thisThread;
97 mutex->owner_count = 1;
104 pthread_mutex_lock(pthread_mutex_t* mutex)
106 return __pthread_mutex_lock(mutex, 0, B_INFINITE_TIMEOUT);
111 pthread_mutex_trylock(pthread_mutex_t* mutex)
113 return __pthread_mutex_lock(mutex, B_ABSOLUTE_REAL_TIME_TIMEOUT, -1);
118 pthread_mutex_clocklock(pthread_mutex_t* mutex, clockid_t clock_id,
143 status_t status = __pthread_mutex_lock(mutex, flags, timeout);
145 // The timespec was not valid and the mutex could not be locked
155 pthread_mutex_timedlock(pthread_mutex_t* mutex, const struct timespec* abstime)
157 return pthread_mutex_clocklock(mutex, CLOCK_REALTIME, abstime);
162 pthread_mutex_unlock(pthread_mutex_t* mutex)
164 if (mutex->owner != find_thread(NULL))
167 if (MUTEX_TYPE(mutex) == PTHREAD_MUTEX_RECURSIVE
168 && --mutex->owner_count > 0) {
173 mutex->owner = -1;
176 int32 oldValue = atomic_and((int32*)&mutex->lock,
179 _kern_mutex_unblock((int32*)&mutex->lock,
180 (mutex->flags & MUTEX_FLAG_SHARED) ? B_USER_MUTEX_SHARED : 0);
183 if (MUTEX_TYPE(mutex) == PTHREAD_MUTEX_ERRORCHECK
184 || MUTEX_TYPE(mutex) == PTHREAD_MUTEX_DEFAULT) {
194 pthread_mutex_getprioceiling(const pthread_mutex_t* mutex, int* _prioCeiling)
196 if (mutex == NULL || _prioCeiling == NULL)
207 pthread_mutex_setprioceiling(pthread_mutex_t* mutex, int prioCeiling,
210 if (mutex == NULL)