jubilant-funicular
src
Semaphore.cpp
1
#include "nta/ThreadPool.h"
2
3
namespace
nta
{
4
namespace
utils {
5
Semaphore::Semaphore
(
int
value) : m_value(value) {
6
}
7
void
Semaphore::wait
() {
8
std::lock_guard<std::mutex> lg(
m_mutex
);
9
m_cv.wait(
m_mutex
, [
this
]{
return
m_value
> 0;});
10
m_value
--;
11
}
12
void
Semaphore::signal
() {
13
std::lock_guard<std::mutex> lg(
m_mutex
);
14
if
(
m_value
++ == 0) m_cv.notify_all();
15
}
16
}
17
}
nta::utils::Semaphore::Semaphore
Semaphore(int value=0)
Constructs Semaphore with given value.
Definition:
Semaphore.cpp:5
nta::utils::Semaphore::wait
void wait()
Halts until value of Semaphore is > 0.
Definition:
Semaphore.cpp:7
nta::utils::Semaphore::m_value
int m_value
The number of resources available.
Definition:
ThreadPool.h:23
nta
Definition:
Animation2D.h:6
nta::utils::Semaphore::signal
void signal()
Increments value of Semaphore.
Definition:
Semaphore.cpp:12
nta::utils::Semaphore::m_mutex
std::mutex m_mutex
Thread safety stuff.
Definition:
ThreadPool.h:20
Generated by
1.8.17