Skip to content

api/thread.h

Namespaces

Name
cvedia
cvedia::rt
API for controlling the server and lifecycle management of runtime instances.
cvedia::rt::internal
cvedia::rt::iface
cvedia::rt::api
cvedia::rt::api::thread
cvedia::rt::api:🧵:current

Classes

Name
class cvedia::rt::api:🧵:DetachedThreadScope
class cvedia::rt::api:🧵:ThreadRegistrationScope

Types

Name
enum class ThreadType
enum class StorageType
enum class Affinity

Functions

Name
bool isWorkerThread()
void sleep(int ms)
Sleep thread.
void dump()
NODISCARD expected< std::shared_ptr< internal::ThreadContext > > getThreadContext()
NODISCARD expected< int > getThreadVersion()
NODISCARD expected< std::shared_ptr< iface::Solution > > getActiveSolution()
NODISCARD expected< void > setActiveSolution(std::weak_ptr< iface::Solution > solution)
NODISCARD expected< std::shared_ptr< iface::Instance > > getActiveInstance()
Returns the Instance of an existing instance.
NODISCARD expected< void > setActiveInstance(std::weak_ptr< iface::Instance > instance)
NODISCARD expected< void > pinOnCpuCore()
NODISCARD expected< void > clearActiveInstance()
NODISCARD expected< void > unregisterThread()
NODISCARD expected< void > unregisterThread(std:🧵:id id)
void deleteAllThreads()
NODISCARD expected< void > registerThread(ThreadType t, int version =1, std::weak_ptr< iface::Instance > instance ={}, std::string const & location ="")
NODISCARD expected< void > registerThread(std::thread && th, ThreadType t, int version =1, std::string const & location ="")
NODISCARD expected< std::unique_ptr< ThreadRegistrationScope > > registerThreadScoped(ThreadType t, int version =1, std::string const & location ="")
NODISCARD expected< std::unique_ptr< ThreadRegistrationScope > > registerThreadScoped(ThreadType t, int version, std::weak_ptr< iface::Instance > instance, std::string const & location)
NODISCARD expected< std::unique_ptr< ThreadRegistrationScope > > registerThreadScopedOld(ThreadType t, int version =1, std::string const & location ="")
NODISCARD expected< std::unique_ptr< ThreadRegistrationScope > > registerThreadScopedOld(ThreadType t, int version, std::weak_ptr< iface::Instance > instance, std::string const & location)
NODISCARD bool isRegistered()
NODISCARD bool isRegistered(std:🧵:id id)
void setPerformanceMode(Affinity mode)
void setPerformanceModeOnThread(Affinity mode, std::thread & th)
NODISCARD expected< void > setThreadStorage(StorageType s)
NODISCARD expected< int > getVersion()
NODISCARD expected< void > setVersion(int version)
NODISCARD expected< StorageType > getThreadStorage()
NODISCARD expected< void > step(int steps =1)
NODISCARD int getThreadCount(std::weak_ptr< iface::Instance > instance, ThreadType type)
NODISCARD expected< float > getCounterValue(const std::string & name)
NODISCARD expected< void > setCounterValue(const std::string & name, uint32_t value)
NODISCARD expected< void > waitForThreads(std::weak_ptr< iface::Instance > instance, ThreadType type)
NODISCARD expected< void > waitForThread(std:🧵:id id)
expected< std::unique_lock< shared_mutex_class > > getWriteLock()
expected< std::shared_lock< shared_mutex_class > > getReadLock()

Attributes

Name
std::atomic< int > detachedThreadCount

Defines

Name
REGISTER_THREAD_SCOPED(threadType)
REGISTER_THREAD_SCOPED_WARN(threadType)
TRY_REGISTER_THREAD_SCOPED(threadType)
REGISTER_WORKER_THREAD_SCOPED
REGISTER_WORKER_THREAD_SCOPED_WARN
TRY_REGISTER_WORKER_THREAD_SCOPED
REGISTER_INSTANCE_THREAD_SCOPED
REGISTER_INSTANCE_THREAD_SCOPED_WARN
TRY_REGISTER_INSTANCE_THREAD_SCOPED
REGISTER_GLOBAL_THREAD_SCOPED
REGISTER_GLOBAL_THREAD_SCOPED_WARN
TRY_REGISTER_GLOBAL_THREAD_SCOPED
DETACHED_THREAD_SCOPED

