Roc Toolkit internal modules
Roc Toolkit: real-time audio streaming
Toggle main menu visibility
Loading...
Searching...
No Matches
seqlock_impl.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/seqlock_impl.h
10
//! @brief Seqlock implementation.
11
12
#ifndef ROC_CORE_SEQLOCK_IMPL_H_
13
#define ROC_CORE_SEQLOCK_IMPL_H_
14
15
#include "
roc_core/stddefs.h
"
16
17
namespace
roc
{
18
namespace
core
{
19
20
//! Type for holding seqlock value version.
21
//! Version is changed each value update.
22
//! May wrap.
23
typedef
uint32_t
seqlock_version_t
;
24
25
//! Check if this is a valid seqlock version.
26
//! Returns false if seqlock version corresponds to intermediate state
27
//! that should never be seen by seqlock user.
28
inline
bool
seqlock_version_is_valid
(
seqlock_version_t
ver) {
29
return
(ver & 1) == 0;
30
}
31
32
//! Seqlock implementation class.
33
//! @see Seqlock.
34
class
SeqlockImpl
{
35
public
:
36
//! Initialize.
37
SeqlockImpl
();
38
39
//! Load value version.
40
seqlock_version_t
version
()
const
;
41
42
//! Try to store value.
43
bool
try_store
(
seqlock_version_t
& ver,
44
void
* current_value,
45
size_t
value_size,
46
const
void
* new_value);
47
48
//! Store value.
49
void
exclusive_store
(
seqlock_version_t
& ver,
50
void
* current_value,
51
size_t
value_size,
52
const
void
* new_value);
53
54
//! Try to load value and version.
55
bool
try_load_repeat
(
seqlock_version_t
& ver,
56
const
void
* current_value,
57
size_t
value_size,
58
void
* return_value)
const
;
59
60
//! Load value and version.
61
void
wait_load
(
seqlock_version_t
& ver,
62
const
void
* current_value,
63
size_t
value_size,
64
void
* return_value)
const
;
65
66
private
:
67
bool
try_load_(
seqlock_version_t
& ver,
68
const
void
* current_value,
69
size_t
value_size,
70
void
* return_value)
const
;
71
72
seqlock_version_t
ver_;
73
};
74
75
}
// namespace core
76
}
// namespace roc
77
78
#endif
// ROC_CORE_SEQLOCK_IMPL_H_
roc::core::SeqlockImpl::SeqlockImpl
SeqlockImpl()
Initialize.
roc::core::SeqlockImpl::try_store
bool try_store(seqlock_version_t &ver, void *current_value, size_t value_size, const void *new_value)
Try to store value.
roc::core::SeqlockImpl::exclusive_store
void exclusive_store(seqlock_version_t &ver, void *current_value, size_t value_size, const void *new_value)
Store value.
roc::core::SeqlockImpl::try_load_repeat
bool try_load_repeat(seqlock_version_t &ver, const void *current_value, size_t value_size, void *return_value) const
Try to load value and version.
roc::core::SeqlockImpl::wait_load
void wait_load(seqlock_version_t &ver, const void *current_value, size_t value_size, void *return_value) const
Load value and version.
roc::core::SeqlockImpl::version
seqlock_version_t version() const
Load value version.
roc::core
General-purpose building blocks and platform abstraction layer.
roc::core::seqlock_version_is_valid
bool seqlock_version_is_valid(seqlock_version_t ver)
Check if this is a valid seqlock version. Returns false if seqlock version corresponds to intermediat...
Definition
seqlock_impl.h:28
roc::core::seqlock_version_t
uint32_t seqlock_version_t
Type for holding seqlock value version. Version is changed each value update. May wrap.
Definition
seqlock_impl.h:23
roc
Root namespace.
stddefs.h
Commonly used types and functions.
roc_core
seqlock_impl.h
Generated by
1.17.0