File tree Expand file tree Collapse file tree 2 files changed +21
-135
lines changed Expand file tree Collapse file tree 2 files changed +21
-135
lines changed Load Diff This file was deleted.
Original file line number Diff line number Diff line change 45
45
#endif
46
46
47
47
class RWLock {
48
- struct ThreadMutex ;
49
-
50
- static int threads_number;
51
-
52
- mutable ThreadMutex *threads_data = nullptr ;
53
-
54
- static int get_thread_pos ();
55
-
56
- void init () const ;
48
+ mutable THREADING_NAMESPACE::shared_timed_mutex mutex;
57
49
58
50
public:
59
51
// Lock the RWLock, block if locked by someone else.
60
- void read_lock () const ;
52
+ _ALWAYS_INLINE_ void read_lock () const {
53
+ mutex.lock_shared ();
54
+ }
61
55
62
56
// Unlock the RWLock, let other threads continue.
63
- void read_unlock () const ;
57
+ _ALWAYS_INLINE_ void read_unlock () const {
58
+ mutex.unlock_shared ();
59
+ }
60
+
61
+ // Attempt to lock the RWLock for reading. True on success, false means it can't lock.
62
+ _ALWAYS_INLINE_ bool read_try_lock () const {
63
+ return mutex.try_lock_shared ();
64
+ }
64
65
65
66
// Lock the RWLock, block if locked by someone else.
66
- void write_lock ();
67
+ _ALWAYS_INLINE_ void write_lock () {
68
+ mutex.lock ();
69
+ }
67
70
68
71
// Unlock the RWLock, let other threads continue.
69
- void write_unlock ();
72
+ _ALWAYS_INLINE_ void write_unlock () {
73
+ mutex.unlock ();
74
+ }
70
75
71
76
// Attempt to lock the RWLock for writing. True on success, false means it can't lock.
72
- RWLock ();
73
- ~RWLock ();
77
+ _ALWAYS_INLINE_ bool write_try_lock () {
78
+ return mutex.try_lock ();
79
+ }
74
80
};
75
81
76
82
class RWLockRead {
You can’t perform that action at this time.
0 commit comments