Lumiera 0.pre.04
»edit your freedom«
Loading...
Searching...
No Matches
call-queue.hpp
Go to the documentation of this file.
1/*
2 CALL-QUEUE.hpp - a queue to dispatch bound function invocations into another thread
3
4 Copyright (C)
5 2017, Hermann Vosseler <Ichthyostega@web.de>
6
7  **Lumiera** is free software; you can redistribute it and/or modify it
8  under the terms of the GNU General Public License as published by the
9  Free Software Foundation; either version 2 of the License, or (at your
10  option) any later version. See the file COPYING for further details.
11
12*/
13
27#ifndef LIB_CALL_QUEUE_H
28#define LIB_CALL_QUEUE_H
29
30
31#include "lib/error.hpp"
32#include "lib/sync.hpp"
33#include "lib/iter-stack.hpp"
34#include "lib/nocopy.hpp"
35
36#include <functional>
37
38
39namespace lib {
40 namespace error = lumiera::error;
41
42
43
44 /*********************************************************/
51 , public Sync<>
52 {
53 public:
54 using Operation = std::function<void(void)>;
55
56 private:
58
59 public:
61
62
65 {
66 if (not op)
67 throw error::Logic( "Unbound Functor fed to dispatcher CallQueue"
68 , error::LUMIERA_ERROR_BOTTOM_VALUE);
69 {
70 Lock sync{this};
71 queue_.feed (move(op));
72 }
73 return *this;
74 }
75
78 {
79 if (not empty())
80 {
81 Operation operate;
82 {
83 Lock sync{this};
84 operate = move (*queue_);
85 ++queue_;
86 }
87 ASSERT (operate);
88 operate();
89 }
90 return *this;
91 }
92
93
94 /* == diagnostics == */
95
96 size_t
97 size() const
98 {
99 Lock sync{this};
100 return queue_.size();
101 }
102
103 bool
104 empty() const
105 {
106 return 0 == size();
107 }
108 };
109
110
111
112} // namespace lib
113#endif /*LIB_CALL_QUEUE_H*/
A threadsafe queue for bound void(void) functors.
CallQueue & feed(Operation &&op)
lib::IterQueue< Operation > queue_
size_t size() const
CallQueue & invoke()
bool empty() const
std::function< void(void)> Operation
scoped guard to control the actual locking.
Definition sync.hpp:228
Facility for monitor object based locking.
Definition sync.hpp:210
Any copy and copy construction prohibited.
Definition nocopy.hpp:38
Lumiera error handling (C++ interface).
Conveniently iterable stack and queue containers.
Implementation namespace for support and library code.
LumieraError< LERR_(LOGIC)> Logic
Definition error.hpp:207
Mix-Ins to allow or prohibit various degrees of copying and cloning.
A Queue which can be pulled by iterating.
size_t size() const
IterQueue & feed(TY const &elm)
Object Monitor based synchronisation.