MCPcopy Create free account
hub / github.com/3rdparty/libprocess / write_unlock

Method write_unlock

include/process/rwlock.hpp:61–104  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

59 }
60
61 void write_unlock()
62 {
63 // NOTE: We need to satisfy the waiter(s) futures outside the
64 // critical section because it might trigger callbacks which
65 // try to reacquire a read or write lock.
66 std::queue<Waiter> unblocked;
67
68 synchronized (data->lock) {
69 CHECK(data->write_locked);
70 CHECK_EQ(data->read_locked, 0u);
71
72 data->write_locked = false;
73
74 if (!data->waiters.empty()) {
75 switch (data->waiters.front().type) {
76 case Waiter::READ:
77 // Dequeue the group of readers at the front.
78 while (!data->waiters.empty() &&
79 data->waiters.front().type == Waiter::READ) {
80 unblocked.push(std::move(data->waiters.front()));
81 data->waiters.pop();
82 }
83
84 data->read_locked = unblocked.size();
85
86 break;
87
88 case Waiter::WRITE:
89 unblocked.push(std::move(data->waiters.front()));
90 data->waiters.pop();
91 data->write_locked = true;
92
93 CHECK_EQ(data->read_locked, 0u);
94
95 break;
96 }
97 }
98 }
99
100 while (!unblocked.empty()) {
101 unblocked.front().promise.set(Nothing());
102 unblocked.pop();
103 }
104 }
105
106 // TODO(bmahler): Consider returning a 'Locked' object in the
107 // future as the mechanism for unlocking, rather than exposing

Callers 1

TESTFunction · 0.80

Calls 5

pushMethod · 0.80
synchronizedFunction · 0.50
emptyMethod · 0.45
sizeMethod · 0.45
setMethod · 0.45

Tested by 1

TESTFunction · 0.64