OpenCPN Partial API docs
Toggle main menu visibility
Main Page
Related Pages
Namespaces
Namespace List
Namespace Members
All
Functions
Classes
Class List
Class Index
Class Hierarchy
Class Members
All
_
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
r
s
t
u
v
w
x
y
z
~
Functions
a
b
c
d
e
f
g
h
i
k
l
m
n
o
p
r
s
t
u
v
w
z
~
Variables
_
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
r
s
t
u
v
w
x
y
z
Related Symbols
Files
File List
File Members
All
_
a
c
d
e
f
g
i
j
l
m
n
o
p
r
s
t
u
w
x
z
Functions
a
c
d
e
f
g
i
j
m
o
p
r
s
t
u
w
z
Variables
Typedefs
Enumerations
Enumerator
a
c
d
e
i
l
n
o
p
r
s
w
x
Macros
a
i
m
p
s
u
w
Examples
•
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Pages
Loading...
Searching...
No Matches
wait_continue.h
Go to the documentation of this file.
1
/***************************************************************************
2
* Copyright (C) 2024 Alec Leamas *
3
* *
4
* This program is free software; you can redistribute it and/or modify *
5
* it under the terms of the GNU General Public License as published by *
6
* the Free Software Foundation; either version 2 of the License, or *
7
* (at your option) any later version. *
8
* *
9
* This program is distributed in the hope that it will be useful, *
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12
* GNU General Public License for more details. *
13
* *
14
* You should have received a copy of the GNU General Public License *
15
* along with this program; if not, write to the *
16
* Free Software Foundation, Inc., *
17
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
18
**************************************************************************/
19
25
#ifndef WAIT_COND__
26
#define WAIT_COND__
27
28
#include <cassert>
29
#include <chrono>
30
#include <condition_variable>
31
#include <mutex>
32
#include <thread>
33
34
using namespace
std::chrono_literals;
35
36
class
WaitContinue
{
37
public
:
39
WaitContinue
() : is_waiting(false) {}
40
41
WaitContinue
& operator=(
const
WaitContinue
) =
delete
;
42
WaitContinue
(
const
WaitContinue
&) =
delete
;
43
45
void
Continue
() {
46
{
47
std::unique_lock lock(m_mutex);
48
is_waiting =
false
;
49
}
50
cv.notify_all();
51
}
45
void
Continue
() {
…
}
52
54
bool
Wait
(std::chrono::milliseconds timeout = 0s) {
55
std::unique_lock lock(m_mutex);
56
is_waiting =
true
;
57
auto
t = std::chrono::high_resolution_clock::now() + timeout;
58
auto
result = cv.wait_until(lock, t, [&] {
return
!is_waiting; });
59
return
true
;
60
}
54
bool
Wait
(std::chrono::milliseconds timeout = 0s) {
…
}
61
63
void
Wait
(
unsigned
timeout_ms) {
64
Wait
(std::chrono::milliseconds(timeout_ms));
65
}
63
void
Wait
(
unsigned
timeout_ms) {
…
}
66
67
private
:
68
bool
is_waiting;
69
std::mutex m_mutex;
70
std::condition_variable cv;
71
};
36
class
WaitContinue
{
…
};
72
73
#endif
// WAIT_COND__
WaitContinue
Definition
wait_continue.h:36
WaitContinue::WaitContinue
WaitContinue()
Default constructor, neither copyable nor assignable.
Definition
wait_continue.h:39
WaitContinue::Continue
void Continue()
Release any threads blocked by Wait().
Definition
wait_continue.h:45
WaitContinue::Wait
void Wait(unsigned timeout_ms)
Blocking wait for next Continue() or timeout (milliseconds)
Definition
wait_continue.h:63
WaitContinue::Wait
bool Wait(std::chrono::milliseconds timeout=0s)
Blocking wait for next Continue() with optional timeout.
Definition
wait_continue.h:54
model
include
model
wait_continue.h
Generated on Mon Apr 7 2025 02:40:20 for OpenCPN Partial API docs by
1.9.8