Roc Toolkit internal modules
Roc Toolkit: real-time audio streaming
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
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"
19#include "roc_core/time.h"
20
21namespace roc {
22namespace core {
23
24//! Semaphore.
25class Semaphore : public NonCopyable<> {
26public:
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().
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
44private:
45 semaphore_t sem_id_;
46};
47
48} // namespace core
49} // namespace roc
50
51#endif // ROC_CORE_SEMAPHORE_H_
Compiler attributes.
#define ROC_ATTR_NODISCARD
Emit warning if function result is not checked.
Definition attributes.h:31
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.
Shared ownership intrusive pointer.
Definition shared_ptr.h:32
int64_t nanoseconds_t
Nanoseconds.
Definition time.h:58
Root namespace.
Non-copyable object.
Time definitions.