libosmscout
1.1.1
Loading...
Searching...
No Matches
libosmscout
include
osmscout
async
WorkQueue.h
Go to the documentation of this file.
1
#ifndef OSMSCOUT_UTIL_WORKQUEUE_H
2
#define OSMSCOUT_UTIL_WORKQUEUE_H
3
4
/*
5
This source is part of the libosmscout library
6
Copyright (C) 2015 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 <condition_variable>
24
#include <deque>
25
#include <future>
26
#include <memory>
27
#include <limits>
28
#include <thread>
29
30
#include <
osmscout/lib/CoreImportExport.h
>
31
#include <
osmscout/async/ProcessingQueue.h
>
32
33
namespace
osmscout
{
34
35
template
<
typename
R>
36
class
WorkQueue
:
public
ProcessingQueue
<std::packaged_task<R ()>>
37
{
38
private
:
39
using
Task = std::packaged_task<R ()>;
40
41
public
:
42
WorkQueue
() =
default
;
43
44
explicit
WorkQueue
(
size_t
queueLimit);
45
~WorkQueue
()
override
=
default
;
46
47
bool
PopTask
(Task& task);
48
};
49
50
51
template
<
class
R>
52
WorkQueue<R>::WorkQueue
(
size_t
queueLimit)
53
:
ProcessingQueue
<Task>(queueLimit)
54
{
55
// no code
56
}
57
58
template
<
class
R>
59
bool
WorkQueue<R>::PopTask
(Task& task)
60
{
61
auto
taskOpt =
ProcessingQueue<Task>::PopTask
();
62
63
if
(!taskOpt) {
64
return
false
;
65
}
66
67
task=std::move(taskOpt.value());
68
69
return
true
;
70
}
71
}
72
73
#endif
CoreImportExport.h
ProcessingQueue.h
osmscout::ProcessingQueue< std::packaged_task< R()> >::ProcessingQueue
ProcessingQueue()
osmscout::ProcessingQueue< std::packaged_task< R()> >::PopTask
std::optional< std::packaged_task< R()> > PopTask()
Definition
ProcessingQueue.h:154
osmscout::WorkQueue::PopTask
bool PopTask(Task &task)
Definition
WorkQueue.h:59
osmscout::WorkQueue::~WorkQueue
~WorkQueue() override=default
osmscout::WorkQueue::WorkQueue
WorkQueue()=default
osmscout
Definition
Area.h:39
Generated by
1.16.1