ifpps: use uint32_t instead of u32
[netsniff-ng.git] / locking.h
blobddc40270b538cbed13941ede7b28983ec4f17cf6
1 #ifndef LOCKING_H
2 #define LOCKING_H
4 #include <pthread.h>
6 struct spinlock {
7 pthread_spinlock_t lock;
8 };
10 struct mutexlock {
11 pthread_mutex_t lock;
14 #define MUTEXLOCK_INITIALIZER { .lock = PTHREAD_MUTEX_INITIALIZER }
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 */