OpenLibrary
|
Thread safe wrapper for objects. More...
#include <ts_resource.hpp>
Classes | |
struct | Accessor |
ThreadSafeResource's helper class. More... | |
struct | INotify |
Notification interface. More... | |
Public Member Functions | |
template<typename... Args> | |
ThreadSafeResource (const Args &...args) | |
Contructor. More... | |
~ThreadSafeResource () | |
ThreadSafeResource (const ThreadSafeResource< T > &)=delete | |
ThreadSafeResource< T > & | operator= (const ThreadSafeResource< T > &)=delete |
Accessor | lock () |
Accessor | lock (INotify *notify) |
Accessor | try_lock () |
Thread safe wrapper for objects.
ThreadSafeResource is a template class which allows to wrap any object (resource) into a thread safe container. Resource object must be constructed together with ThreadSafeResource (see ThreadSafeResource::ThreadSafeResource()). Then it can accessed by one thread at once. Any access to resource when it is already locked will cause in wait operation. To access locked resource call ThreadSafeResource::lock(). An Accessor object will be returned which is responsible for resource unlocking when no longer used.
|
inline |
Contructor.
Constructs ThreadSafeResource together with locked resource.
|
inline |
Destructor Destructs resource object. If it is still locked by some Accessor, destructor will wait until resource is released.
|
inline |
Locks a resource and returns access to it. As long as returned Accessor object exists the resource will be locked and unavailable for other threads.
|
inline |
Locks a resource and returns access to it. Behaves as lock() but calls INotify::unlocked() when object is being unlocked.
|
inline |
Tries to lock resource. Invalid Accessor will be returned when lock failed.