Added locking primitive lazy_mutex, which has essentially the same behaviour

as a mutex, but allocates its semaphore lazily. This comes at the cost of an
additional atomic_add() when the semaphore has actually to be acquired, but
saves the semaphore creation completely in single-threaded programs and in
any program when there's no lock contention.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@34339 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Ingo Weinhold
2009-11-29 10:44:07 +00:00
parent f2bb2575e6
commit 937b23cb21
2 changed files with 115 additions and 0 deletions
+13
View File
@@ -22,6 +22,19 @@ status_t mutex_lock(mutex *lock);
void mutex_unlock(mutex *lock);
typedef struct lazy_mutex {
int32 benaphore;
sem_id semaphore;
const char* name;
} lazy_mutex;
status_t lazy_mutex_init(lazy_mutex *lock, const char *name);
// name will not be cloned and must rename valid
void lazy_mutex_destroy(mutex *lock);
status_t lazy_mutex_lock(lazy_mutex *lock);
void lazy_mutex_unlock(lazy_mutex *lock);
typedef struct rw_lock {
const char * name;
mutex lock;