perf tools: Don't clone maps from parent when synthesizing forks
[linux/fpc-iii.git] / tools / lib / lockdep / include / liblockdep / rwlock.h
bloba96c3bf0fef121a19fce62b22946e5eb9f39120f
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _LIBLOCKDEP_RWLOCK_H
3 #define _LIBLOCKDEP_RWLOCK_H
5 #include <pthread.h>
6 #include "common.h"
8 struct liblockdep_pthread_rwlock {
9 pthread_rwlock_t rwlock;
10 struct lockdep_map dep_map;
13 typedef struct liblockdep_pthread_rwlock liblockdep_pthread_rwlock_t;
15 #define LIBLOCKDEP_PTHREAD_RWLOCK_INITIALIZER(rwl) \
16 (struct liblockdep_pthread_rwlock) { \
17 .rwlock = PTHREAD_RWLOCK_INITIALIZER, \
18 .dep_map = STATIC_LOCKDEP_MAP_INIT(#rwl, &((&(rwl))->dep_map)), \
21 static inline int __rwlock_init(liblockdep_pthread_rwlock_t *lock,
22 const char *name,
23 struct lock_class_key *key,
24 const pthread_rwlockattr_t *attr)
26 lockdep_init_map(&lock->dep_map, name, key, 0);
28 return pthread_rwlock_init(&lock->rwlock, attr);
31 #define liblockdep_pthread_rwlock_init(lock, attr) \
32 ({ \
33 static struct lock_class_key __key; \
35 __rwlock_init((lock), #lock, &__key, (attr)); \
38 static inline int liblockdep_pthread_rwlock_rdlock(liblockdep_pthread_rwlock_t *lock)
40 lock_acquire(&lock->dep_map, 0, 0, 2, 1, NULL, (unsigned long)_RET_IP_);
41 return pthread_rwlock_rdlock(&lock->rwlock);
45 static inline int liblockdep_pthread_rwlock_unlock(liblockdep_pthread_rwlock_t *lock)
47 lock_release(&lock->dep_map, 0, (unsigned long)_RET_IP_);
48 return pthread_rwlock_unlock(&lock->rwlock);
51 static inline int liblockdep_pthread_rwlock_wrlock(liblockdep_pthread_rwlock_t *lock)
53 lock_acquire(&lock->dep_map, 0, 0, 0, 1, NULL, (unsigned long)_RET_IP_);
54 return pthread_rwlock_wrlock(&lock->rwlock);
57 static inline int liblockdep_pthread_rwlock_tryrdlock(liblockdep_pthread_rwlock_t *lock)
59 lock_acquire(&lock->dep_map, 0, 1, 2, 1, NULL, (unsigned long)_RET_IP_);
60 return pthread_rwlock_tryrdlock(&lock->rwlock) == 0 ? 1 : 0;
63 static inline int liblockdep_pthread_rwlock_trywlock(liblockdep_pthread_rwlock_t *lock)
65 lock_acquire(&lock->dep_map, 0, 1, 0, 1, NULL, (unsigned long)_RET_IP_);
66 return pthread_rwlock_trywlock(&lock->rwlock) == 0 ? 1 : 0;
69 static inline int liblockdep_rwlock_destroy(liblockdep_pthread_rwlock_t *lock)
71 return pthread_rwlock_destroy(&lock->rwlock);
74 #ifdef __USE_LIBLOCKDEP
76 #define pthread_rwlock_t liblockdep_pthread_rwlock_t
77 #define pthread_rwlock_init liblockdep_pthread_rwlock_init
78 #define pthread_rwlock_rdlock liblockdep_pthread_rwlock_rdlock
79 #define pthread_rwlock_unlock liblockdep_pthread_rwlock_unlock
80 #define pthread_rwlock_wrlock liblockdep_pthread_rwlock_wrlock
81 #define pthread_rwlock_tryrdlock liblockdep_pthread_rwlock_tryrdlock
82 #define pthread_rwlock_trywlock liblockdep_pthread_rwlock_trywlock
83 #define pthread_rwlock_destroy liblockdep_rwlock_destroy
85 #endif
87 #endif