TODO(bmahler): Consider returning a 'Locked' object in the future as the mechanism for unlocking, rather than exposing unlocking functions for all to call.
| 107 | // future as the mechanism for unlocking, rather than exposing |
| 108 | // unlocking functions for all to call. |
| 109 | Future<Nothing> read_lock() |
| 110 | { |
| 111 | Future<Nothing> future = Nothing(); |
| 112 | |
| 113 | synchronized (data->lock) { |
| 114 | if (!data->write_locked && data->waiters.empty()) { |
| 115 | data->read_locked++; |
| 116 | } else { |
| 117 | Waiter w{Waiter::READ}; |
| 118 | future = w.promise.future(); |
| 119 | data->waiters.push(std::move(w)); |
| 120 | } |
| 121 | } |
| 122 | |
| 123 | return future; |
| 124 | } |
| 125 | |
| 126 | void read_unlock() |
| 127 | { |