@@ -61,11 +61,15 @@ class WaitingQueue final : private RawMutex {
61
61
// RAII guard to lock and unlock the waiting queue.
62
62
class Guard {
63
63
WaitingQueue &queue;
64
+ bool is_pshared;
64
65
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
+ }
66
70
67
71
public:
68
- LIBC_INLINE ~Guard () { queue.unlock (); }
72
+ LIBC_INLINE ~Guard () { queue.unlock (is_pshared ); }
69
73
template <Role role> LIBC_INLINE FutexWordType &pending_count () {
70
74
if constexpr (role == Role::Reader)
71
75
return queue.pending_readers ;
@@ -86,9 +90,9 @@ class WaitingQueue final : private RawMutex {
86
90
: RawMutex(), pending_readers(0 ), pending_writers(0 ),
87
91
reader_serialization(0 ), writer_serialization(0 ) {}
88
92
89
- LIBC_INLINE Guard acquire () {
93
+ LIBC_INLINE Guard acquire (bool is_pshared ) {
90
94
this ->lock ();
91
- return Guard (*this );
95
+ return Guard (*this , is_pshared );
92
96
}
93
97
94
98
template <Role role>
@@ -426,7 +430,7 @@ class RwLock {
426
430
// that this lock will make the timeout imprecise, but this is the
427
431
// best we can do. The transaction is small and everyone should make
428
432
// progress rather quickly.
429
- WaitingQueue::Guard guard = queue.acquire ();
433
+ WaitingQueue::Guard guard = queue.acquire (is_pshared );
430
434
guard.template pending_count <role>()++;
431
435
432
436
// Use atomic operation to guarantee the total order of the operations
@@ -450,7 +454,7 @@ class RwLock {
450
454
{
451
455
// Similarly, the unregister operation should also be an atomic
452
456
// transaction.
453
- WaitingQueue::Guard guard = queue.acquire ();
457
+ WaitingQueue::Guard guard = queue.acquire (is_pshared );
454
458
guard.pending_count <role>()--;
455
459
// Clear the flag if we are the last reader. The flag must be
456
460
// cleared otherwise operations like trylock may fail even though
@@ -500,7 +504,7 @@ class RwLock {
500
504
WakeTarget status;
501
505
502
506
{
503
- WaitingQueue::Guard guard = queue.acquire ();
507
+ WaitingQueue::Guard guard = queue.acquire (is_pshared );
504
508
if (guard.pending_count <Role::Writer>() != 0 ) {
505
509
guard.serialization <Role::Writer>()++;
506
510
status = WakeTarget::Writers;
0 commit comments