master
h 35 lines 1.67 KB
Raw
1 // SPDX-License-Identifier: GPL-3.0-or-later
2
3 #ifndef NETDATA_RW_SPINLOCK_H
4 #define NETDATA_RW_SPINLOCK_H
5
6 #include "libnetdata/common.h"
7 #include "spinlock.h"
8
9 typedef struct netdata_rw_spinlock {
10 pid_t writer;
11 uint32_t counter;
12 } RW_SPINLOCK;
13
14 #define RW_SPINLOCK_INITIALIZER { .counter = 0, .writer = 0, }
15
16 void rw_spinlock_init_with_trace(RW_SPINLOCK *rw_spinlock, const char *func);
17 void rw_spinlock_read_lock_with_trace(RW_SPINLOCK *rw_spinlock, const char *func);
18 void rw_spinlock_read_unlock_with_trace(RW_SPINLOCK *rw_spinlock, const char *func);
19 void rw_spinlock_write_lock_with_trace(RW_SPINLOCK *rw_spinlock, const char *func);
20 void rw_spinlock_write_unlock_with_trace(RW_SPINLOCK *rw_spinlock, const char *func);
21 bool rw_spinlock_tryread_lock_with_trace(RW_SPINLOCK *rw_spinlock, const char *func);
22 bool rw_spinlock_trywrite_lock_with_trace(RW_SPINLOCK *rw_spinlock, const char *func);
23
24
25 #define rw_spinlock_init(rw_spinlock) rw_spinlock_init_with_trace(rw_spinlock, __FUNCTION__)
26 #define rw_spinlock_read_lock(rw_spinlock) rw_spinlock_read_lock_with_trace(rw_spinlock, __FUNCTION__)
27 #define rw_spinlock_read_unlock(rw_spinlock) rw_spinlock_read_unlock_with_trace(rw_spinlock, __FUNCTION__)
28 #define rw_spinlock_write_lock(rw_spinlock) rw_spinlock_write_lock_with_trace(rw_spinlock, __FUNCTION__)
29 #define rw_spinlock_write_unlock(rw_spinlock) rw_spinlock_write_unlock_with_trace(rw_spinlock, __FUNCTION__)
30 #define rw_spinlock_tryread_lock(rw_spinlock) rw_spinlock_tryread_lock_with_trace(rw_spinlock, __FUNCTION__)
31 #define rw_spinlock_trywrite_lock(rw_spinlock) rw_spinlock_trywrite_lock_with_trace(rw_spinlock, __FUNCTION__)
32
33 int rw_spinlock_unittest(void);
34
35 #endif //NETDATA_RW_SPINLOCK_H