Types Documentation

enum ThreadType

Enumerator Value Description
Global
Instance
Worker

enum StorageType

Enumerator Value Description
Global
Solution
Instance
None

enum Affinity

Enumerator Value Description
Powersave
Performance

Functions Documentation

function isWorkerThread

bool isWorkerThread()

function sleep

void sleep(
    int ms
)

Sleep thread.

Parameters:

  • number $ms Milliseconds to sleep

function dump

void dump()

function getThreadContext

NODISCARD expected< std::shared_ptr< internal::ThreadContext > > getThreadContext()

function getThreadVersion

NODISCARD expected< int > getThreadVersion()

function getActiveSolution

NODISCARD expected< std::shared_ptr< iface::Solution > > getActiveSolution()

function setActiveSolution

NODISCARD expected< void > setActiveSolution(
    std::weak_ptr< iface::Solution > solution
)

function getActiveInstance

NODISCARD expected< std::shared_ptr< iface::Instance > > getActiveInstance()

Returns the Instance of an existing instance.

Return: shared_ptr

function setActiveInstance

NODISCARD expected< void > setActiveInstance(
    std::weak_ptr< iface::Instance > instance
)

function pinOnCpuCore

NODISCARD expected< void > pinOnCpuCore()

function clearActiveInstance

NODISCARD expected< void > clearActiveInstance()

function unregisterThread

NODISCARD expected< void > unregisterThread()

function unregisterThread

NODISCARD expected< void > unregisterThread(
    std::thread::id id
)

function deleteAllThreads

void deleteAllThreads()

function registerThread

NODISCARD expected< void > registerThread(
    ThreadType t,
    int version =1,
    std::weak_ptr< iface::Instance > instance ={},
    std::string const & location =""
)

function registerThread

NODISCARD expected< void > registerThread(
    std::thread && th,
    ThreadType t,
    int version =1,
    std::string const & location =""
)

function registerThreadScoped

NODISCARD expected< std::unique_ptr< ThreadRegistrationScope > > registerThreadScoped(
    ThreadType t,
    int version =1,
    std::string const & location =""
)

function registerThreadScoped

NODISCARD expected< std::unique_ptr< ThreadRegistrationScope > > registerThreadScoped(
    ThreadType t,
    int version,
    std::weak_ptr< iface::Instance > instance,
    std::string const & location
)

function registerThreadScopedOld

NODISCARD expected< std::unique_ptr< ThreadRegistrationScope > > registerThreadScopedOld(
    ThreadType t,
    int version =1,
    std::string const & location =""
)

function registerThreadScopedOld

NODISCARD expected< std::unique_ptr< ThreadRegistrationScope > > registerThreadScopedOld(
    ThreadType t,
    int version,
    std::weak_ptr< iface::Instance > instance,
    std::string const & location
)

function isRegistered

NODISCARD bool isRegistered()

function isRegistered

NODISCARD bool isRegistered(
    std::thread::id id
)

function setPerformanceMode

void setPerformanceMode(
    Affinity mode
)

function setPerformanceModeOnThread

void setPerformanceModeOnThread(
    Affinity mode,
    std::thread & th
)

function setThreadStorage

NODISCARD expected< void > setThreadStorage(
    StorageType s
)

function getVersion

NODISCARD expected< int > getVersion()

function setVersion

NODISCARD expected< void > setVersion(
    int version
)

function getThreadStorage

NODISCARD expected< StorageType > getThreadStorage()

function step

NODISCARD expected< void > step(
    int steps =1
)

function getThreadCount

NODISCARD int getThreadCount(
    std::weak_ptr< iface::Instance > instance,
    ThreadType type
)

function getCounterValue

NODISCARD expected< float > getCounterValue(
    const std::string & name
)

function setCounterValue

