gPTP Documentation
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
TicketingLock Class Reference

#include <linux_hal_common.hpp>

Collaboration diagram for TicketingLock:
Collaboration graph

Public Member Functions

bool lock (bool *got=NULL)
 Lock mechanism. Gets a ticket and try locking the process. More...
 
bool unlock ()
 Unlock mechanism. Increments the release counter and unblock other threads waiting for a condition flag. More...
 
bool init ()
 Initializes all flags and counters. Create private structures. More...
 
 TicketingLock ()
 
 ~TicketingLock ()
 

Detailed Description

TicketingLock: Implements the ticket lock algorithm. A ticket lock consists of two counters, one containing the number of requests to acquire the lock, and the other the number of times the lock has been released. A processor acquires the lock by performing a fetch and increment operation on the request counter and waiting until the result its ticket is equal to the value of the release counter. It releases the lock by incrementing the release counter.

Constructor & Destructor Documentation

TicketingLock::TicketingLock ( )

Default constructor sets some flags to false that will be initialized on the init method. Protects against using lock/unlock without calling init.

TicketingLock::~TicketingLock ( )

Deletes the object and private structures.

Member Function Documentation

bool TicketingLock::init ( )

Initializes all flags and counters. Create private structures.

Returns
TRUE in case of success, FALSE otherwise.
bool TicketingLock::lock ( bool *  got = NULL)

Lock mechanism. Gets a ticket and try locking the process.

Parameters
got[out] If non-null, it is set to TRUE when the lock is acquired. FALSE otherwise.
Returns
TRUE when successfully got the lock, FALSE otherwise.
bool TicketingLock::unlock ( )

Unlock mechanism. Increments the release counter and unblock other threads waiting for a condition flag.

Returns
TRUE in case of success, FALSE otherwise.

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