ros2_control - jazzy
Loading...
Searching...
No Matches
realtime_tools Namespace Reference

A pthread mutex wrapper that provides a mutex with the priority inheritance protocol and a priority ceiling of 99. The mutex is also error checked and robust. This mutex is intended to be used in real-time contexts. More...

Classes

class  AsyncSchedulingPolicy
 Enum class to define the scheduling policy for the async worker thread. SYNCHRONIZED: The async worker thread will be synchronized with the main thread, as the main thread will be triggering the async callback method. DETACHED: The async worker thread will be detached from the main thread and will have its own execution cycle. SELF_PACED: The async worker thread will be scheduled by the hardware, by blocking at start of read() until a UDP packet arrives. Then the control cycle is started. UNKNOWN: The scheduling policy is unknown. More...
struct  AsyncFunctionHandlerParams
 The AsyncFunctionHandlerParams struct is used to configure the AsyncFunctionHandler. If the type is SYNCHRONIZED, the async worker thread will be synchronized with the main thread, as the main thread will be triggering the async callback method. If the type is DETACHED, the async worker thread will be detached from the main thread and will have its own execution cycle. If the type is SELF_PACED, the async worker thread paces itself. The callback must block, for example in a hardware read(). More...
class  AsyncFunctionHandler
 Class to handle asynchronous function calls. AsyncFunctionHandler is a class that allows the user to have a asynchronous call to the parsed method and be able to set some thread specific parameters. More...
class  LockFreePooledSPSCQueue
 Wait-free SPSC queue for large or move-only types, backed by a preallocated pool. More...
class  LockFreeQueueBase
 A base class for lock-free queues. More...
class  RealtimeBuffer
class  RealtimeClock
class  RealtimePublisher
class  RealtimeServerGoalHandle
class  RealtimeThreadSafeBox

Typedefs

template<class DataType, std::size_t Capacity = 0>
using LockFreeSPSCQueue
 Lock-free Single Producer Single Consumer Queue.
template<class DataType, std::size_t Capacity = 0, bool FixedSize = true>
using LockFreeMPMCQueue
 Lock-free Multiple Producer Multiple Consumer Queue.
using prio_inherit_mutex = detail::mutex<detail::error_mutex_type_t, detail::robust_robustness_t>
using prio_inherit_recursive_mutex
template<class T, typename mutex_type = std::mutex>
using RealtimeBoxBase = RealtimeThreadSafeBox<T, mutex_type>
template<typename T>
using RealtimeBoxStandard = RealtimeBoxBase<T, std::mutex>
template<typename T>
using RealtimeBoxRecursive = RealtimeBoxBase<T, std::recursive_mutex>
template<typename T>
using RealtimeBox = RealtimeBoxStandard<T>
template<class MessageT>
using RealtimePublisherSharedPtr = std::shared_ptr<RealtimePublisher<MessageT>>
using rt_server_goal_handle_mutex = prio_inherit_mutex
template<typename T>
using RealtimeThreadSafeBoxRecursive = RealtimeThreadSafeBox<T, RECURSIVE_MUTEX>
template<class T, typename mutex_type = std::mutex>
using RealtimeBoxBase

Functions

bool has_realtime_kernel ()
bool configure_sched_fifo (int priority)
bool configure_sched_rr (int priority)
bool lock_memory (std::string &message)
std::pair< bool, std::string > lock_memory ()
std::pair< bool, std::string > set_thread_affinity (NATIVE_THREAD_HANDLE thread, const std::vector< int > &cores)
std::pair< bool, std::string > set_thread_affinity (NATIVE_THREAD_HANDLE thread, int core)
std::pair< bool, std::string > set_thread_affinity (std::thread &thread, int core)
std::pair< bool, std::string > set_current_thread_affinity (int core)
std::pair< bool, std::string > set_current_thread_affinity (const std::vector< int > &cores)
std::pair< bool, std::string > set_current_thread_name (const std::string &name)
int64_t get_number_of_available_processors ()

Variables

template<typename T>
constexpr auto is_ptr_or_smart_ptr = rcpputils::is_pointer<T>::value

Detailed Description

A pthread mutex wrapper that provides a mutex with the priority inheritance protocol and a priority ceiling of 99. The mutex is also error checked and robust. This mutex is intended to be used in real-time contexts.

Author
Sai Kishor Kothakota
Sai Kishor Kothakota
Note
This mutex is not recursive.
Author
Stuart Glaser

Typedef Documentation

◆ LockFreeMPMCQueue

template<class DataType, std::size_t Capacity = 0, bool FixedSize = true>
using realtime_tools::LockFreeMPMCQueue
Initial value:
std::conditional_t<
Capacity == 0,
DataType, boost::lockfree::queue<DataType, boost::lockfree::fixed_sized<FixedSize>>>,
DataType,
boost::lockfree::queue<
DataType, boost::lockfree::capacity<Capacity>, boost::lockfree::fixed_sized<FixedSize>>>>
A base class for lock-free queues.
Definition lock_free_queue.hpp:119

Lock-free Multiple Producer Multiple Consumer Queue.

Template Parameters
DataTypeType of the data to be stored in the queue
CapacityCapacity of the queue
FixedSizeFixed size of the queue

◆ LockFreeSPSCQueue

template<class DataType, std::size_t Capacity = 0>
using realtime_tools::LockFreeSPSCQueue
Initial value:
std::conditional_t<
DataType, boost::lockfree::spsc_queue<DataType, boost::lockfree::capacity<Capacity>>>>

Lock-free Single Producer Single Consumer Queue.

