Skip to content

Commit 05c5f98

Browse files
Yifan ZhuSchrodingerZhu
authored andcommitted
fix missed pshared flags
1 parent d8f9d1f commit 05c5f98

File tree

1 file changed

+11
-7
lines changed
  • libc/src/__support/threads/linux

1 file changed

+11
-7
lines changed

libc/src/__support/threads/linux/rwlock.h

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,15 @@ class WaitingQueue final : private RawMutex {
6161
// RAII guard to lock and unlock the waiting queue.
6262
class Guard {
6363
WaitingQueue &queue;
64+
bool is_pshared;
6465

65-
LIBC_INLINE constexpr Guard(WaitingQueue &queue) : queue(queue) {}
66+
LIBC_INLINE constexpr Guard(WaitingQueue &queue, bool is_pshared)
67+
: queue(queue), is_pshared(is_pshared) {
68+
queue.lock();
69+
}
6670

6771
public:
68-
LIBC_INLINE ~Guard() { queue.unlock(); }
72+
LIBC_INLINE ~Guard() { queue.unlock(is_pshared); }
6973
template <Role role> LIBC_INLINE FutexWordType &pending_count() {
7074
if constexpr (role == Role::Reader)
7175
return queue.pending_readers;
@@ -86,9 +90,9 @@ class WaitingQueue final : private RawMutex {
8690
: RawMutex(), pending_readers(0), pending_writers(0),
8791
reader_serialization(0), writer_serialization(0) {}
8892

89-
LIBC_INLINE Guard acquire() {
93+
LIBC_INLINE Guard acquire(bool is_pshared) {
9094
this->lock();
91-
return Guard(*this);
95+
return Guard(*this, is_pshared);
9296
}
9397

9498
template <Role role>
@@ -426,7 +430,7 @@ class RwLock {
426430
// that this lock will make the timeout imprecise, but this is the
427431
// best we can do. The transaction is small and everyone should make
428432
// progress rather quickly.
429-
WaitingQueue::Guard guard = queue.acquire();
433+
WaitingQueue::Guard guard = queue.acquire(is_pshared);
430434
guard.template pending_count<role>()++;
431435

432436
// Use atomic operation to guarantee the total order of the operations
@@ -450,7 +454,7 @@ class RwLock {
450454
{
451455
// Similarly, the unregister operation should also be an atomic
452456
// transaction.
453-
WaitingQueue::Guard guard = queue.acquire();
457+
WaitingQueue::Guard guard = queue.acquire(is_pshared);
454458
guard.pending_count<role>()--;
455459
// Clear the flag if we are the last reader. The flag must be
456460
// cleared otherwise operations like trylock may fail even though
@@ -500,7 +504,7 @@ class RwLock {
500504
WakeTarget status;
501505

502506
{
503-
WaitingQueue::Guard guard = queue.acquire();
507+
WaitingQueue::Guard guard = queue.acquire(is_pshared);
504508
if (guard.pending_count<Role::Writer>() != 0) {
505509
guard.serialization<Role::Writer>()++;
506510
status = WakeTarget::Writers;

0 commit comments

Comments
 (0)