OpenWalnut  1.5.0dev
Public Member Functions | Protected Member Functions | Protected Attributes | Friends | List of all members
WSharedObjectTicket< Data > Class Template Referenceabstract

Class which represents granted access to a locked object. More...

#include <WSharedObjectTicket.h>

+ Inheritance diagram for WSharedObjectTicket< Data >:
+ Collaboration diagram for WSharedObjectTicket< Data >:

Public Member Functions

virtual ~WSharedObjectTicket ()
 Destroys the ticket and releases the lock. More...
 
void suppressUnlockCondition ()
 If called, the unlock will NOT fire the condition. More...
 

Protected Member Functions

 WSharedObjectTicket (Data &data, std::shared_ptr< std::shared_mutex > mutex, std::shared_ptr< WCondition > condition)
 Create a new instance. More...
 
virtual void unlock ()=0
 Unlocks the mutex. More...
 

Protected Attributes

Data & m_data
 The data to which access is allowed by the ticket. More...
 
std::shared_ptr< std::shared_mutex > m_mutex
 The mutex used for locking. More...
 
std::shared_ptr< WConditionm_condition
 A condition which gets notified after unlocking. More...
 

Friends

class WSharedObject< Data >
 The shared object class needs protected access to create new instances. More...
 

Detailed Description

template<typename Data>
class WSharedObjectTicket< Data >

Class which represents granted access to a locked object.

It contains a reference to the object and a lock. The lock is freed after the ticket has been destroyed.

Note
This class does not provide any member to actually get the contained value/instance. This is done in read and write tickets.

Definition at line 45 of file WSharedObjectTicket.h.

Constructor & Destructor Documentation

◆ ~WSharedObjectTicket()

template<typename Data >
virtual WSharedObjectTicket< Data >::~WSharedObjectTicket ( )
inlinevirtual

Destroys the ticket and releases the lock.

Definition at line 55 of file WSharedObjectTicket.h.

References WSharedObjectTicket< Data >::m_condition.

◆ WSharedObjectTicket()

template<typename Data >
WSharedObjectTicket< Data >::WSharedObjectTicket ( Data &  data,
std::shared_ptr< std::shared_mutex >  mutex,
std::shared_ptr< WCondition condition 
)
inlineprotected

Create a new instance.

It is protected to avoid someone to create them. It locks the mutex.

Parameters
datathe data to protect
mutexthe mutex used to lock
conditiona condition that should be fired upon unlock. Can be NULL.

Definition at line 81 of file WSharedObjectTicket.h.

Member Function Documentation

◆ suppressUnlockCondition()

template<typename Data >
void WSharedObjectTicket< Data >::suppressUnlockCondition ( )
inline

If called, the unlock will NOT fire the condition.

This is useful in some situations if you find out "hey there actually was nothing changed".

Definition at line 68 of file WSharedObjectTicket.h.

References WSharedObjectTicket< Data >::m_condition.

◆ unlock()

template<typename Data >
virtual void WSharedObjectTicket< Data >::unlock ( )
protectedpure virtual

Unlocks the mutex.

Implemented in WSharedObjectTicketWrite< Data >, and WSharedObjectTicketRead< Data >.

Friends And Related Function Documentation

◆ WSharedObject< Data >

template<typename Data >
friend class WSharedObject< Data >
friend

The shared object class needs protected access to create new instances.

Definition at line 1 of file WSharedObjectTicket.h.

Member Data Documentation

◆ m_condition

template<typename Data >
std::shared_ptr< WCondition > WSharedObjectTicket< Data >::m_condition
protected

A condition which gets notified after unlocking.

Especially useful to notify waiting threads about a change in the object.

Definition at line 101 of file WSharedObjectTicket.h.

Referenced by WSharedObjectTicket< Data >::suppressUnlockCondition(), and WSharedObjectTicket< Data >::~WSharedObjectTicket().

◆ m_data

template<typename Data >
Data& WSharedObjectTicket< Data >::m_data
protected

The data to which access is allowed by the ticket.

Definition at line 91 of file WSharedObjectTicket.h.

◆ m_mutex

template<typename Data >
std::shared_ptr< std::shared_mutex > WSharedObjectTicket< Data >::m_mutex
protected

The mutex used for locking.

Definition at line 96 of file WSharedObjectTicket.h.


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