Cbeam
Loading...
Searching...
No Matches
cbeam::container::thread_safe_container< T > Class Template Reference

Base class for thread safe containers. More...

#include <thread_safe_container.hpp>

Classes

class  lock_guard
 Inner class providing RAII-style locking mechanism. More...
 

Public Member Functions

lock_guard get_lock_guard () const
 Acquires a lock guard for the set, ensuring thread safety.
 
 thread_safe_container ()=default
 Default constructor.
 
virtual ~thread_safe_container () noexcept
 
bool empty () const
 Checks if the container is empty.
 
void clear ()
 Clears the contents.
 
std::size_t size () const
 Returns the number of elements.
 
auto begin ()
 Returns an iterator to the beginning.
 
auto end ()
 Returns an iterator to the end.
 
bool is_being_modified () const
 

Protected Attributes

std::recursive_mutex _mutex
 Mutex to protect access to _container.
 
_container
 Internal non-thread safe container.
 
std::atomic< bool > _is_being_modified {false}
 

Detailed Description

template<typename T>
class cbeam::container::thread_safe_container< T >

Base class for thread safe containers.

Template Parameters
TType of the container

Constructor & Destructor Documentation

◆ thread_safe_container()

template<typename T>
cbeam::container::thread_safe_container< T >::thread_safe_container ( )
default

Default constructor.

◆ ~thread_safe_container()

template<typename T>
virtual cbeam::container::thread_safe_container< T >::~thread_safe_container ( )
inlinevirtualnoexcept

Member Function Documentation

◆ begin()

template<typename T>
auto cbeam::container::thread_safe_container< T >::begin ( )
inline

Returns an iterator to the beginning.

◆ clear()

template<typename T>
void cbeam::container::thread_safe_container< T >::clear ( )
inline

Clears the contents.

◆ empty()

template<typename T>
bool cbeam::container::thread_safe_container< T >::empty ( ) const
inline

Checks if the container is empty.

Returns
true if the container is empty, false otherwise

◆ end()

template<typename T>
auto cbeam::container::thread_safe_container< T >::end ( )
inline

Returns an iterator to the end.

◆ get_lock_guard()

template<typename T>
lock_guard cbeam::container::thread_safe_container< T >::get_lock_guard ( ) const
inline

Acquires a lock guard for the set, ensuring thread safety.

This method provides a mechanism to acquire a lock on the set's mutex, ensuring that no other thread can modify the set while the lock is held. The returned lock guard object will release the lock when it goes out of scope.

Returns
A lock_guard object that manages the lock on the set's mutex.
Exceptions
cbeam::error::runtime_errorif the set is being modified during the call.

◆ is_being_modified()

template<typename T>
bool cbeam::container::thread_safe_container< T >::is_being_modified ( ) const
inline

◆ size()

template<typename T>
std::size_t cbeam::container::thread_safe_container< T >::size ( ) const
inline

Returns the number of elements.

Returns
The number of elements in the container

Member Data Documentation

◆ _container

template<typename T>
T cbeam::container::thread_safe_container< T >::_container
protected

Internal non-thread safe container.

◆ _is_being_modified

template<typename T>
std::atomic<bool> cbeam::container::thread_safe_container< T >::_is_being_modified {false}
protected

◆ _mutex

template<typename T>
std::recursive_mutex cbeam::container::thread_safe_container< T >::_mutex
mutableprotected

Mutex to protect access to _container.


The documentation for this class was generated from the following file: