carb/tasking/IThreadPool.h

File members: carb/tasking/IThreadPool.h

// Copyright (c) 2019-2022, 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 "../Interface.h"

namespace carb
{
namespace tasking
{

class ThreadPool DOXYGEN_EMPTY_CLASS;

typedef void (*JobFn)(void* jobData);

struct IThreadPool
{
    CARB_PLUGIN_INTERFACE("carb::tasking::IThreadPool", 1, 0)

    ThreadPool*(CARB_ABI* createEx)(size_t workerCount);

    ThreadPool* create() const;

    void(CARB_ABI* destroy)(ThreadPool* threadPool);

    size_t(CARB_ABI* getDefaultWorkerCount)();

    size_t(CARB_ABI* getWorkerCount)(ThreadPool* threadPool);

    bool(CARB_ABI* enqueueJob)(ThreadPool* threadPool, JobFn jobFunction, void* jobData);

    size_t(CARB_ABI* getCurrentlyRunningJobCount)(ThreadPool* threadPool);

    void(CARB_ABI* waitUntilFinished)(ThreadPool* threadPool);
};

inline ThreadPool* IThreadPool::create() const
{
    return createEx(getDefaultWorkerCount());
}

} // namespace tasking
} // namespace carb