Skip to content

Commit 9b65d61

Browse files
committed
Remove rw_lock changes as they don't improve performance.
1 parent 73d9280 commit 9b65d61

File tree

2 files changed

+21
-135
lines changed

2 files changed

+21
-135
lines changed

core/os/rw_lock.cpp

Lines changed: 0 additions & 120 deletions
This file was deleted.

core/os/rw_lock.h

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -45,32 +45,38 @@
4545
#endif
4646

4747
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;
5749

5850
public:
5951
// 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+
}
6155

6256
// 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+
}
6465

6566
// Lock the RWLock, block if locked by someone else.
66-
void write_lock();
67+
_ALWAYS_INLINE_ void write_lock() {
68+
mutex.lock();
69+
}
6770

6871
// Unlock the RWLock, let other threads continue.
69-
void write_unlock();
72+
_ALWAYS_INLINE_ void write_unlock() {
73+
mutex.unlock();
74+
}
7075

7176
// 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+
}
7480
};
7581

7682
class RWLockRead {

0 commit comments

Comments
 (0)