omni/kit/exec/core/unstable/TbbSchedulerState.h

File members: omni/kit/exec/core/unstable/TbbSchedulerState.h

// Copyright (c) 2022-2024, NVIDIA CORPORATION. All rights reserved.
//
// NVIDIA CORPORATION and its licensors retain all intellectual property
// and proprietary rights in and to this software, related documentation
// and any modifications thereto. Any use, reproduction, disclosure or
// distribution of this software and related documentation without an express
// license agreement from NVIDIA CORPORATION is strictly prohibited.
//

#pragma once

#include <carb/container/LocklessStack.h>

#include <tbb/enumerable_thread_specific.h>
#include <tbb/recursive_mutex.h>
CARB_IGNOREWARNING_GNUC_WITH_PUSH("-Wattributes")
#include <tbb/task.h>
CARB_IGNOREWARNING_GNUC_POP

#include <atomic>
#include <thread>

namespace omni
{
namespace kit
{
namespace exec
{
namespace core
{
namespace unstable
{

struct TbbSchedulerState
{
    struct TaskStackEntry : public tbb::task
    {
        carb::container::LocklessStackLink<TaskStackEntry> m_link;
    };

    carb::container::LocklessStack<TaskStackEntry, &TaskStackEntry::m_link> stackParallel;
    carb::container::LocklessStack<TaskStackEntry, &TaskStackEntry::m_link> stackSerial;
    carb::container::LocklessStack<TaskStackEntry, &TaskStackEntry::m_link> stackIsolate;

    std::atomic<int> totalTasksInFlight{ 0 };
    tbb::enumerable_thread_specific<int> tasksExecutingPerThread{ 0 };

    std::atomic<std::thread::id> serialThreadId;
    std::atomic<std::thread::id> isolateThreadId;

    tbb::recursive_mutex executingThreadMutex;
};

} // namespace unstable
} // namespace core
} // namespace exec
} // namespace kit
} // namespace omni