mat: add matrix operations
[transsip-mirror.git] / src / locking.h
blob049e72cea254d306cb3bf4deae0a3190f0f66abe
1 /*
2 * transsip - the telephony toolkit
3 * By Daniel Borkmann <daniel@transsip.org>
4 * Copyright 2011, 2012 Daniel Borkmann <dborkma@tik.ee.ethz.ch>
5 * Subject to the GPL, version 2.
6 */
8 #ifndef LOCKING_H
9 #define LOCKING_H
11 #include <pthread.h>
13 struct spinlock {
14 pthread_spinlock_t lock;
17 struct mutexlock {
18 pthread_mutex_t lock;
21 struct rwlock {
22 pthread_rwlock_t lock;
25 static inline int spinlock_init(struct spinlock *l)
27 return -pthread_spin_init(&l->lock, 0);
30 static inline void spinlock_destroy(struct spinlock *l)
32 pthread_spin_destroy(&l->lock);
35 static inline void spinlock_lock(struct spinlock *l)
37 pthread_spin_lock(&l->lock);
40 static inline void spinlock_unlock(struct spinlock *l)
42 pthread_spin_unlock(&l->lock);
45 static inline int mutexlock_init(struct mutexlock *l)
47 return -pthread_mutex_init(&l->lock, 0);
50 static inline void mutexlock_destroy(struct mutexlock *l)
52 pthread_mutex_destroy(&l->lock);
55 static inline void mutexlock_lock(struct mutexlock *l)
57 pthread_mutex_lock(&l->lock);
60 static inline void mutexlock_unlock(struct mutexlock *l)
62 pthread_mutex_unlock(&l->lock);
65 static inline int rwlock_init(struct rwlock *l)
67 return -pthread_rwlock_init(&l->lock, 0);
70 static inline void rwlock_destroy(struct rwlock *l)
72 pthread_rwlock_destroy(&l->lock);
75 static inline void rwlock_rd_lock(struct rwlock *l)
77 pthread_rwlock_rdlock(&l->lock);
80 static inline void rwlock_wr_lock(struct rwlock *l)
82 pthread_rwlock_wrlock(&l->lock);
85 static inline void rwlock_unlock(struct rwlock *l)
87 pthread_rwlock_unlock(&l->lock);
90 #endif /* LOCKING_H */