Scroom 0.14-48-ga0fee447
Loading...
Searching...
No Matches
Scroom::Semaphore Class Reference

#include <semaphore.hh>

Collaboration diagram for Scroom::Semaphore:
Collaboration graph

Public Member Functions

 Semaphore (unsigned int count=0)
 
void P ()
 
void V ()
 
template<typename duration_type >
bool P (duration_type const &rel_time)
 
bool try_P ()
 

Private Attributes

unsigned int count
 
boost::condition_variable cond
 
boost::mutex mut
 

Constructor & Destructor Documentation

◆ Semaphore()

Scroom::Semaphore::Semaphore ( unsigned int  count = 0)
inlineexplicit
34 : count(count_)
35 {
36 }
unsigned int count
Definition semaphore.hh:18

Member Function Documentation

◆ P() [1/2]

void Scroom::Semaphore::P ( )
inline
39 {
40 boost::mutex::scoped_lock lock(mut);
41 while(count == 0)
42 {
43 cond.wait(lock);
44 }
45 count--;
46 }
boost::condition_variable cond
Definition semaphore.hh:19
boost::mutex mut
Definition semaphore.hh:20

Referenced by WaitForAsyncOp::operator()(), and A::~A().

Here is the caller graph for this function:

◆ P() [2/2]

template<typename duration_type >
bool Scroom::Semaphore::P ( duration_type const &  rel_time)
inline
62 {
63 boost::posix_time::ptime const timeout = boost::posix_time::second_clock::universal_time() + rel_time;
64
65 boost::mutex::scoped_lock lock(mut);
66 while(count == 0)
67 {
68 if(!cond.timed_wait(lock, timeout))
69 {
70 return false;
71 }
72 }
73 count--;
74 return true;
75 }

◆ try_P()

bool Scroom::Semaphore::try_P ( )
inline
49 {
50 boost::mutex::scoped_lock const lock(mut);
51 if(count > 0)
52 {
53 count--;
54 return true;
55 }
56
57 return false;
58 }

◆ V()

void Scroom::Semaphore::V ( )
inline
78 {
79 boost::mutex::scoped_lock const lock(mut);
80 count++;
81 cond.notify_one();
82 }

Referenced by A::operator()(), B< R >::operator()(), WaitForAsyncOp::operator()(), and A::~A().

Here is the caller graph for this function:

Member Data Documentation

◆ cond

boost::condition_variable Scroom::Semaphore::cond
private

Referenced by P(), P(), and V().

◆ count

unsigned int Scroom::Semaphore::count
private

Referenced by P(), P(), try_P(), and V().

◆ mut

boost::mutex Scroom::Semaphore::mut
private

Referenced by P(), P(), try_P(), and V().


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