fpmas 1.6
Public Member Functions | List of all members
fpmas::synchro::hard::HardSyncMutex< T > Class Template Reference

#include <hard_sync_mutex.h>

Inheritance diagram for fpmas::synchro::hard::HardSyncMutex< T >:
Inheritance graph
[legend]
Collaboration diagram for fpmas::synchro::hard::HardSyncMutex< T >:
Collaboration graph
[legend]

Public Member Functions

 HardSyncMutex (fpmas::api::graph::DistributedNode< T > *node, MutexClient &mutex_client, MutexServer &mutex_server)
 
void pushRequest (Request request) override
 
std::queue< RequestrequestsToProcess () override
 
T & data () override
 
const T & data () const override
 
const T & read () override
 
void releaseRead () override
 
T & acquire () override
 
void releaseAcquire () override
 
void lock () override
 
void unlock () override
 
bool locked () const override
 
void lockShared () override
 
void unlockShared () override
 
int sharedLockCount () const override
 
void synchronize () override
 
virtual void pushRequest (MutexRequest request)=0
 
virtual std::queue< MutexRequestrequestsToProcess ()=0
 
virtual T & data ()=0
 
virtual const T & data () const =0
 
virtual const T & read ()=0
 
virtual void releaseRead ()=0
 
virtual T & acquire ()=0
 
virtual void releaseAcquire ()=0
 
virtual void lock ()=0
 
virtual void unlock ()=0
 
virtual bool locked () const =0
 
virtual void lockShared ()=0
 
virtual void unlockShared ()=0
 
virtual int sharedLockCount () const =0
 
virtual void synchronize ()=0
 

Additional Inherited Members

virtual void _lock ()=0
 
virtual void _lockShared ()=0
 
virtual void _unlock ()=0
 
virtual void _unlockShared ()=0
 

Detailed Description

template<typename T>
class fpmas::synchro::hard::HardSyncMutex< T >

HardSyncMode Mutex implementation.

Each operation is added to a queue and potentially transmitted to DISTANT processes to ensure a strict global concurrent access management.

Constructor & Destructor Documentation

◆ HardSyncMutex()

template<typename T >
fpmas::synchro::hard::HardSyncMutex< T >::HardSyncMutex ( fpmas::api::graph::DistributedNode< T > *  node,
MutexClient mutex_client,
MutexServer mutex_server 
)
inline

HardSyncMutex constructor.

Parameters
nodenode associated to this mutex
mutex_clientclient used to transmit requests to other processes
mutex_serverserver used to handle incoming mutex requests

Member Function Documentation

◆ pushRequest()

template<typename T >
void fpmas::synchro::hard::HardSyncMutex< T >::pushRequest ( Request  request)
overridevirtual

Pushes a pending request into the waiting queue.

Parameters
requestmutex request to push

Implements fpmas::synchro::hard::api::HardSyncMutex< T >.

◆ requestsToProcess()

template<typename T >
std::queue< typename HardSyncMutex< T >::Request > fpmas::synchro::hard::HardSyncMutex< T >::requestsToProcess ( )
overridevirtual

Returns an ordered list of requests that can be handled, depending on the current mutex status.

For example, if the mutex is locked, an empty queue might be returned. Else, read or lock shared requests can be returned, until the next pending acquire or lock request.

