| 158 | }; |
| 159 | |
| 160 | struct Data |
| 161 | { |
| 162 | Data() : read_locked(0), write_locked(false) {} |
| 163 | |
| 164 | ~Data() |
| 165 | { |
| 166 | // TODO(zhitao): Fail promises? |
| 167 | } |
| 168 | |
| 169 | // The state of the lock can be either: |
| 170 | // (1) Unlocked: an incoming read or write grabs the lock. |
| 171 | // |
| 172 | // (2) Read locked (by one or more readers): an incoming write |
| 173 | // will queue in the waiters. An incoming read will proceed |
| 174 | // if no one is waiting, otherwise it will queue. |
| 175 | // |
| 176 | // (3) Write locked: incoming reads and writes will queue. |
| 177 | |
| 178 | size_t read_locked; |
| 179 | bool write_locked; |
| 180 | std::queue<Waiter> waiters; |
| 181 | |
| 182 | // Rather than use a process to serialize access to the |
| 183 | // internal data we use a 'std::atomic_flag'. |
| 184 | std::atomic_flag lock = ATOMIC_FLAG_INIT; |
| 185 | }; |
| 186 | |
| 187 | std::shared_ptr<Data> data; |
| 188 | }; |
nothing calls this directly
no outgoing calls
no test coverage detected