xrpld
Loading...
Searching...
No Matches
xrpl::BasicSemaphore< Mutex, CondVar > Class Template Reference

#include <semaphore.h>

Collaboration diagram for xrpl::BasicSemaphore< Mutex, CondVar >:

Public Types

using size_type = std::size_t

Public Member Functions

 BasicSemaphore (size_type count=0)
 Create the semaphore, with an optional initial count.
void notify ()
 Increment the count and unblock one waiting thread.
void wait ()
 Block until notify is called.
bool tryWait ()
 Perform a non-blocking wait.

Private Attributes

Mutex mutex_
CondVar cond_
std::size_t count_

Detailed Description

template<class Mutex, class CondVar>
class xrpl::BasicSemaphore< Mutex, CondVar >

Definition at line 37 of file semaphore.h.

Member Typedef Documentation

◆ size_type

template<class Mutex, class CondVar>
using xrpl::BasicSemaphore< Mutex, CondVar >::size_type = std::size_t

Definition at line 45 of file semaphore.h.

Constructor & Destructor Documentation

◆ BasicSemaphore()

template<class Mutex, class CondVar>
xrpl::BasicSemaphore< Mutex, CondVar >::BasicSemaphore ( size_type count = 0)
explicit

Create the semaphore, with an optional initial count.

If unspecified, the initial count is zero.

Definition at line 50 of file semaphore.h.

Member Function Documentation

◆ notify()

template<class Mutex, class CondVar>
void xrpl::BasicSemaphore< Mutex, CondVar >::notify ( )

Increment the count and unblock one waiting thread.

Definition at line 56 of file semaphore.h.

◆ wait()

template<class Mutex, class CondVar>
void xrpl::BasicSemaphore< Mutex, CondVar >::wait ( )

Block until notify is called.

Definition at line 65 of file semaphore.h.

◆ tryWait()

template<class Mutex, class CondVar>
bool xrpl::BasicSemaphore< Mutex, CondVar >::tryWait ( )

Perform a non-blocking wait.

Returns
true If the wait would be satisfied.

Definition at line 77 of file semaphore.h.

Member Data Documentation

◆ mutex_

template<class Mutex, class CondVar>
Mutex xrpl::BasicSemaphore< Mutex, CondVar >::mutex_
private

Definition at line 40 of file semaphore.h.

◆ cond_

template<class Mutex, class CondVar>
CondVar xrpl::BasicSemaphore< Mutex, CondVar >::cond_
private

Definition at line 41 of file semaphore.h.

◆ count_

template<class Mutex, class CondVar>
std::size_t xrpl::BasicSemaphore< Mutex, CondVar >::count_
private

Definition at line 42 of file semaphore.h.