Cbeam
Loading...
Searching...
No Matches
cbeam::concurrency Namespace Reference

Provides concurrency primitives and abstractions for multithreaded programming. It features the powerful message_manager class for managing asynchronous message queues with flexible ordering (FIFO, FILO, or RANDOM), as well as threaded_object, which uses CRTP to encapsulate worker-thread logic with built-in synchronization. These classes simplify threaded operations, interprocess synchronization, and message dispatch under varying concurrency scenarios. More...

Classes

class  message_manager
 
class  named_recursive_mutex
 Provides a cross-platform interface for recursive named mutexes, enabling interprocess synchronization. More...
 
struct  tagTHREADNAME_INFO
 
class  threaded_object
 

Typedefs

using process_id_type = DWORD
 Defines a platform-independent type for process identifiers.
 
using thread_id_type = HANDLE
 
typedef struct cbeam::concurrency::tagTHREADNAME_INFO THREADNAME_INFO
 

Functions

std::size_t get_max_shm_name_length ()
 
process_id_type get_current_process_id ()
 Retrieves the current process's identifier in a platform-independent manner.
 
thread_id_type get_current_thread_id ()
 Retrieves the current thread's native identifier.
 
void set_thread_name (uint32_t dwThreadID, const char *thread_name)
 Sets the name for a thread with a specified Thread ID.
 
void set_thread_name (const char *thread_name)
 Sets the name of the current thread.
 
void set_thread_name (std::thread &thread, const char *thread_name)
 Sets the name of a std::thread on Windows.
 
std::wstring get_thread_name (thread_id_type id)
 Retrieves the name of the specified thread.
 
std::wstring to_string (concurrency::thread_id_type id, std::size_t mask=(std::size_t) -1)
 Returns a hexadecimal string representation of the given thread ID.
 

Detailed Description

Provides concurrency primitives and abstractions for multithreaded programming. It features the powerful message_manager class for managing asynchronous message queues with flexible ordering (FIFO, FILO, or RANDOM), as well as threaded_object, which uses CRTP to encapsulate worker-thread logic with built-in synchronization. These classes simplify threaded operations, interprocess synchronization, and message dispatch under varying concurrency scenarios.

Typedef Documentation

◆ process_id_type

Defines a platform-independent type for process identifiers.

On Windows, this is defined as DWORD, representing the native process ID type. On Unix-based systems (Linux, macOS), this is defined as pid_t, the standard type for process IDs.

◆ thread_id_type

◆ THREADNAME_INFO

Function Documentation

◆ get_current_process_id()

process_id_type cbeam::concurrency::get_current_process_id ( )
inline

Retrieves the current process's identifier in a platform-independent manner.

On Windows, this function wraps the GetCurrentProcessId() call. On Unix-based systems, it calls getpid().

Returns
process_id_type The unique identifier of the current process.

◆ get_current_thread_id()

thread_id_type cbeam::concurrency::get_current_thread_id ( )
inline

Retrieves the current thread's native identifier.

On Windows, the returned identifier is a HANDLE to the current thread. On other platforms, this is a pthread_t.

Returns
thread_id_type The native identifier of the current thread.

◆ get_max_shm_name_length()

std::size_t cbeam::concurrency::get_max_shm_name_length ( )
inline

◆ get_thread_name()

std::wstring cbeam::concurrency::get_thread_name ( thread_id_type id)
inline

Retrieves the name of the specified thread.

Parameters
idThe thread identifier.
Returns
std::wstring The name of the thread, or an empty string if not available or on failure.

◆ set_thread_name() [1/3]

void cbeam::concurrency::set_thread_name ( const char * thread_name)
inline

Sets the name of the current thread.

Parameters
thread_nameThe name to set for the current thread.

◆ set_thread_name() [2/3]

void cbeam::concurrency::set_thread_name ( std::thread & thread,
const char * thread_name )
inline

Sets the name of a std::thread on Windows.

Parameters
threadThe std::thread object whose name is to be set.
thread_nameThe name to assign to that thread.

◆ set_thread_name() [3/3]

void cbeam::concurrency::set_thread_name ( uint32_t dwThreadID,
const char * thread_name )
inline

Sets the name for a thread with a specified Thread ID.

This Windows-specific function uses a debugger exception mechanism to associate a name with a thread in debugging tools like Visual Studio.

Parameters
dwThreadIDThe numeric thread ID.
thread_nameThe name to set for the thread.

◆ to_string()

std::wstring cbeam::concurrency::to_string ( concurrency::thread_id_type id,
std::size_t mask = (std::size_t)-1 )
inline

Returns a hexadecimal string representation of the given thread ID.

Parameters
idThe thread identifier.
maskA bitmask to apply to the thread ID before conversion. May be used to achieve a shortened string representation. Defaults to all bits set.
Returns
std::wstring The hexadecimal string representation of the thread ID.