Skip to content

Commit d61a360

Browse files
committed
Update SpinLock.h
1 parent 989708c commit d61a360

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

Common/Cpp/Concurrency/SpinLock.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,11 @@ class SpinLockMRSW{
8989
}
9090
}
9191

92+
PA_FORCE_INLINE bool try_acquire_write(){
93+
size_t state = 0;
94+
return m_readers.compare_exchange_strong(state, (size_t)-1);
95+
}
96+
9297
PA_FORCE_INLINE void unlock_read(){
9398
m_readers.fetch_sub(1);
9499
}
@@ -134,7 +139,11 @@ class WriteSpinLock{
134139
WriteSpinLock(const WriteSpinLock&) = delete;
135140
void operator=(const WriteSpinLock&) = delete;
136141

137-
PA_FORCE_INLINE WriteSpinLock(SpinLockMRSW& lock, const char* label = "(unnamed lock)")
142+
PA_FORCE_INLINE WriteSpinLock(
143+
SpinLockMRSW& lock,
144+
const char* label = "(unnamed lock)",
145+
bool try_acquire = false
146+
)
138147
: m_lock(lock)
139148
{
140149
lock.acquire_write(label);

0 commit comments

Comments
 (0)