Main Page
Namespaces
Classes
Files
File List
File Members
include
micros_swarm
semaphore.h
Go to the documentation of this file.
1
23
#ifndef MY_SEMAPHORE_H_
24
#define MY_SEMAPHORE_H_
25
26
#include <iostream>
27
#include <boost/thread.hpp>
28
29
namespace
micros_swarm
{
30
class
Semaphore
{
31
public
:
32
Semaphore
(
int
value):
value_
(value){}
33
Semaphore
(
const
Semaphore
&) =
delete
;
34
35
void
P
()
36
{
37
boost::unique_lock<boost::mutex> lock(
mutex_
);
38
while
(
value_
== 0) {
39
condition_
.
wait
(lock);
40
}
41
42
value_
--;
43
}
44
45
void
V
()
46
{
47
boost::unique_lock<boost::mutex> lock(
mutex_
);
48
value_
++;
49
50
condition_
.
notify_one
();
51
}
52
private
:
53
int
value_
;
54
boost::mutex
mutex_
;
55
boost::condition_variable
condition_
;
56
};
57
};
58
59
#endif
micros_swarm
Definition:
app_manager.h:44
boost::condition_variable::wait
void wait(unique_lock< mutex > &m)
micros_swarm::Semaphore
Definition:
semaphore.h:30
micros_swarm::Semaphore::P
void P()
Definition:
semaphore.h:35
micros_swarm::Semaphore::V
void V()
Definition:
semaphore.h:45
micros_swarm::Semaphore::mutex_
boost::mutex mutex_
Definition:
semaphore.h:54
boost::condition_variable
micros_swarm::Semaphore::Semaphore
Semaphore(int value)
Definition:
semaphore.h:32
boost::condition_variable::notify_one
void notify_one() BOOST_NOEXCEPT
micros_swarm::Semaphore::condition_
boost::condition_variable condition_
Definition:
semaphore.h:55
micros_swarm::Semaphore::value_
int value_
Definition:
semaphore.h:53
micros_swarm
Author(s):
autogenerated on Mon Jun 10 2019 14:02:06