Botan
3.6.1
Crypto and TLS for C&
src
lib
utils
thread_utils
semaphore.cpp
Go to the documentation of this file.
1
/*
2
* Semaphore
3
* (C) 2013 Joel Low
4
*
5
* Botan is released under the Simplified BSD License (see license.txt)
6
*/
7
8
#include <botan/internal/semaphore.h>
9
10
// Based on code by Pierre Gaston (http://p9as.blogspot.com/2012/06/c11-semaphores.html)
11
12
namespace
Botan
{
13
14
void
Semaphore::release
(
size_t
n) {
15
for
(
size_t
i = 0; i != n; ++i) {
16
std::lock_guard<std::mutex>
lock
(m_mutex);
17
18
if
(m_value++ < 0) {
19
++m_wakeups;
20
m_cond.notify_one();
21
}
22
}
23
}
24
25
void
Semaphore::acquire
() {
26
std::unique_lock<std::mutex>
lock
(m_mutex);
27
if
(m_value-- <= 0) {
28
m_cond.wait(
lock
, [
this
] {
return
m_wakeups > 0; });
29
--m_wakeups;
30
}
31
}
32
33
}
// namespace Botan
Botan::Semaphore::release
void release(size_t n=1)
Definition
semaphore.cpp:14
Botan::Semaphore::acquire
void acquire()
Definition
semaphore.cpp:25
Botan
Definition
alg_id.cpp:13
Botan::lock
secure_vector< T > lock(const std::vector< T > &in)
Definition
secmem.h:70
Generated by
1.12.0