libosmscout
1.1.1
Toggle main menu visibility
Loading...
Searching...
No Matches
libosmscout
include
osmscout
async
Worker.h
Go to the documentation of this file.
1
#ifndef OSMSCOUT_UTIL_WORKER_H
2
#define OSMSCOUT_UTIL_WORKER_H
3
4
/*
5
This source is part of the libosmscout library
6
Copyright (C) 2020 Tim Teulings
7
8
This library is free software; you can redistribute it and/or
9
modify it under the terms of the GNU Lesser General Public
10
License as published by the Free Software Foundation; either
11
version 2.1 of the License, or (at your option) any later version.
12
13
This library is distributed in the hope that it will be useful,
14
but WITHOUT ANY WARRANTY; without even the implied warranty of
15
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16
Lesser General Public License for more details.
17
18
You should have received a copy of the GNU Lesser General Public
19
License along with this library; if not, write to the Free Software
20
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21
*/
22
23
#include <thread>
24
#include <optional>
25
26
#include <
osmscout/async/ProcessingQueue.h
>
27
28
#include <
osmscout/lib/CoreImportExport.h
>
29
30
namespace
osmscout
{
31
43
class
OSMSCOUT_API
ThreadedWorker
44
{
45
private
:
46
std::thread thread;
47
bool
success=
true
;
48
49
protected
:
62
void
MarkWorkerAsFailed
() {
63
success=
false
;
64
}
65
66
public
:
67
ThreadedWorker
() =
default
;
68
69
ThreadedWorker
(
const
ThreadedWorker
& other) =
delete
;
70
ThreadedWorker
(
ThreadedWorker
&& other) =
delete
;
71
72
virtual
~ThreadedWorker
() =
default
;
73
83
bool
WasSuccessful
()
const
84
{
85
return
success;
86
}
87
88
void
Wait
() {
89
if
(thread.joinable()) {
90
thread.join();
91
}
92
}
93
94
protected
:
95
void
Start
()
96
{
97
thread = std::thread(&
ThreadedWorker::ProcessingLoop
,
this
);
98
}
99
100
virtual
void
ProcessingLoop
() = 0;
101
};
102
112
template
<
typename
E>
113
class
Producer
:
public
ThreadedWorker
114
{
115
protected
:
116
ProcessingQueue<E>
&
outQueue
;
117
118
public
:
119
explicit
Producer
(
ProcessingQueue<E>
&
outQueue
)
120
:
outQueue
(
outQueue
)
121
{
122
}
123
};
124
134
template
<
typename
E1,
typename
E2>
135
class
Pipe
:
public
ThreadedWorker
136
{
137
protected
:
138
ProcessingQueue<E1>
&
inQueue
;
139
ProcessingQueue<E2>
&
outQueue
;
140
141
public
:
142
Pipe
(
ProcessingQueue<E1>
&
inQueue
,
143
ProcessingQueue<E2>
&
outQueue
)
144
:
inQueue
(
inQueue
),
145
outQueue
(
outQueue
)
146
{
147
}
148
};
149
158
template
<
typename
E>
159
class
Consumer
:
public
ThreadedWorker
160
{
161
protected
:
162
ProcessingQueue<E>
&
inQueue
;
163
164
public
:
165
explicit
Consumer
(
ProcessingQueue<E>
&
inQueue
)
166
:
inQueue
(
inQueue
)
167
{
168
}
169
};
170
171
}
172
173
#endif
CoreImportExport.h
OSMSCOUT_API
#define OSMSCOUT_API
Definition
CoreImportExport.h:45
ProcessingQueue.h
osmscout::Consumer::inQueue
ProcessingQueue< E > & inQueue
Definition
Worker.h:162
osmscout::Consumer::Consumer
Consumer(ProcessingQueue< E > &inQueue)
Definition
Worker.h:165
osmscout::Pipe::Pipe
Pipe(ProcessingQueue< E1 > &inQueue, ProcessingQueue< E2 > &outQueue)
Definition
Worker.h:142
osmscout::Pipe::inQueue
ProcessingQueue< E1 > & inQueue
Definition
Worker.h:138
osmscout::Pipe::outQueue
ProcessingQueue< E2 > & outQueue
Definition
Worker.h:139
osmscout::ProcessingQueue
Definition
ProcessingQueue.h:56
osmscout::Producer::Producer
Producer(ProcessingQueue< E > &outQueue)
Definition
Worker.h:119
osmscout::Producer::outQueue
ProcessingQueue< E > & outQueue
Definition
Worker.h:116
osmscout::ThreadedWorker::ThreadedWorker
ThreadedWorker(const ThreadedWorker &other)=delete
osmscout::ThreadedWorker::Wait
void Wait()
Definition
Worker.h:88
osmscout::ThreadedWorker::ProcessingLoop
virtual void ProcessingLoop()=0
osmscout::ThreadedWorker::Start
void Start()
Definition
Worker.h:95
osmscout::ThreadedWorker::WasSuccessful
bool WasSuccessful() const
Definition
Worker.h:83
osmscout::ThreadedWorker::ThreadedWorker
ThreadedWorker()=default
osmscout::ThreadedWorker::MarkWorkerAsFailed
void MarkWorkerAsFailed()
Definition
Worker.h:62
osmscout::ThreadedWorker::ThreadedWorker
ThreadedWorker(ThreadedWorker &&other)=delete
osmscout::ThreadedWorker::~ThreadedWorker
virtual ~ThreadedWorker()=default
osmscout
Definition
Area.h:39
Generated by
1.17.0