TODO(bmahler): Consider returning a 'Locked' object in the future as the mechanism for unlocking, rather than exposing unlocking functions for all to call.
| 42 | // future as the mechanism for unlocking, rather than exposing |
| 43 | // unlocking functions for all to call. |
| 44 | Future<Nothing> write_lock() |
| 45 | { |
| 46 | Future<Nothing> future = Nothing(); |
| 47 | |
| 48 | synchronized (data->lock) { |
| 49 | if (!data->write_locked && data->read_locked == 0u) { |
| 50 | data->write_locked = true; |
| 51 | } else { |
| 52 | Waiter w{Waiter::WRITE}; |
| 53 | future = w.promise.future(); |
| 54 | data->waiters.push(std::move(w)); |
| 55 | } |
| 56 | } |
| 57 | |
| 58 | return future; |
| 59 | } |
| 60 | |
| 61 | void write_unlock() |
| 62 | { |