Roc Toolkit internal modules
Roc Toolkit: real-time audio streaming
Loading...
Searching...
No Matches
cond.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2017 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_posix/roc_core/cond.h
10//! @brief Condition variable.
11
12#ifndef ROC_CORE_COND_H_
13#define ROC_CORE_COND_H_
14
15#include <errno.h>
16#include <pthread.h>
17
18#include "roc_core/atomic.h"
19#include "roc_core/mutex.h"
21#include "roc_core/time.h"
22
23namespace roc {
24namespace core {
25
26//! Condition variable.
27class Cond : public NonCopyable<> {
28public:
29 //! Initialize.
30 Cond(const Mutex& mutex);
31
32 //! Destroy.
34
35 //! Wait with timeout.
36 //! @returns false if timeout expired.
37 bool timed_wait(nanoseconds_t timeout) const;
38
39 //! Wait.
40 void wait() const;
41
42 //! Wake up one pending waits.
43 void signal() const;
44
45 //! Wake up all pending waits.
46 void broadcast() const;
47
48private:
49 mutable pthread_cond_t cond_;
50 mutable Atomic<int> guard_;
51
52 pthread_mutex_t& mutex_;
53};
54
55} // namespace core
56} // namespace roc
57
58#endif // ROC_CORE_COND_H_
Atomic.
Atomic integer. Provides sequential consistency. For a fine-grained memory order control,...
Definition: atomic.h:26
Condition variable.
Definition: cond.h:27
void signal() const
Wake up one pending waits.
bool timed_wait(nanoseconds_t timeout) const
Wait with timeout.
Cond(const Mutex &mutex)
Initialize.
~Cond()
Destroy.
void wait() const
Wait.
void broadcast() const
Wake up all pending waits.
Mutex.
Definition: mutex.h:30
Base class for non-copyable objects.
Definition: noncopyable.h:23
Mutex.
int64_t nanoseconds_t
Nanoseconds.
Definition: time.h:58
Root namespace.
Non-copyable object.
Time definitions.