Template Parameters
DataTypeType of the data to be stored in the queue
CapacityCapacity of the queue

◆ prio_inherit_recursive_mutex

using realtime_tools::prio_inherit_recursive_mutex
Initial value:
A class template that provides a pthread mutex with the priority inheritance protocol.
Definition mutex.hpp:78

Function Documentation

◆ configure_sched_fifo()

bool realtime_tools::configure_sched_fifo ( int priority)

Configure SCHED_FIFO thread priority for the thread that calls this function

Parameters
[in]prioritythe priority of this thread from 0-99
Returns
true if configuring scheduler succeeded

◆ configure_sched_rr()

bool realtime_tools::configure_sched_rr ( int priority)

Configure SCHED_RR thread priority for the thread that calls this function. SCHED_RR threads of the same priority are time-sliced (round-robin) Useful on PREEMPT_RT kernels with multiple RT-priority threads.

Parameters
[in]priorityscheduling priority (platform-dependent; on Linux typically 1-99)
Returns
true if configuring scheduler succeeded

◆ get_number_of_available_processors()

int64_t realtime_tools::get_number_of_available_processors ( )

Method to get the amount of available cpu cores https://man7.org/linux/man-pages/man3/sysconf.3.html https://stackoverflow.com/a/150971

Returns
The number of processors currently online (available)

◆ has_realtime_kernel()

bool realtime_tools::has_realtime_kernel ( )

Detect if realtime kernel is present.

Returns
true if realtime kernel is detected

◆ lock_memory() [1/2]

std::pair< bool, std::string > realtime_tools::lock_memory ( )

Locks the memory pages of the calling thread to prevent page faults. By calling this method, the programs locks all pages mapped into the address space of the calling process and future mappings. This means that the kernel will not swap out the pages to disk i.e., the pages are guaranteed to stay in RAM until later unlocked - which is important for realtime applications.

Parameters
[out]messagea message describing the result of the operation
Returns
a pair of a boolean indicating whether the operation succeeded or not and a message describing the result of the operation

◆ lock_memory() [2/2]

bool realtime_tools::lock_memory ( std::string & message)

Locks the memory pages of the calling thread to prevent page faults. By calling this method, the programs locks all pages mapped into the address space of the calling process and future mappings. This means that the kernel will not swap out the pages to disk i.e., the pages are guaranteed to stay in RAM until later unlocked - which is important for realtime applications.

Parameters
[out]messagea message describing the result of the operation
Returns
true if memory locking succeeded, false otherwise.

◆ set_current_thread_affinity() [1/2]

std::pair< bool, std::string > realtime_tools::set_current_thread_affinity ( const std::vector< int > & cores)

Configure the current thread affinity - Tell the scheduler to prefer a certain set of cores for the current thread.

Note
The threads created by the calling thread will inherit the affinity.
Parameters
[in]corethe cpu numbers of the core. If an empty vector is passed, the affinity is reset to the default.
Returns
a pair of a boolean indicating whether the operation succeeded or not and a message describing the result of the operation

◆ set_current_thread_affinity() [2/2]

std::pair< bool, std::string > realtime_tools::set_current_thread_affinity ( int core)

Configure the current thread affinity - Tell the scheduler to prefer a certain core for the current thread.

Note
The threads created by the calling thread will inherit the affinity.
Parameters
[in]corethe cpu number of the core. If a negative number is passed, the affinity is reset to the default.
Returns
a pair of a boolean indicating whether the operation succeeded or not and a message describing the result of the operation

◆ set_current_thread_name()

std::pair< bool, std::string > realtime_tools::set_current_thread_name ( const std::string & name)

Configure the current thread name.

Parameters
[in]nameThe name for the thread. On Linux, it will be automatically truncated to 15 characters.
Returns
a pair of a boolean indicating whether the operation succeeded or not and a message describing the result of the operation

◆ set_thread_affinity() [1/3]

std::pair< bool, std::string > realtime_tools::set_thread_affinity ( NATIVE_THREAD_HANDLE thread,
const std::vector< int > & cores )

Configure the caller thread affinity - Tell the scheduler to prefer a certain set of cores for the given thread handle.

Note
The threads created by the calling thread will inherit the affinity.
Parameters
[in]threadthe thread handle of the thread
[in]corethe cpu numbers of the core. If an empty vector is passed, the affinity is reset to the default.
Returns
a pair of a boolean indicating whether the operation succeeded or not and a message describing the result of the operation

◆ set_thread_affinity() [2/3]

std::pair< bool, std::string > realtime_tools::set_thread_affinity ( NATIVE_THREAD_HANDLE thread,
int core )

Configure the caller thread affinity - Tell the scheduler to prefer a certain core for the given thread handle.

Note
The threads created by the calling thread will inherit the affinity.
Parameters
[in]threadthe thread handle of the thread
[in]corethe cpu number of the core. If a negative number is passed, the affinity is reset to the default.
Returns
a pair of a boolean indicating whether the operation succeeded or not and a message describing the result of the operation

◆ set_thread_affinity() [3/3]

std::pair< bool, std::string > realtime_tools::set_thread_affinity ( std::thread & thread,
int core )

Configure the caller thread affinity - Tell the scheduler to prefer a certain core for the given thread.

Note
The threads created by the calling thread will inherit the affinity.
Parameters
[in]threadthe reference of the thread
[in]corethe cpu number of the core. If a negative number is passed, the affinity is reset to the default.
Returns
a pair of a boolean indicating whether the operation succeeded or not and a message describing the result of the operation