22 for (
unsigned long i = 0; i < nodeCount; ++i)
23 lockNode(compositionState, nodeIndices[i], eventId);
31 recordWaiting(compositionState, eventId, nodeIndex);
36 std::unique_lock<std::mutex> lock(*
static_cast<std::mutex *
>(nodeContext->
nodeMutex));
37 static_cast<std::condition_variable *
>(nodeContext->
nodeConditionVariable)->wait(lock, [nodeContext, eventId]()
46 recordLocked(compositionState, eventId, nodeIndex);
54 for (
unsigned long i = 0; i < nodeCount; ++i)
63 unsigned long eventId = 0;
68 std::unique_lock<std::mutex> lock(*
static_cast<std::mutex *
>(nodeContext->
nodeMutex));
76 recordUnlocked(compositionState, eventId, nodeIndex);
82 void VuoNodeSynchronization::recordWaiting(
VuoCompositionState *compositionState,
unsigned long eventId,
unsigned long nodeIndex)
87 std::lock_guard<std::mutex> lock(statusMutex);
90 if (i != statusWaiting.end())
92 auto j = i->second.find(eventId);
93 if (j != i->second.end())
95 auto k = std::find(j->second.begin(), j->second.end(), nodeIndex);
96 if (k != j->second.end())
107 void VuoNodeSynchronization::recordLocked(
VuoCompositionState *compositionState,
unsigned long eventId,
unsigned long nodeIndex)
112 std::lock_guard<std::mutex> lock(statusMutex);
115 if (i != statusWaiting.end())
117 auto j = i->second.find(eventId);
118 if (j != i->second.end())
120 auto k = std::find(j->second.begin(), j->second.end(), nodeIndex);
121 if (k != j->second.end())
124 if (j->second.empty())
126 if (i->second.empty())
127 statusWaiting.erase(i);
133 if (i != statusLocked.end())
135 auto j = i->second.find(eventId);
136 if (j != i->second.end())
138 auto k = std::find(j->second.begin(), j->second.end(), nodeIndex);
139 if (k != j->second.end())
150 void VuoNodeSynchronization::recordUnlocked(
VuoCompositionState *compositionState,
unsigned long eventId,
unsigned long nodeIndex)
155 std::lock_guard<std::mutex> lock(statusMutex);
158 if (i != statusLocked.end())
160 auto j = i->second.find(eventId);
161 if (j != i->second.end())
163 auto k = std::find(j->second.begin(), j->second.end(), nodeIndex);
164 if (k != j->second.end())
167 if (j->second.empty())
169 if (i->second.empty())
170 statusLocked.erase(i);
177 VDebugLog(
"Error: Node %lu was unlocked without having been locked", nodeIndex);
183 void VuoNodeSynchronization::print(
void)
187 VUserLog(
"Enable debug mode to record status.");
191 std::lock_guard<std::mutex> lock(statusMutex);
194 oss <<
"=== locked ===" << endl << endl;
195 for (
auto i : statusLocked)
197 oss << i.first <<
":" << endl;
198 for (
auto j : i.second)
200 oss <<
" eventId " << j.first <<
":";
201 for (
unsigned long nodeIndex : j.second)
202 oss <<
" " << nodeIndex;
209 oss <<
"=== waiting to lock ===" << endl << endl;
210 for (
auto i : statusWaiting)
212 oss << i.first <<
":" << endl;
213 for (
auto j : i.second)
215 oss <<
" eventId " << j.first <<
":";
216 for (
unsigned long nodeIndex : j.second)
217 oss <<
" " << nodeIndex;
224 VUserLog(
"\n%s", oss.str().c_str());