Since there were no further complaints: Added mutex_lock_with_timeout().
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@34403 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -22,6 +22,7 @@ typedef struct mutex {
|
||||
thread_id holder;
|
||||
#else
|
||||
int32 count;
|
||||
uint16 ignore_unlock_count;
|
||||
#endif
|
||||
uint8 flags;
|
||||
} mutex;
|
||||
@@ -81,7 +82,7 @@ typedef struct rw_lock {
|
||||
# define MUTEX_INITIALIZER(name) { name, NULL, -1, 0 }
|
||||
# define RECURSIVE_LOCK_INITIALIZER(name) { MUTEX_INITIALIZER(name), 0 }
|
||||
#else
|
||||
# define MUTEX_INITIALIZER(name) { name, NULL, 0, 0 }
|
||||
# define MUTEX_INITIALIZER(name) { name, NULL, 0, 0, 0 }
|
||||
# define RECURSIVE_LOCK_INITIALIZER(name) { MUTEX_INITIALIZER(name), -1, 0 }
|
||||
#endif
|
||||
|
||||
@@ -132,6 +133,8 @@ extern status_t mutex_switch_lock(mutex* from, mutex* to);
|
||||
extern status_t _mutex_lock(mutex* lock, bool threadsLocked);
|
||||
extern void _mutex_unlock(mutex* lock, bool threadsLocked);
|
||||
extern status_t _mutex_trylock(mutex* lock);
|
||||
extern status_t _mutex_lock_with_timeout(mutex* lock, uint32 timeoutFlags,
|
||||
bigtime_t timeout);
|
||||
|
||||
|
||||
static inline status_t
|
||||
@@ -173,6 +176,19 @@ mutex_trylock(mutex* lock)
|
||||
}
|
||||
|
||||
|
||||
static inline status_t
|
||||
mutex_lock_with_timeout(mutex* lock, uint32 timeoutFlags, bigtime_t timeout)
|
||||
{
|
||||
#if KDEBUG
|
||||
return _mutex_lock_with_timeout(lock, timeoutFlags, timeout);
|
||||
#else
|
||||
if (atomic_add(&lock->count, -1) < 0)
|
||||
return _mutex_lock_with_timeout(lock, timeoutFlags, timeout);
|
||||
return B_OK;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
static inline void
|
||||
mutex_unlock(mutex* lock)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user