Skip to content

Commit 067e040

Browse files
authored
Merge pull request #154 from arosenzweig3/sequencer-coro
Provide local::context() to Mutex::Guard
2 parents 826bb16 + 69447a1 commit 067e040

File tree

2 files changed

+23
-7
lines changed

2 files changed

+23
-7
lines changed

quantum/util/impl/quantum_sequencer_experimental_impl.h

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
//##############################################################################################
2121

2222
#include <quantum/util/quantum_drain_guard.h>
23+
#include <quantum/quantum_local.h>
2324
#include <quantum/quantum_promise.h>
2425
#include <quantum/quantum_traits.h>
2526
#include <quantum/impl/quantum_stl_impl.h>
@@ -281,7 +282,7 @@ Sequencer<SequenceKey, Hash, KeyEqual, Allocator>::enqueueSingle(
281282
queueId,
282283
isHighPriority);
283284

284-
Mutex::Guard lock(_mutex);
285+
Mutex::Guard lock(local::context(), _mutex);
285286

286287
_taskStats->incrementPostedTaskCount();
287288
_taskStats->incrementPendingTaskCount();
@@ -344,7 +345,7 @@ Sequencer<SequenceKey, Hash, KeyEqual, Allocator>::enqueueMultiple(
344345
queueId,
345346
isHighPriority);
346347

347-
Mutex::Guard lock(_mutex);
348+
Mutex::Guard lock(local::context(), _mutex);
348349

349350
_taskStats->incrementPostedTaskCount();
350351
_taskStats->incrementPendingTaskCount();
@@ -410,7 +411,7 @@ Sequencer<SequenceKey, Hash, KeyEqual, Allocator>::enqueueAllImpl(
410411
queueId,
411412
isHighPriority);
412413

413-
Mutex::Guard lock(_mutex);
414+
Mutex::Guard lock(local::context(), _mutex);
414415

415416
_taskStats->incrementPostedTaskCount();
416417
_taskStats->incrementPendingTaskCount();
@@ -433,7 +434,7 @@ template <class SequenceKey, class Hash, class KeyEqual, class Allocator>
433434
size_t
434435
Sequencer<SequenceKey, Hash, KeyEqual, Allocator>::trimSequenceKeys()
435436
{
436-
Mutex::Guard lock(_mutex);
437+
Mutex::Guard lock(local::context(), _mutex);
437438
for(typename PendingTaskQueueMap::iterator it = _pendingTaskQueueMap.begin(); it != _pendingTaskQueueMap.end(); )
438439
{
439440
if (it->second._tasks.empty())
@@ -448,7 +449,7 @@ template <class SequenceKey, class Hash, class KeyEqual, class Allocator>
448449
SequenceKeyStatistics
449450
Sequencer<SequenceKey, Hash, KeyEqual, Allocator>::getStatistics(const SequenceKey& sequenceKey)
450451
{
451-
Mutex::Guard lock(_mutex);
452+
Mutex::Guard lock(local::context(), _mutex);
452453
typename PendingTaskQueueMap::const_iterator it = _pendingTaskQueueMap.find(sequenceKey);
453454
if (it == _pendingTaskQueueMap.end())
454455
return SequenceKeyStatistics();
@@ -459,7 +460,7 @@ template <class SequenceKey, class Hash, class KeyEqual, class Allocator>
459460
SequenceKeyStatistics
460461
Sequencer<SequenceKey, Hash, KeyEqual, Allocator>::getStatistics()
461462
{
462-
Mutex::Guard lock(_mutex);
463+
Mutex::Guard lock(local::context(), _mutex);
463464
return *_universalTaskQueue._stats;
464465
}
465466

@@ -474,7 +475,7 @@ template <class SequenceKey, class Hash, class KeyEqual, class Allocator>
474475
size_t
475476
Sequencer<SequenceKey, Hash, KeyEqual, Allocator>::getSequenceKeyCount()
476477
{
477-
Mutex::Guard lock(_mutex);
478+
Mutex::Guard lock(local::context(), _mutex);
478479
return _pendingTaskQueueMap.size();
479480
}
480481

tests/quantum_sequencer_experimental_tests.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -670,4 +670,19 @@ TEST_P(SequencerExperimentalTest, PerformanceTest)
670670
0);
671671
}
672672

673+
TEST_P(SequencerExperimentalTest, CoroSafety)
674+
{
675+
// This test demonstrates that it is safe to call the experimental::Sequencer from within a
676+
// coroutine
677+
678+
SequencerExperimentalTestData::TaskSequencer sequencer{ getDispatcher() };
679+
680+
getDispatcher().post([&sequencer](VoidContextPtr ctx) -> int {
681+
sequencer.enqueue(0, [](VoidContextPtr ctx) -> int { return 0; });
682+
return 0;
683+
});
684+
685+
getDispatcher().drain();
686+
}
687+
673688
#endif // BLOOMBERG_QUANTUM_SEQUENCER_LITE_SUPPORT

0 commit comments

Comments
 (0)