man: trafgen: finish syntax section
[netsniff-ng.git] / locking.h
blobac10d5d92625d24e13f224f463725a41fd367fbe
1 /*
2 * netsniff-ng - the packet sniffing beast
3 * Copyright 2011 Daniel Borkmann.
4 * Subject to the GPL, version 2.
5 */
7 #ifndef LOCKING_H
8 #define LOCKING_H
10 #include <pthread.h>
12 #include "built_in.h"
14 struct spinlock {
15 pthread_spinlock_t lock;
18 struct mutexlock {
19 pthread_mutex_t lock;
22 struct rwlock {
23 pthread_rwlock_t lock;
26 static inline int spinlock_init(struct spinlock *l)
28 return -pthread_spin_init(&l->lock, 0);
31 static inline void spinlock_destroy(struct spinlock *l)
33 pthread_spin_destroy(&l->lock);
36 static inline void spinlock_lock(struct spinlock *l)
38 pthread_spin_lock(&l->lock);
41 static inline void spinlock_unlock(struct spinlock *l)
43 pthread_spin_unlock(&l->lock);
46 static inline int mutexlock_init(struct mutexlock *l)
48 return -pthread_mutex_init(&l->lock, 0);
51 static inline void mutexlock_destroy(struct mutexlock *l)
53 pthread_mutex_destroy(&l->lock);
56 static inline void mutexlock_lock(struct mutexlock *l)
58 pthread_mutex_lock(&l->lock);
61 static inline void mutexlock_unlock(struct mutexlock *l)
63 pthread_mutex_unlock(&l->lock);
66 static inline int rwlock_init(struct rwlock *l)
68 return -pthread_rwlock_init(&l->lock, 0);
71 static inline int rwlock_init2(struct rwlock *l,
72 pthread_rwlockattr_t *restrict attr)
74 return -pthread_rwlock_init(&l->lock, attr);
77 static inline void rwlock_destroy(struct rwlock *l)
79 pthread_rwlock_destroy(&l->lock);
82 static inline void rwlock_rd_lock(struct rwlock *l)
84 pthread_rwlock_rdlock(&l->lock);
87 static inline void rwlock_wr_lock(struct rwlock *l)
89 pthread_rwlock_wrlock(&l->lock);
92 static inline void rwlock_unlock(struct rwlock *l)
94 pthread_rwlock_unlock(&l->lock);
97 #endif /* LOCKING_H */