Open Lighting Architecture: include/ola/thread/ExecutorThread.h Source File

| Open Lighting Architecture 0.10.9

Loading...
Searching...
No Matches
ExecutorThread.h
1/*
2 * This library is free software; you can redistribute it and/or
3 * modify it under the terms of the GNU Lesser General Public
4 * License as published by the Free Software Foundation; either
5 * version 2.1 of the License, or (at your option) any later version.
6 *
7 * This library is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10 * Lesser General Public License for more details.
11 *
12 * You should have received a copy of the GNU Lesser General Public
13 * License along with this library; if not, write to the Free Software
14 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
15 *
16 * ExecutorThread.h
17 * Run callbacks in a separate thread.
18 * Copyright (C) 2015 Simon Newton
19 */
20
21#ifndef INCLUDE_OLA_THREAD_EXECUTORTHREAD_H_
22#define INCLUDE_OLA_THREAD_EXECUTORTHREAD_H_
23
24#include <ola/Callback.h>
25#include <ola/io/SelectServer.h>
26#include <ola/thread/Thread.h>
27#include <ola/thread/ConsumerThread.h>
28
29#include <memory>
30#include <queue>
31
32namespace ola {
33namespace thread {
34
54 class ExecutorThread : public ola::thread::ExecutorInterface {
55 public:
60 explicit ExecutorThread(const ola::thread::Thread::Options& options)
61 : m_shutdown(false),
62 m_thread(&m_callback_queue, &m_shutdown, &m_mutex, &m_condition_var,
63 options) {
64 }
65
66 ~ExecutorThread();
67
68 void Execute(ola::BaseCallback0<void> *callback);
69
76 void DrainCallbacks();
77
85 bool Start();
86
97 bool Stop();
98
99 private:
100 // CallbackThread m_thread;
101 std::queue<ola::BaseCallback0<void>*> m_callback_queue;
102 bool m_shutdown;
103 Mutex m_mutex;
104 ConditionVariable m_condition_var;
105 ConsumerThread m_thread;
106
107 void RunRemaining();
108
109 ExecutorThread(const ExecutorThread &) = delete;
110 const ExecutorThread &operator=(const ExecutorThread &) = delete;
111};
112
113} // namespace thread
114} // namespace ola
115#endif // INCLUDE_OLA_THREAD_EXECUTORTHREAD_H_
Callback.h
ola::BaseCallback0
The base class for all 0 argument callbacks.
Definition Callback.h:119
ola::thread::ConditionVariable
Definition Mutex.h:83
ola::thread::ConsumerThread
Definition ConsumerThread.h:36
ola::thread::ExecutorInterface
Defer execution of a callback.
Definition ExecutorInterface.h:35
ola::thread::ExecutorThread
Enables callbacks to be executed in a separate thread.
Definition ExecutorThread.h:54
ola::thread::ExecutorThread::ExecutorThread
ExecutorThread(const ola::thread::Thread::Options &options)
Create a new ExecutorThread.
Definition ExecutorThread.h:60
ola::thread::ExecutorThread::DrainCallbacks
void DrainCallbacks()
Block until all pending callbacks have been processed.
Definition ExecutorThread.cpp:54
ola::thread::ExecutorThread::Start
bool Start()
Start the ExecutorThread.
Definition ExecutorThread.cpp:60
ola::thread::ExecutorThread::Stop
bool Stop()
Stop this Executor thread.
Definition ExecutorThread.cpp:64
ola::thread::ExecutorThread::Execute
void Execute(ola::BaseCallback0< void > *callback)
Execute the supplied callback at some point in the future.
Definition ExecutorThread.cpp:46
ola::thread::Mutex
Definition Mutex.h:41
ola::thread
Threads and synchronization mechanisms.
Definition ConsumerThread.cpp:25
ola
The namespace containing all OLA symbols.
Definition Credentials.cpp:44
ola::thread::Thread::Options
Thread options.
Definition Thread.h:60