Roc Toolkit internal modules
Roc Toolkit: real-time audio streaming
Toggle main menu visibility
Loading...
Searching...
No Matches
thread.h
Go to the documentation of this file.
1
/*
2
* Copyright (c) 2015 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/thread.h
10
//! @brief Thread.
11
12
#ifndef ROC_CORE_THREAD_H_
13
#define ROC_CORE_THREAD_H_
14
15
#include <pthread.h>
16
17
#include "
roc_core/atomic.h
"
18
#include "
roc_core/attributes.h
"
19
#include "
roc_core/mutex.h
"
20
#include "
roc_core/noncopyable.h
"
21
#include "
roc_core/stddefs.h
"
22
23
namespace
roc
{
24
namespace
core
{
25
26
//! Base class for thread objects.
27
class
Thread :
public
NonCopyable<Thread> {
28
public
:
29
//! Get numeric identifier of current process.
30
static
uint64_t
get_pid
();
31
32
//! Get numeric identifier of current thread.
33
static
uint64_t
get_tid
();
34
35
//! Raise current thread priority to realtime.
36
ROC_ATTR_NODISCARD
static
bool
enable_realtime
();
37
38
//! Check if thread was started and can be joined.
39
//! @returns
40
//! true if start() was called and join() was not called yet.
41
bool
is_joinable
()
const
;
42
43
//! Start thread.
44
//! @remarks
45
//! Executes run() in new thread.
46
ROC_ATTR_NODISCARD
bool
start
();
47
48
//! Join thread.
49
//! @remarks
50
//! Blocks until run() returns and thread terminates.
51
void
join
();
52
53
protected
:
54
virtual
~Thread();
55
56
Thread();
57
58
//! Method to be executed in thread.
59
virtual
void
run
() = 0;
60
61
private
:
62
static
void
* thread_runner_(
void
* ptr);
63
64
pthread_t thread_;
65
66
int
started_;
67
Atomic<int>
joinable_;
68
69
Mutex
mutex_;
70
};
71
72
}
// namespace core
73
}
// namespace roc
74
75
#endif
// ROC_CORE_THREAD_H_
atomic.h
Atomic.
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::Atomic
Atomic integer. Provides sequential consistency. For a fine-grained memory order control,...
Definition
atomic.h:26
roc::core::Mutex
Mutex.
Definition
mutex.h:31
roc::core::Thread::enable_realtime
static ROC_ATTR_NODISCARD bool enable_realtime()
Raise current thread priority to realtime.
roc::core::Thread::start
ROC_ATTR_NODISCARD bool start()
Start thread.
roc::core::Thread::join
void join()
Join thread.
roc::core::Thread::is_joinable
bool is_joinable() const
Check if thread was started and can be joined.
roc::core::Thread::run
virtual void run()=0
Method to be executed in thread.
roc::core::Thread::get_tid
static uint64_t get_tid()
Get numeric identifier of current thread.
roc::core::Thread::get_pid
static uint64_t get_pid()
Get numeric identifier of current process.
mutex.h
Mutex.
roc::core
General-purpose building blocks and platform abstraction layer.
roc
Root namespace.
noncopyable.h
Non-copyable object.
stddefs.h
Commonly used types and functions.
roc_core
target_posix
roc_core
thread.h
Generated by
1.17.0