fix a kmap leak in virtio_console
[linux/fpc-iii.git] / tools / lib / lockdep / include / liblockdep / rwlock.h
bloba680ab8c2e3647b77745f1fc698a115822d4068c
1 #ifndef _LIBLOCKDEP_RWLOCK_H
2 #define _LIBLOCKDEP_RWLOCK_H
4 #include <pthread.h>
5 #include "common.h"
7 struct liblockdep_pthread_rwlock {
8 pthread_rwlock_t rwlock;
9 struct lockdep_map dep_map;
12 typedef struct liblockdep_pthread_rwlock liblockdep_pthread_rwlock_t;
14 #define LIBLOCKDEP_PTHREAD_RWLOCK_INITIALIZER(rwl) \
15 (struct liblockdep_pthread_rwlock) { \
16 .rwlock = PTHREAD_RWLOCK_INITIALIZER, \
17 .dep_map = STATIC_LOCKDEP_MAP_INIT(#rwl, &((&(rwl))->dep_map)), \
20 static inline int __rwlock_init(liblockdep_pthread_rwlock_t *lock,
21 const char *name,
22 struct lock_class_key *key,
23 const pthread_rwlockattr_t *attr)
25 lockdep_init_map(&lock->dep_map, name, key, 0);
27 return pthread_rwlock_init(&lock->rwlock, attr);
30 #define liblockdep_pthread_rwlock_init(lock, attr) \
31 ({ \
32 static struct lock_class_key __key; \
34 __rwlock_init((lock), #lock, &__key, (attr)); \
37 static inline int liblockdep_pthread_rwlock_rdlock(liblockdep_pthread_rwlock_t *lock)
39 lock_acquire(&lock->dep_map, 0, 0, 2, 2, NULL, (unsigned long)_RET_IP_);
40 return pthread_rwlock_rdlock(&lock->rwlock);
44 static inline int liblockdep_pthread_rwlock_unlock(liblockdep_pthread_rwlock_t *lock)
46 lock_release(&lock->dep_map, 0, (unsigned long)_RET_IP_);
47 return pthread_rwlock_unlock(&lock->rwlock);
50 static inline int liblockdep_pthread_rwlock_wrlock(liblockdep_pthread_rwlock_t *lock)
52 lock_acquire(&lock->dep_map, 0, 0, 0, 2, NULL, (unsigned long)_RET_IP_);
53 return pthread_rwlock_wrlock(&lock->rwlock);
56 static inline int liblockdep_pthread_rwlock_tryrdlock(liblockdep_pthread_rwlock_t *lock)
58 lock_acquire(&lock->dep_map, 0, 1, 2, 2, NULL, (unsigned long)_RET_IP_);
59 return pthread_rwlock_tryrdlock(&lock->rwlock) == 0 ? 1 : 0;
62 static inline int liblockdep_pthread_rwlock_trywlock(liblockdep_pthread_rwlock_t *lock)
64 lock_acquire(&lock->dep_map, 0, 1, 0, 2, NULL, (unsigned long)_RET_IP_);
65 return pthread_rwlock_trywlock(&lock->rwlock) == 0 ? 1 : 0;
68 static inline int liblockdep_rwlock_destroy(liblockdep_pthread_rwlock_t *lock)
70 return pthread_rwlock_destroy(&lock->rwlock);
73 #ifdef __USE_LIBLOCKDEP
75 #define pthread_rwlock_t liblockdep_pthread_rwlock_t
76 #define pthread_rwlock_init liblockdep_pthread_rwlock_init
77 #define pthread_rwlock_rdlock liblockdep_pthread_rwlock_rdlock
78 #define pthread_rwlock_unlock liblockdep_pthread_rwlock_unlock
79 #define pthread_rwlock_wrlock liblockdep_pthread_rwlock_wrlock
80 #define pthread_rwlock_tryrdlock liblockdep_pthread_rwlock_tryrdlock
81 #define pthread_rwlock_trywlock liblockdep_pthread_rwlock_trywlock
82 #define pthread_rwlock_destroy liblockdep_rwlock_destroy
84 #endif
86 #endif