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:
Ingo Weinhold
2009-12-01 09:38:34 +00:00
parent f8ec4c04a0
commit e182b46db6
2 changed files with 115 additions and 1 deletions
+17 -1
View File
@@ -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)
{