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

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

#include <WSharedObjectTicketWrite.h>

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

Public Member Functions

virtual ~WSharedObjectTicketWrite ()
 Destroys the ticket and releases the lock. More...
 
Data & get () const
 Returns the protected data. More...
 
- Public Member Functions inherited from WSharedObjectTicket< Data >
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

 WSharedObjectTicketWrite (Data &data, std::shared_ptr< std::shared_mutex > mutex, std::shared_ptr< WCondition > condition)
 Create a new instance. More...
 
virtual void unlock ()
 Unlocks the mutex. More...
 
- Protected Member Functions inherited from WSharedObjectTicket< Data >
 WSharedObjectTicket (Data &data, std::shared_ptr< std::shared_mutex > mutex, std::shared_ptr< WCondition > condition)
 Create a new instance. More...
 

Protected Attributes

std::unique_lock< std::shared_mutex > m_lock
 The lock. More...
 
- Protected Attributes inherited from WSharedObjectTicket< Data >
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 WSharedObjectTicketWrite< 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. This class especially implements the exclusive (write) lock.

Definition at line 40 of file WSharedObjectTicketWrite.h.

Constructor & Destructor Documentation

◆ ~WSharedObjectTicketWrite()

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

Destroys the ticket and releases the lock.

Definition at line 50 of file WSharedObjectTicketWrite.h.

References WSharedObjectTicketWrite< Data >::unlock().

+ Here is the call graph for this function:

◆ WSharedObjectTicketWrite()

template<typename Data >
WSharedObjectTicketWrite< Data >::WSharedObjectTicketWrite ( 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 for write.

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

Definition at line 74 of file WSharedObjectTicketWrite.h.

Member Function Documentation

◆ get()

template<typename Data >
Data& WSharedObjectTicketWrite< Data >::get ( ) const
inline

Returns the protected data.

As long as you own the ticket, you are allowed to use it.

Returns
the data

Definition at line 61 of file WSharedObjectTicketWrite.h.

◆ unlock()

template<typename Data >
virtual void WSharedObjectTicketWrite< Data >::unlock ( )
inlineprotectedvirtual

Unlocks the mutex.

Implements WSharedObjectTicket< Data >.

Definition at line 88 of file WSharedObjectTicketWrite.h.

References WSharedObjectTicketWrite< Data >::m_lock.

Referenced by WSharedObjectTicketWrite< Data >::~WSharedObjectTicketWrite().

+ Here is the caller graph for this function:

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 WSharedObjectTicketWrite.h.

Member Data Documentation

◆ m_lock

template<typename Data >
std::unique_lock< std::shared_mutex > WSharedObjectTicketWrite< Data >::m_lock
protected

The lock.

Definition at line 83 of file WSharedObjectTicketWrite.h.

Referenced by WSharedObjectTicketWrite< Data >::unlock().


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