MCPcopy Create free account
hub / github.com/Snapchat/Valdi / barrier

Method barrier

valdi_core/src/valdi_core/cpp/Threading/TaskQueue.cpp:128–153  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

126
127 _condition.notifyAll();
128}
129
130DispatchFunction TaskQueue::lockFreeRemoveTask(task_id_t taskId) {
131 for (auto i = _tasks.begin(); i != _tasks.end(); ++i) {
132 if (i->id == taskId) {
133 auto task = std::move(*i);
134 _tasks.erase(i);
135 return std::move(task.function);
136 }
137 }
138
139 return DispatchFunction();
140}
141
142void TaskQueue::barrier(const DispatchFunction& function) {
143 auto executeTime = std::chrono::steady_clock::now();
144
145 std::unique_lock<Mutex> lockGuard(_mutex);
146 auto id = insertTask(DispatchFunction(), executeTime, true, 0);
147
148 while (!_tasks.empty()) {
149 // Wait until we have no currently running tasks, and that the task at the front is our barrier task
150 if (_currentRunningTasks != 0 || _tasks.front().id != id) {
151 _condition.wait(lockGuard);
152 continue;
153 }
154
155 // We have no running tasks, and our barrier task is at the front.
156 // We can now execute our barrier

Callers 2

syncMethod · 0.80
TESTFunction · 0.80

Calls 8

DispatchFunctionClass · 0.85
frontMethod · 0.80
notifyAllMethod · 0.80
nowFunction · 0.50
emptyMethod · 0.45
waitMethod · 0.45
unlockMethod · 0.45
lockMethod · 0.45

Tested by 1

TESTFunction · 0.64