Roc Toolkit internal modules
Roc Toolkit: real-time audio streaming
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
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/attributes.h"
20#include "roc_core/mutex.h"
22#include "roc_core/time.h"
23
24namespace roc {
25namespace core {
26
27//! Condition variable.
28class Cond : public NonCopyable<> {
29public:
30 //! Initialize.
31 Cond(const Mutex& mutex);
32
33 //! Destroy.
35
36 //! Wait with timeout.
37 //! @returns false if timeout expired.
39
40 //! Wait.
41 void wait() const;
42
43 //! Wake up one pending waits.
44 void signal() const;
45
46 //! Wake up all pending waits.
47 void broadcast() const;
48
49private:
50 mutable pthread_cond_t cond_;
51 mutable Atomic<int> guard_;
52
53 pthread_mutex_t& mutex_;
54};
55
56} // namespace core
57} // namespace roc
58
59#endif // ROC_CORE_COND_H_
Atomic.
Compiler attributes.
#define ROC_ATTR_NODISCARD
Emit warning if function result is not checked.
Definition attributes.h:31
Condition variable.
Definition cond.h:28
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.
Base class for non-copyable objects.
Definition noncopyable.h:23
Shared ownership intrusive pointer.
Definition shared_ptr.h:32
Mutex.
int64_t nanoseconds_t
Nanoseconds.
Definition time.h:58
Root namespace.
Non-copyable object.
Time definitions.