| 160 | } |
| 161 | |
| 162 | Future<Lock> lock(int priority = 0) { |
| 163 | prioritylock_printf("lock begin %s\n", toString().c_str()); |
| 164 | |
| 165 | // This shortcut may enable a waiter to jump the line when the releaser loop yields |
| 166 | if (available > 0) { |
| 167 | --available; |
| 168 | Lock p; |
| 169 | addRunner(p); |
| 170 | prioritylock_printf("lock exit immediate %s\n", toString().c_str()); |
| 171 | return p; |
| 172 | } |
| 173 | |
| 174 | Waiter w; |
| 175 | waiters[priority].push_back(w); |
| 176 | ++waiting; |
| 177 | prioritylock_printf("lock exit queued %s\n", toString().c_str()); |
| 178 | return w.lockPromise.getFuture(); |
| 179 | } |
| 180 | |
| 181 | std::string toString() const { |
| 182 | int runnersDone = 0; |
no test coverage detected