In any case, the exact behavior is implementation defined and might depend about what priority is given to each request. (e.g. : https://en.wikipedia.org/wiki/Readers%E2%80%93writers_problem)

Returns
an ordered queue of request that can safely be handled at the time of the call, depending on the current mutex status

Implements fpmas::synchro::hard::api::HardSyncMutex< T >.

◆ data() [1/2]

template<typename T >
T & fpmas::synchro::hard::HardSyncMutex< T >::data ( )
inlineoverridevirtual

Direct access to internal data representation.

Does not guarantee any concurrent access or data update management.

Returns
direct reference to internal data

Implements fpmas::api::synchro::Mutex< T >.

◆ data() [2/2]

template<typename T >
const T & fpmas::synchro::hard::HardSyncMutex< T >::data ( ) const
inlineoverridevirtual

Direct access to internal data representation.

Does not guarantee any concurrent access or data update management.

Returns
direct reference to internal data

Implements fpmas::api::synchro::Mutex< T >.

◆ read()

template<typename T >
const T & fpmas::synchro::hard::HardSyncMutex< T >::read
overridevirtual

Provides a read access to the internal data.

The functions blocks until data is effectively read.

Read data must be released using releaseRead().

Returns
reference to read data
Implementation details
If the protected node is LOCAL and locked, adds the local request to the queue and waits for the request to complete. Else if its unlocked, directly returns the read data (which is already local).
If the node is DISTANT, transmits the request using the MutexClient.
See also
MutexServer::wait()
MutexClient::read()

Implements fpmas::api::synchro::Mutex< T >.

◆ releaseRead()

template<typename T >
void fpmas::synchro::hard::HardSyncMutex< T >::releaseRead
overridevirtual

Releases a mutex previously accessed with read().

Implementation details
If the protected node is LOCAL, releases a shared lock from the mutex. If this unlocks the resource, the MutexServer is notified and pending requests are handled.
If the node is DISTANT, transmits the request using the MutexClient.
See also
MutexServer::notify()
MutexClient::releaseRead()

Implements fpmas::api::synchro::Mutex< T >.

◆ acquire()

template<typename T >
T & fpmas::synchro::hard::HardSyncMutex< T >::acquire
overridevirtual

Releases a mutex previously accessed with acquire().

Semantically, this operation also "commits" eventual write operations that were performed on the acquired data. However, the actual behavior is implementation defined.

Implementation details
If the protected node is LOCAL and locked, adds the local request to the queue and waits for the request to complete. Else if its unlocked, directly returns the acquired data (which is already local).
If the node is DISTANT, transmits the request using the MutexClient.
See also
MutexServer::wait()
MutexClient::acquire()

Implements fpmas::api::synchro::Mutex< T >.

◆ releaseAcquire()

template<typename T >
void fpmas::synchro::hard::HardSyncMutex< T >::releaseAcquire
overridevirtual

Releases a mutex previously accessed with acquire().

Semantically, this operation also "commits" eventual write operations that were performed on the acquired data. However, the actual behavior is implementation defined.

Implementation details
If the protected node is LOCAL, releases the exclusive lock from the mutex and notifies the MutexServer so that pending requests are handled.
If the node is DISTANT, transmits the request with local data updates using the MutexClient.
See also
MutexServer::notify()
MutexClient::releaseAcquire()

Implements fpmas::api::synchro::Mutex< T >.

◆ lock()

template<typename T >
void fpmas::synchro::hard::HardSyncMutex< T >::lock
overridevirtual

Locks the mutex.

This function blocks until internal data is effectively locked. Upon return, an exclusive access to the internal data is guaranteed. However, contrary to the acquire() function, this operation does not involve any data update or write operation handling.

A locked mutex must be unlocked using unlock().

Implementation details
If the protected node is LOCAL and locked, adds the local request to the queue and waits for the request to complete. Else if its unlocked, directly locks the mutex.
If the node is DISTANT, transmits the request using the MutexClient.
See also
MutexServer::wait()
MutexClient::lock()

Implements fpmas::api::synchro::Mutex< T >.

◆ unlock()

template<typename T >
void fpmas::synchro::hard::HardSyncMutex< T >::unlock
overridevirtual

Unlocks a mutex previously locked with lock().

Implementation details
If the protected node is LOCAL, releases the exclusive lock from the mutex and notifies the MutexServer so that pending requests are handled.
If the node is DISTANT, transmits the request using the MutexClient.
See also
MutexServer::notify()
MutexClient::unlock()

Implements fpmas::api::synchro::Mutex< T >.

◆ locked()

template<typename T >
bool fpmas::synchro::hard::HardSyncMutex< T >::locked ( ) const
inlineoverridevirtual

Returns true if and only if the mutex has been locked and not yet unlocked.

Returns
true iff mutex is locked

Implements fpmas::api::synchro::Mutex< T >.

◆ lockShared()

template<typename T >
void fpmas::synchro::hard::HardSyncMutex< T >::lockShared
overridevirtual

Obtains a shared lock access to the mutex.

This function blocks until a shared lock access to mutex is effectively obtained. Contrary to lock(), multiple threads are allowed to simultaneously obtain a shared lock to the mutex.

The mutex must then be unlocked using unlockShared().

Implementation details
If the protected node is LOCAL and locked, adds the local request to the queue and waits for the request to complete. Else if its unlocked (or shared lock), adds a share lock to the mutex.
If the node is DISTANT, transmits the request using the MutexClient.
See also
MutexServer::wait()
MutexClient::lockShared()

Implements fpmas::api::synchro::Mutex< T >.

◆ unlockShared()

template<typename T >
void fpmas::synchro::hard::HardSyncMutex< T >::unlockShared
overridevirtual

Unlocks a mutex previously locked with lockShared().

Semantically, all threads that called lockShared() must call unlockShared() to finally unlock the mutex.

Implementation details
If the protected node is LOCAL, releases a shared lock from the mutex. If this unlocks the resource, the MutexServer is notified and pending requests are handled.
If the node is DISTANT, transmits the request using the MutexClient.
See also
MutexServer::notify()
MutexClient::unlockShared()

Implements fpmas::api::synchro::Mutex< T >.

◆ sharedLockCount()

template<typename T >
int fpmas::synchro::hard::HardSyncMutex< T >::sharedLockCount ( ) const
inlineoverridevirtual

Returns the count of threads that currently own a shared lock access to the mutex.

Returns
shared lock count

Implements fpmas::api::synchro::Mutex< T >.

◆ synchronize()

template<typename T >
void fpmas::synchro::hard::HardSyncMutex< T >::synchronize ( )
inlineoverridevirtual

Method eventually called when data synchronization is performed on this Mutex.

The behavior of this method depends on the currently implemented SynchronizationMode.

Implements fpmas::api::synchro::Mutex< T >.


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