Roc Toolkit internal modules
Roc Toolkit: real-time audio streaming
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
18#include "roc_core/time.h"
19
20namespace roc {
21namespace core {
22
23//! Semaphore.
24class Semaphore : public NonCopyable<> {
25public:
26 //! Initialize semaphore with given counter.
27 explicit Semaphore(unsigned counter = 0);
28
29 ~Semaphore();
30
31 //! Wait until the counter becomes non-zero, decrement it, and return true.
32 //! If deadline expires before the counter becomes non-zero, returns false.
33 //! Deadline should be in the same time domain as core::timestamp().
34 bool timed_wait(nanoseconds_t deadline);
35
36 //! Wait until the counter becomes non-zero, decrement it, and return.
37 void wait();
38
39 //! Increment counter and wake up blocked waits.
40 //! This method is lock-free.
41 void post();
42
43private:
44 semaphore_t sem_id_;
45};
46
47} // namespace core
48} // namespace roc
49
50#endif // ROC_CORE_SEMAPHORE_H_
Base class for non-copyable objects.
Definition noncopyable.h:23
Semaphore(unsigned counter=0)
Initialize semaphore with given counter.
bool timed_wait(nanoseconds_t deadline)
Wait until the counter becomes non-zero, decrement it, and return true. If deadline expires before th...
void wait()
Wait until the counter becomes non-zero, decrement it, and return.
void post()
Increment counter and wake up blocked waits. This method is lock-free.
int64_t nanoseconds_t
Nanoseconds.
Definition time.h:58
Root namespace.
Non-copyable object.
Time definitions.