NODISCARD expected< void > setCounterValue(
    const std::string & name,
    uint32_t value
)

function waitForThreads

NODISCARD expected< void > waitForThreads(
    std::weak_ptr< iface::Instance > instance,
    ThreadType type
)

function waitForThread

NODISCARD expected< void > waitForThread(
    std::thread::id id
)

function getWriteLock

expected< std::unique_lock< shared_mutex_class > > getWriteLock()

function getReadLock

expected< std::shared_lock< shared_mutex_class > > getReadLock()

Attributes Documentation

variable detachedThreadCount

std::atomic< int > detachedThreadCount = 0;

Macros Documentation

define REGISTER_THREAD_SCOPED

#define REGISTER_THREAD_SCOPED(
    threadType
)
    auto &&__registrationScopeExp = ::cvedia::rt::api::thread::registerThreadScoped(threadType, 1, __LOCATION__); \
    if (!__registrationScopeExp) { \
        return; \
    } \
    auto __registrationScope = std::move(__registrationScopeExp.value())

define REGISTER_THREAD_SCOPED_WARN

#define REGISTER_THREAD_SCOPED_WARN(
    threadType
)
    auto &&__registrationScopeExp = ::cvedia::rt::api::thread::registerThreadScoped(threadType, 1, __LOCATION__); \
    if (!__registrationScopeExp) { \
        LOGW << "Failed to register thread: " << __registrationScopeExp.error().message(); \
        return; \
    } \
    auto __registrationScope = std::move(__registrationScopeExp.value())

define TRY_REGISTER_THREAD_SCOPED

#define TRY_REGISTER_THREAD_SCOPED(
    threadType
)
RT_TRY(auto __registrationScope, ::cvedia::rt::api::thread::registerThreadScoped(threadType, 1, __LOCATION__))

define REGISTER_WORKER_THREAD_SCOPED

#define REGISTER_WORKER_THREAD_SCOPED REGISTER_THREAD_SCOPED(cvedia::rt::ThreadType::Worker)

define REGISTER_WORKER_THREAD_SCOPED_WARN

#define REGISTER_WORKER_THREAD_SCOPED_WARN REGISTER_THREAD_SCOPED_WARN(cvedia::rt::ThreadType::Worker)

define TRY_REGISTER_WORKER_THREAD_SCOPED

#define TRY_REGISTER_WORKER_THREAD_SCOPED TRY_REGISTER_THREAD_SCOPED(cvedia::rt::ThreadType::Worker)

define REGISTER_INSTANCE_THREAD_SCOPED

#define REGISTER_INSTANCE_THREAD_SCOPED REGISTER_THREAD_SCOPED(cvedia::rt::ThreadType::Instance)

define REGISTER_INSTANCE_THREAD_SCOPED_WARN

#define REGISTER_INSTANCE_THREAD_SCOPED_WARN REGISTER_THREAD_SCOPED_WARN(cvedia::rt::ThreadType::Instance)

define TRY_REGISTER_INSTANCE_THREAD_SCOPED

#define TRY_REGISTER_INSTANCE_THREAD_SCOPED TRY_REGISTER_THREAD_SCOPED(cvedia::rt::ThreadType::Instance)

define REGISTER_GLOBAL_THREAD_SCOPED

#define REGISTER_GLOBAL_THREAD_SCOPED REGISTER_THREAD_SCOPED(cvedia::rt::ThreadType::Global)

define REGISTER_GLOBAL_THREAD_SCOPED_WARN

#define REGISTER_GLOBAL_THREAD_SCOPED_WARN REGISTER_THREAD_SCOPED_WARN(cvedia::rt::ThreadType::Global)

define TRY_REGISTER_GLOBAL_THREAD_SCOPED

#define TRY_REGISTER_GLOBAL_THREAD_SCOPED TRY_REGISTER_THREAD_SCOPED(cvedia::rt::ThreadType::Global)

define DETACHED_THREAD_SCOPED

#define DETACHED_THREAD_SCOPED ::cvedia::rt::api::thread::DetachedThreadScope __detachedThreadScope