libosmscout 1.1.1
Loading...
Searching...
No Matches
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
27
29
30namespace osmscout {
31
44 {
45 private:
46 std::thread thread;
47 bool success=true;
48
49 protected:
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>
114 {
115 protected:
117
118 public:
121 {
122 }
123 };
124
134 template <typename E1, typename E2>
149
158 template <typename E>
160 {
161 protected:
163
164 public:
167 {
168 }
169 };
170
171}
172
173#endif
#define OSMSCOUT_API
Definition CoreImportExport.h:45
ProcessingQueue< E > & inQueue
Definition Worker.h:162
Consumer(ProcessingQueue< E > &inQueue)
Definition Worker.h:165
Pipe(ProcessingQueue< E1 > &inQueue, ProcessingQueue< E2 > &outQueue)
Definition Worker.h:142
ProcessingQueue< E1 > & inQueue
Definition Worker.h:138
ProcessingQueue< E2 > & outQueue
Definition Worker.h:139
Definition ProcessingQueue.h:56
Producer(ProcessingQueue< E > &outQueue)
Definition Worker.h:119
ProcessingQueue< E > & outQueue
Definition Worker.h:116
ThreadedWorker(const ThreadedWorker &other)=delete
void Wait()
Definition Worker.h:88
virtual void ProcessingLoop()=0
void Start()
Definition Worker.h:95
bool WasSuccessful() const
Definition Worker.h:83
void MarkWorkerAsFailed()
Definition Worker.h:62
ThreadedWorker(ThreadedWorker &&other)=delete
virtual ~ThreadedWorker()=default
Definition Area.h:39