Roc Toolkit internal modules
Roc Toolkit: real-time audio streaming
Toggle main menu visibility
Loading...
Searching...
No Matches
semaphore.h
Go to the documentation of this file.
1
/*
2
* Copyright (c) 2020 Roc Streaming authors
3
*
4
* This Source Code Form is subject to the terms of the Mozilla Public
5
* License, v. 2.0. If a copy of the MPL was not distributed with this
6
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
7
*/
8
9
//! @file roc_core/target_darwin/roc_core/semaphore.h
10
//! @brief Semaphore.
11
12
#ifndef ROC_CORE_SEMAPHORE_H_
13
#define ROC_CORE_SEMAPHORE_H_
14
15
#include <mach/semaphore.h>
16
17
#include "
roc_core/attributes.h
"
18
#include "
roc_core/noncopyable.h
"
19
#include "
roc_core/time.h
"
20
21
namespace
roc
{
22
namespace
core
{
23
24
//! Semaphore.
25
class
Semaphore
:
public
NonCopyable<> {
26
public
:
27
//! Initialize semaphore with given counter.
28
explicit
Semaphore
(
unsigned
counter = 0);
29
30
~Semaphore
();
31
32
//! Wait until the counter becomes non-zero, decrement it, and return true.
33
//! If deadline expires before the counter becomes non-zero, returns false.
34
//! Deadline should be in the same time domain as core::timestamp().
35
ROC_ATTR_NODISCARD
bool
timed_wait
(
nanoseconds_t
deadline);
36
37
//! Wait until the counter becomes non-zero, decrement it, and return.
38
void
wait
();
39
40
//! Increment counter and wake up blocked waits.
41
//! This method is lock-free.
42
void
post
();
43
44
private
:
45
semaphore_t sem_id_;
46
};
47
48
}
// namespace core
49
}
// namespace roc
50
51
#endif
// ROC_CORE_SEMAPHORE_H_
attributes.h
Compiler attributes.
ROC_ATTR_NODISCARD
#define ROC_ATTR_NODISCARD
Emit warning if function result is not checked.
Definition
attributes.h:31
roc::core::Semaphore::Semaphore
Semaphore(unsigned counter=0)
Initialize semaphore with given counter.
roc::core::Semaphore::timed_wait
ROC_ATTR_NODISCARD bool timed_wait(nanoseconds_t deadline)
Wait until the counter becomes non-zero, decrement it, and return true. If deadline expires before th...
roc::core::Semaphore::wait
void wait()
Wait until the counter becomes non-zero, decrement it, and return.
roc::core::Semaphore::post
void post()
Increment counter and wake up blocked waits. This method is lock-free.
roc::core
General-purpose building blocks and platform abstraction layer.
roc::core::nanoseconds_t
int64_t nanoseconds_t
Nanoseconds.
Definition
time.h:58
roc
Root namespace.
noncopyable.h
Non-copyable object.
time.h
Time definitions.
roc_core
target_darwin
roc_core
semaphore.h
Generated by
1.17.0