16constexpr int32_t kMaxTasksStackSize = 64;
18DISPENSO_THREAD_LOCAL TaskSetBase* g_taskStack[kMaxTasksStackSize];
19DISPENSO_THREAD_LOCAL int32_t g_taskStackSize = 0;
21void pushThreadTaskSet(TaskSetBase* t) {
23 if (g_taskStackSize < 0 || g_taskStackSize >= kMaxTasksStackSize) {
24 fprintf(stderr,
"TaskSet parent stack index is invalid when pushing: %d\n", g_taskStackSize);
28 g_taskStack[g_taskStackSize++] = t;
30void popThreadTaskSet() {
32 if (g_taskStackSize <= 0) {
33 fprintf(stderr,
"TaskSet parent stack index is invalid when popping: %d\n", g_taskStackSize);
41TaskSetBase* parentTaskSet() {
42 using namespace detail;
45 if (g_taskStackSize < 0 || g_taskStackSize >= kMaxTasksStackSize) {
46 fprintf(stderr,
"TaskSet parent stack index is invalid when accessing: %d\n", g_taskStackSize);
51 return g_taskStackSize ? g_taskStack[g_taskStackSize - 1] :
nullptr;
54void TaskSetBase::trySetCurrentException() {
55#if defined(__cpp_exceptions)
57 if (guardException_.compare_exchange_strong(status, kSetting, std::memory_order_acq_rel)) {
58 exception_ = std::current_exception();
59 guardException_.store(kSet, std::memory_order_release);
60 canceled_.store(
true, std::memory_order_release);
65inline bool TaskSetBase::testAndResetException() {
66#if defined(__cpp_exceptions)
67 if (guardException_.load(std::memory_order_acquire) == kSet) {
68 auto exception = std::move(exception_);
69 guardException_.store(kUnset, std::memory_order_release);
70 std::rethrow_exception(exception);
73 return canceled_.load(std::memory_order_acquire);
85 if (!pool_.tryExecuteNext()) {
86 std::this_thread::yield();
95 if (!pool_.tryExecuteNext()) {
110moodycamel::ProducerToken TaskSet::makeToken(moodycamel::ConcurrentQueue<OnceFunction>&
pool) {
111 return moodycamel::ProducerToken(
pool);
119 while (pool_.tryExecuteNextFromProducerToken(token_)) {
123 if (!pool_.tryExecuteNext()) {
124 std::this_thread::yield();
134 if (!pool_.tryExecuteNextFromProducerToken(token_)) {
146 if (!pool_.tryExecuteNext()) {
147 std::this_thread::yield();
DISPENSO_DLL_ACCESS bool tryWait(size_t maxToExecute)
DISPENSO_DLL_ACCESS bool wait()
DISPENSO_DLL_ACCESS bool tryWait(size_t maxToExecute)
DISPENSO_DLL_ACCESS bool wait()
detail::OpResult< T > OpResult