25 #ifndef WSHAREDOBJECT_H
26 #define WSHAREDOBJECT_H
29 #include <shared_mutex>
31 #include <boost/thread.hpp>
33 #include "WCondition.h"
34 #include "WSharedObjectTicket.h"
35 #include "WSharedObjectTicketRead.h"
36 #include "WSharedObjectTicketWrite.h"
43 template <
typename T >
65 typedef std::shared_ptr< WSharedObjectTicketRead< T > >
ReadTicket;
70 typedef std::shared_ptr< WSharedObjectTicketWrite< T > >
WriteTicket;
75 typedef std::shared_ptr< WSharedObject< T > >
SPtr;
80 typedef std::shared_ptr< WSharedObject< T > >
ConstSPtr;
116 mutable std::shared_ptr< std::shared_mutex >
m_lock;
126 template <
typename T >
128 m_lock( new std::shared_mutex ),
134 template <
typename T >
140 template <
typename T >
143 return m_changeCondition;
146 template <
typename T >
149 return std::shared_ptr< WSharedObjectTicketRead< T > >(
154 template <
typename T >
159 return std::shared_ptr< WSharedObjectTicketWrite< T > >(
165 return std::shared_ptr< WSharedObjectTicketWrite< T > >(
Class to encapsulate boost::condition_variable_any.
Class which represents granted access to a locked object.
Class which represents granted access to a locked object.
Wrapper around an object/type for thread safe sharing of objects among multiple threads.
T m_object
The object wrapped by this class.
std::shared_ptr< std::shared_mutex > m_lock
The lock to ensure thread safe access.
std::shared_ptr< WSharedObject< T > > SPtr
Shared pointer abbreviation.
std::shared_ptr< WSharedObjectTicketRead< T > > ReadTicket
Type for read tickets.
std::shared_ptr< WCondition > m_changeCondition
This condition set fires whenever the contained object changes.
ReadTicket getReadTicket() const
Returns a ticket to get read access to the contained data.
std::shared_ptr< WSharedObjectTicketWrite< T > > WriteTicket
Type for write tickets.
virtual ~WSharedObject()
Destructor.
WriteTicket getWriteTicket(bool suppressNotify=false) const
Returns a ticket to get write access to the contained data.
std::shared_ptr< WCondition > getChangeCondition() const
This condition fires whenever the encapsulated object changed.
T ValueT
The type protected by this shared object class.
std::shared_ptr< WSharedObject< T > > ConstSPtr
Const shared ptr abbreviation.
WSharedObject()
Default constructor.