build: use VERSION_SHORT instead of VERSION_STRING
[netsniff-ng.git] / locking.h
blob95f13418a144be696863e4764fd3e64f2a5f86e1
1 #ifndef LOCKING_H
2 #define LOCKING_H
4 #include <pthread.h>
6 #include "built_in.h"
8 struct spinlock {
9 pthread_spinlock_t lock;
12 struct mutexlock {
13 pthread_mutex_t lock;
16 struct rwlock {
17 pthread_rwlock_t lock;
20 static inline int spinlock_init(struct spinlock *l)
22 return -pthread_spin_init(&l->lock, 0);
25 static inline void spinlock_destroy(struct spinlock *l)
27 pthread_spin_destroy(&l->lock);
30 static inline void spinlock_lock(struct spinlock *l)
32 pthread_spin_lock(&l->lock);
35 static inline void spinlock_unlock(struct spinlock *l)
37 pthread_spin_unlock(&l->lock);
40 static inline int mutexlock_init(struct mutexlock *l)
42 return -pthread_mutex_init(&l->lock, 0);
45 static inline void mutexlock_destroy(struct mutexlock *l)
47 pthread_mutex_destroy(&l->lock);
50 static inline void mutexlock_lock(struct mutexlock *l)
52 pthread_mutex_lock(&l->lock);
55 static inline void mutexlock_unlock(struct mutexlock *l)
57 pthread_mutex_unlock(&l->lock);
60 static inline int rwlock_init(struct rwlock *l)
62 return -pthread_rwlock_init(&l->lock, 0);
65 static inline int rwlock_init2(struct rwlock *l,
66 pthread_rwlockattr_t *attr)
68 return -pthread_rwlock_init(&l->lock, attr);
71 static inline void rwlock_destroy(struct rwlock *l)
73 pthread_rwlock_destroy(&l->lock);
76 static inline void rwlock_rd_lock(struct rwlock *l)
78 pthread_rwlock_rdlock(&l->lock);
81 static inline void rwlock_wr_lock(struct rwlock *l)
83 pthread_rwlock_wrlock(&l->lock);
86 static inline void rwlock_unlock(struct rwlock *l)
88 pthread_rwlock_unlock(&l->lock);
91 #endif /* LOCKING_H */