/
AutoPacket.cpp
687 lines (600 loc) · 22.9 KB
/
AutoPacket.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
// Copyright (C) 2012-2018 Leap Motion, Inc. All rights reserved.
#include "stdafx.h"
#include "AutoCurrentPacketPusher.h"
#include "AutoPacket.h"
#include "AutoPacketFactory.h"
#include "AutoPacketInternal.hpp"
#include "AutoFilterDescriptor.h"
#include "autowiring_error.h"
#include "ContextEnumerator.h"
#include "demangle.h"
#include "SatCounter.h"
#include "thread_specific_ptr.h"
#include <algorithm>
#include <sstream>
#include RVALUE_HEADER
using namespace autowiring;
/// <summary>
/// A pointer to the current AutoPacket, specific to the current thread.
/// </summary>
static thread_specific_ptr<AutoPacket> autoCurrentPacket([] (void*) {});
AutoPacket::AutoPacket(AutoPacketFactory& factory, std::shared_ptr<void>&& outstanding):
m_parentFactory(std::static_pointer_cast<AutoPacketFactory>(factory.shared_from_this())),
m_outstanding(std::move(outstanding))
{
// Need to ensure our identity type is instantiated
(void) auto_id_t_init<AutoPacket>::init;
}
AutoPacket::~AutoPacket(void) {
m_parentFactory->RecordPacketDuration(
std::chrono::duration_cast<std::chrono::nanoseconds>(
std::chrono::high_resolution_clock::now() - m_initTime
)
);
// Needed for the AutoPacketGraph
NotifyTeardownListeners();
// Safe linked list unwind
for (auto cur = m_firstCounter; cur;) {
auto next = cur->flink;
delete cur;
cur = next;
}
}
DecorationDisposition& AutoPacket::DecorateImmediateUnsafe(const DecorationKey& key, const void* pvImmed)
{
// Obtain the decoration disposition of the entry we will be returning
DecorationDisposition& dec = m_decoration_map[key];
if (dec.m_state != DispositionState::Unsatisfied) {
std::stringstream ss;
ss << "Cannot perform immediate decoration with type " << demangle(key.id)
<< ", the requested decoration already exists";
throw autowiring_error(ss.str());
}
// Mark the entry as appropriate:
dec.m_state = DispositionState::Complete;
dec.m_pImmediate = pvImmed;
return dec;
}
void AutoPacket::AddSatCounterUnsafe(SatCounter& satCounter) {
for(auto pCur = satCounter.GetAutoFilterArguments(); *pCur; pCur++) {
DecorationKey key(pCur->id);
DecorationDisposition& entry = m_decoration_map[key];
// Decide what to do with this entry:
if (pCur->is_input) {
if (entry.m_publishers.size() > 1 && !pCur->is_multi) {
std::stringstream ss;
ss << "Cannot add listener for multi-broadcast type " << demangle(pCur->id);
throw autowiring_error(ss.str());
}
if (entry.m_state == DispositionState::Complete) {
// Either decorations must be present, or the decoration type must be a shared_ptr.
if (!entry.m_decorations.empty() || pCur->is_shared) {
satCounter.Decrement();
}
}
}
if (pCur->is_rvalue) {
// Throw exception when there is already a modifier with the same altitude,
// otherwise insert it to the right position so that the modifiers vector is sorted by altitude
auto it = entry.m_modifiers.begin();
while (it != entry.m_modifiers.end()) {
if (it->altitude == satCounter.GetAltitude()) {
std::stringstream ss;
ss << "Added multiple rvalue decorations with same altitudes for type " << demangle(pCur->id);
throw autowiring_error(ss.str());
}
if (it->altitude > satCounter.GetAltitude())
break;
it++;
}
entry.m_modifiers.emplace(it, pCur->is_shared, satCounter.GetAltitude(), &satCounter);
} else {
if (pCur->is_input) {
entry.m_subscribers.emplace(
pCur->is_shared,
pCur->is_multi ?
DecorationDisposition::Subscriber::Type::Multi :
pCur->is_shared ?
DecorationDisposition::Subscriber::Type::Optional :
DecorationDisposition::Subscriber::Type::Normal,
satCounter.GetAltitude(),
&satCounter
);
}
if (pCur->is_output) {
if (!entry.m_publishers.empty()) {
for (const auto& subscriber : entry.m_subscribers) {
for (auto pOther = subscriber.satCounter->GetAutoFilterArguments(); *pOther; pOther++) {
if (pOther->id == pCur->id && !pOther->is_multi) {
std::stringstream ss;
ss << "Added identical data broadcasts of type " << demangle(pCur->id) << " with existing subscriber.";
throw autowiring_error(ss.str());
}
}
}
if (!entry.m_modifiers.empty()) {
std::stringstream ss;
ss << "Added identical data broadcasts of type " << demangle(pCur->id) << " with existing modifier.";
throw autowiring_error(ss.str());
}
}
entry.m_publishers.push_back(&satCounter);
}
}
}
auto tempVisited = std::unordered_set<SatCounter*>();
auto permVisited = std::unordered_set<SatCounter*>();
DetectCycle(satCounter, tempVisited, permVisited);
}
void AutoPacket::DetectCycle(SatCounter& satCounter, std::unordered_set<SatCounter*>& tempVisited, std::unordered_set<SatCounter*>& permVisited) {
if (tempVisited.count(&satCounter)) {
std::stringstream ss;
ss << "Detected cycle in the auto filter graph involving type " << demangle(satCounter.GetType());
throw autowiring_error(ss.str());
}
if (permVisited.count(&satCounter))
return;
std::unordered_set<SatCounter*> nextCounters;
for(auto pCur = satCounter.GetAutoFilterArguments(); *pCur; pCur++) {
if (!pCur->is_output) continue;
DecorationKey key(pCur->id);
DecorationDisposition& entry = m_decoration_map[key];
for (auto& subscriber : entry.m_subscribers) {
auto ptr = subscriber.satCounter;
nextCounters.insert(ptr);
}
}
if (nextCounters.empty())
return;
tempVisited.insert(&satCounter);
for (auto pCounter : nextCounters) {
DetectCycle(*pCounter, tempVisited, permVisited);
}
permVisited.insert(&satCounter);
tempVisited.erase(&satCounter);
}
void AutoPacket::RemoveSatCounterUnsafe(const SatCounter& satCounter) {
for (auto pCur = satCounter.GetAutoFilterArguments(); *pCur; pCur++) {
DecorationKey key(pCur->id);
DecorationDisposition& entry = m_decoration_map[key];
if (pCur->is_rvalue) {
entry.m_modifiers.erase(
std::remove_if(
entry.m_modifiers.begin(),
entry.m_modifiers.end(),
[&satCounter](const DecorationDisposition::Modifier& modifier){
return modifier.satCounter && *modifier.satCounter == satCounter;
}
),
entry.m_modifiers.end()
);
} else {
if (pCur->is_input) {
for (auto& sub : entry.m_subscribers) {
if (sub.satCounter && *sub.satCounter == satCounter) {
entry.m_subscribers.erase(sub);
break;
}
}
}
if (pCur->is_output) {
entry.m_publishers.erase(
std::remove_if(
entry.m_publishers.begin(),
entry.m_publishers.end(),
[&satCounter](SatCounter* publisher){
return publisher && *publisher == satCounter;
}),
entry.m_publishers.end()
);
}
}
}
}
void AutoPacket::MarkUnsatisfiable(const DecorationKey& key) {
// Ensure correct type if instantiated here
std::unique_lock<std::mutex> lk(m_lock);
auto& entry = m_decoration_map[key];
// Clear all decorations and pointers attached here
entry.m_state = DispositionState::Complete;
entry.m_decorations.clear();
entry.m_pImmediate = nullptr;
// Notify all consumers
UpdateSatisfactionUnsafe(std::move(lk), entry);
}
void AutoPacket::UpdateSatisfactionUnsafe(std::unique_lock<std::mutex> lk, const DecorationDisposition& disposition) {
// Update satisfaction inside of lock
if (disposition.m_state != DispositionState::Complete)
// Nothing to do yet
return;
// Any filter that who can take this decoration as an optional input should be called
std::vector<SatCounter*> callQueue;
// Recursively mark unsatisfiable any single-output arguments on these subscribers:
std::vector<const AutoFilterArgument*> unsatOutputArgs;
auto markOutputsUnsat = [&unsatOutputArgs] (SatCounter& satCounter) {
// make sure each satCounter only gets marked once
if (!satCounter.remaining)
return;
satCounter.remaining = 0;
const auto* args = satCounter.GetAutoFilterArguments();
for (size_t i = satCounter.GetArity(); i--;) {
// Only consider output arguments:
if (args[i].is_output)
// This output is transitively unsatisfiable, include it for later removal
unsatOutputArgs.push_back(&args[i]);
}
};
if (!disposition.m_modifiers.empty() && disposition.m_decorations.size() > 1)
throw autowiring_error("An AutoFilter was detected which has single-decorate rvalue argument in a graph with multi-decorate outputs");
for (auto modifier : disposition.m_modifiers) {
if (!modifier.satCounter)
continue;
auto& satCounter = *modifier.satCounter;
if (modifier.is_shared) {
if (satCounter.Decrement()) {
lk.unlock();
callQueue.push_back(&satCounter);
{
AutoCurrentPacketPusher apkt(*this);
for (SatCounter* call : callQueue)
call->GetCall()(call->GetAutoFilter().ptr(), *this);
}
callQueue.clear();
lk.lock();
}
} else {
switch(disposition.m_decorations.size()) {
case 0:
markOutputsUnsat(satCounter);
break;
case 1:
if (satCounter.Decrement())
callQueue.push_back(&satCounter);
break;
default:
// should not reach here
throw autowiring_error("An AutoFilter was detected which has single-decorate rvalue argument in a graph with multi-decorate outputs");
}
}
}
switch (disposition.m_decorations.size()) {
case 0:
// No decorations here whatsoever.
// Subscribers that cannot be invoked should have their outputs recursively marked unsatisfiable.
// Subscribers that can be invoked should be.
for (auto subscriber : disposition.m_subscribers) {
auto& satCounter = *subscriber.satCounter;
if (!satCounter.remaining)
// Skip subscribers that have already been called--a decoration is being expunged from the packet,
// but the filter in question has already been invoked, and so its outputs are already on the packet
continue;
switch (subscriber.type) {
case DecorationDisposition::Subscriber::Type::Multi:
case DecorationDisposition::Subscriber::Type::Optional:
// Optional, we will just generate a call to this subscriber, if possible:
if (satCounter.Decrement())
callQueue.push_back(&satCounter);
break;
case DecorationDisposition::Subscriber::Type::Normal:
// Non-optional, consider outputs and recursively invalidate
markOutputsUnsat(satCounter);
break;
}
}
break;
case 1:
// One unique decoration available. We should be able to call everyone.
for (auto subscriber : disposition.m_subscribers) {
auto& satCounter = *subscriber.satCounter;
if (satCounter.Decrement())
callQueue.push_back(&satCounter);
}
break;
default:
// Multiple decorations. Single-input types should never be encountered, but if they are,
// we can't call them. Always call multi-input entries.
for (auto subscriber : disposition.m_subscribers) {
if (subscriber.type != DecorationDisposition::Subscriber::Type::Multi)
throw autowiring_error("An AutoFilter was detected which has single-decorate inputs in a graph with multi-decorate outputs");
// One more entry for this input to consider
if(subscriber.satCounter->Decrement())
callQueue.push_back(subscriber.satCounter);
}
break;
}
lk.unlock();
// Generate all calls
{
AutoCurrentPacketPusher apkt(*this);
for (SatCounter* call : callQueue)
call->GetCall()(call->GetAutoFilter().ptr(), *this);
}
// Mark all unsatisfiable output types
for (auto unsatOutputArg : unsatOutputArgs) {
// One more producer run, even though we couldn't attach any new decorations
auto& disposition = m_decoration_map[DecorationKey{unsatOutputArg->id}];
if(disposition.IncProducerCount())
// Recurse on this entry
UpdateSatisfactionUnsafe(std::unique_lock<std::mutex>{m_lock}, disposition);
}
}
void AutoPacket::PulseSatisfactionUnsafe(std::unique_lock<std::mutex> lk, DecorationDisposition* pTypeSubs[], size_t nInfos) {
std::vector<SatCounter*> callQueue;
std::vector<SatCounter*> reincrement;
// We will need to loop as long as each pass results in something more to be executed
do
{
// Empty everything first
callQueue.clear();
reincrement.clear();
// First pass, decrement what we can:
for (size_t i = nInfos; i--;)
for (const auto& cur : pTypeSubs[i]->m_subscribers) {
SatCounter* satCounter = cur.satCounter;
if (
// Require that this counter not need a shared pointer, because we can't provide one
!cur.is_shared &&
// We only care about sat counters that aren't deferred--skip everyone else
// Deferred calls will be too late.
!satCounter->IsDeferred() &&
// And we have something to decrement
satCounter->remaining
)
{
if (satCounter->Decrement())
// This one is satisfied, we will need to call it
callQueue.push_back(satCounter);
else
// Reincrement. We need to retain total control over this immediate-mode decoration.
// If a decrementation happens in another thread context due to a simultaneous call
// to DecorateImmediate, we could wind up with a race condition. Multiple decorations
// passed to DecorateImmediate may satisfy simultaneously, however, so we want to
// delay reincrementation until after the loop concludes
reincrement.push_back(satCounter);
}
}
// Reincrement anything that didn't zero out. This is safe to do even if some of these
// entries are present in the callQueue; if there's a call in the callQueue, we will assign
// the saturation counter to zero anyway.
for (auto& cur : reincrement)
cur->Increment();
// Run through calls while unsynchronized:
lk.unlock();
for (SatCounter* call : callQueue) {
call->GetCall()(call->GetAutoFilter().ptr(), *this);
call->remaining = 0;
}
lk.lock();
} while (!callQueue.empty());
}
bool AutoPacket::HasUnsafe(const DecorationKey& key) const {
auto q = m_decoration_map.find(key);
if(q == m_decoration_map.end())
return false;
return !q->second.m_decorations.empty();
}
void AutoPacket::DecorateNoPriors(const AnySharedPointer& ptr, DecorationKey key) {
DecorationDisposition* disposition;
std::unique_lock<std::mutex> lk(m_lock);
disposition = &m_decoration_map[key];
switch (disposition->m_state) {
case DispositionState::Complete:
{
std::stringstream ss;
if (disposition->m_decorations.empty())
// Completed with no decorations, unsatisfiable
ss << "Cannot check out decoration of type " << demangle(ptr)
<< ", it has been marked unsatisfiable";
else
ss << "Cannot decorate this packet with type " << demangle(ptr)
<< ", the requested decoration is already satisfied";
throw autowiring_error(ss.str());
}
break;
default:
break;
}
// Decoration attaches here, if it is non-null
if(ptr)
disposition->m_decorations.push_back(ptr);
if(disposition->IncProducerCount())
UpdateSatisfactionUnsafe(std::move(lk), *disposition);
}
void AutoPacket::Decorate(const AnySharedPointer& ptr, DecorationKey key) {
auto cur = shared_from_this();
// Update satisfaction set on this entry
cur->DecorateNoPriors(ptr, key);
}
void AutoPacket::RemoveDecoration(DecorationKey key) {
std::lock_guard<std::mutex> lk(m_lock);
auto q = m_decoration_map.find(key);
if (q == m_decoration_map.end())
return;
q->second.m_decorations.clear();
}
const DecorationDisposition* AutoPacket::GetDisposition(const DecorationKey& key) const {
std::lock_guard<std::mutex> lk(m_lock);
auto q = m_decoration_map.find(key);
if (q != m_decoration_map.end() && q->second.m_state == DispositionState::Complete)
return &q->second;
return nullptr;
}
bool AutoPacket::HasSubscribers(const DecorationKey& key) const {
std::lock_guard<std::mutex> lk(m_lock);
auto q = m_decoration_map.find(key);
return
q == m_decoration_map.end() ?
false :
q->second.m_subscribers.size() != 0;
}
size_t AutoPacket::HasPublishers(const DecorationKey& key) const {
std::lock_guard<std::mutex> lk(m_lock);
auto q = m_decoration_map.find(key);
return
q == m_decoration_map.end() ?
0 :
q->second.m_publishers.size();
}
const SatCounter& AutoPacket::GetSatisfaction(auto_id subscriber) const {
std::lock_guard<std::mutex> lk(m_lock);
for (auto* sat = m_firstCounter; sat; sat = sat->flink)
if (sat->GetType() == subscriber)
return *sat;
throw autowiring_error("Attempted to get the satisfaction counter for an unavailable subscriber");
}
void AutoPacket::ThrowNotDecoratedException(const DecorationKey& key) {
std::stringstream ss;
ss << "Attempted to obtain a type " << demangle(key.id) << " which was not decorated on this packet";
throw autowiring_error(ss.str());
}
void AutoPacket::ThrowMultiplyDecoratedException(const DecorationKey& key) {
std::stringstream ss;
ss << "Attempted to obtain a type " << demangle(key.id) << " which was decorated more than once on this packet";
throw autowiring_error(ss.str());
}
size_t AutoPacket::GetDecorationTypeCount(void) const
{
std::lock_guard<std::mutex> lk(m_lock);
return m_decoration_map.size();
}
AutoPacket::t_decorationMap AutoPacket::GetDecorations(void) const
{
std::lock_guard<std::mutex> lk(m_lock);
return m_decoration_map;
}
bool AutoPacket::IsUnsatisfiable(const auto_id& id) const
{
const DecorationDisposition* pDisposition = GetDisposition(DecorationKey{ id });
if (!pDisposition)
// We have never heard of this type
return false;
if (!pDisposition->m_decorations.empty())
// We have some actual decorations, we know this is not unsatisfiable
return false;
if (pDisposition->m_nProducersRun != pDisposition->m_publishers.size())
// Some producers have not yet run, we could still feasibly get a decoration back
return false;
return true;
}
void AutoPacket::ForwardAll(const std::shared_ptr<AutoPacket>& recipient) const {
// Copy decorations into an internal decorations maintenance collection. The values
// in this collection are guaranteed to be stable in memory, and there are stable states
// that can be relied upon without synchronization.
std::vector<std::pair<DecorationKey, DecorationDisposition>> dd;
{
std::lock_guard<std::mutex> lk(m_lock);
for (const auto& decoration : m_decoration_map)
// Only fully complete decorations are considered for propagation
if (decoration.second.m_state == DispositionState::Complete)
dd.push_back(decoration);
}
// Lock down recipient collection while we go through and attach decorations:
for (auto& cur : dd)
for (const auto& decoration : cur.second.m_decorations)
recipient->Decorate(decoration, cur.first);
}
const SatCounter* AutoPacket::AddRecipient(const AutoFilterDescriptor& descriptor) {
SatCounter& sat = *new SatCounter(descriptor);
// Linked list insertion:
{
std::lock_guard<std::mutex> lk(m_lock);
for (auto cur = m_firstCounter; cur; cur=cur->flink) {
if (*cur == sat)
return cur;
}
sat.flink = m_firstCounter;
if (m_firstCounter)
m_firstCounter->blink = &sat;
m_firstCounter = &sat;
// Update satisfaction & Append types from subscriber
AddSatCounterUnsafe(sat);
}
if (!sat.remaining)
// Filter is ready to be called, oblige it
sat.GetCall()(sat.GetAutoFilter().ptr(), *this);
return &sat;
}
void AutoPacket::RemoveRecipient(const SatCounter& recipient) {
// Remove the recipient from our list
std::lock_guard<std::mutex> lk(m_lock);
if (recipient.blink)
recipient.blink->flink = recipient.flink;
if (recipient.flink)
recipient.flink->blink = recipient.blink;
RemoveSatCounterUnsafe(recipient);
}
AutoPacket* AutoPacket::SetCurrent(AutoPacket* apkt) {
AutoPacket* prior = autoCurrentPacket.get();
if(apkt)
autoCurrentPacket.reset(apkt);
else
autoCurrentPacket.release();
return prior;
}
AutoPacket& AutoPacket::CurrentPacket(void) {
auto retVal = autoCurrentPacket.get();
if (!retVal)
throw autowiring_error("Attempted to obtain a current AutoPacket, which was not made");
return *retVal;
}
std::shared_ptr<CoreContext> AutoPacket::GetContext(void) const {
return m_parentFactory->GetContext();
}
bool AutoPacket::Wait(std::condition_variable& cv, const AutoFilterArgument* inputs, std::chrono::nanoseconds duration) {
auto stub = std::make_shared<SignalStub>(*this, cv);
// This ad-hoc filter detects when all the requested decorations have been added, and then
// sets the necessary flags to inform the user
AddRecipient(
AutoFilterDescriptor(
stub,
AutoFilterDescriptorStub(
auto_id_t<AutoPacketFactory>{},
altitude::Dispatch,
inputs,
false,
[] (const void* pObj, AutoPacket&) {
SignalStub* stub = (SignalStub*)pObj;
// Completed, mark the output as satisfied and update the condition variable
std::condition_variable* pcv;
{
std::lock_guard<std::mutex>{stub->packet.m_lock};
stub->is_satisfied = true;
pcv = stub->cv;
}
// Only notify while the condition variable is still valid
if (pcv)
pcv->notify_all();
}
)
)
);
// This lambda will detect when the packet has been abandoned without all of the necessary
// decorations. In that case, the satisfaction flag is left in its initial state
AddTeardownListener(
[stub] {
std::condition_variable* pcv;
{
std::lock_guard<std::mutex> lk(stub->packet.m_lock);
stub->is_complete = true;
pcv = stub->cv;
}
// Only notify the condition variable if it's still present
if (pcv)
pcv->notify_all();
}
);
// Delay for the requested period:
std::unique_lock<std::mutex> lk(m_lock);
auto x = MakeAtExit([&stub] {
// Clear the condition variable out of the stub to prevent anyone else from trying to signal it
stub->cv = nullptr;
});
bool bRet =
duration == std::chrono::nanoseconds::max() ?
cv.wait(lk, [&] { return stub->is_complete; }), true :
cv.wait_for(lk, duration, [&] { return stub->is_satisfied || stub->is_complete; });
// If we didn't get all of the decorations we wanted we should throw an exception indicating this
if (!stub->is_satisfied)
throw autowiring_error("Not all of the requested decorations were available on a packet at the conclusion of Call");
return bRet;
}