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

| Open Lighting Architecture 0.10.9

Loading...
Searching...
No Matches
ConsumerThread.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 * ConsumerThread.h
17 * An thread which consumes Callbacks from a queue and runs them.
18 * Copyright (C) 2011 Simon Newton
19 */
20
21#ifndef INCLUDE_OLA_THREAD_CONSUMERTHREAD_H_
22#define INCLUDE_OLA_THREAD_CONSUMERTHREAD_H_
23
24#include <ola/Callback.h>
25#include <ola/base/Macro.h>
26#include <ola/thread/Thread.h>
27#include <queue>
28
29namespace ola {
30namespace thread {
31
36 class ConsumerThread: public ola::thread::Thread {
37 public :
38 typedef BaseCallback0<void>* Action;
48 ConsumerThread(std::queue<Action> *callback_queue,
49 const bool *shutdown,
50 Mutex *mutex,
51 ConditionVariable *condition_var,
52 const Thread::Options& options = Thread::Options())
53 : Thread(options),
54 m_callback_queue(callback_queue),
55 m_shutdown(shutdown),
56 m_mutex(mutex),
57 m_condition_var(condition_var) {
58 }
59 ~ConsumerThread() {}
60 void *Run();
61
62 private:
63 std::queue<Action> *m_callback_queue;
64 const bool *m_shutdown;
65 Mutex *m_mutex;
66 ConditionVariable *m_condition_var;
67
68 void EmptyQueue();
69
70 ConsumerThread(const ConsumerThread &) = delete;
71 const ConsumerThread &operator=(const ConsumerThread &) = delete;
72};
73} // namespace thread
74} // namespace ola
75#endif // INCLUDE_OLA_THREAD_CONSUMERTHREAD_H_
Callback.h
Macro.h
Helper macros.
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::ConsumerThread::Run
void * Run()
Definition ConsumerThread.cpp:31
ola::thread::ConsumerThread::ConsumerThread
ConsumerThread(std::queue< Action > *callback_queue, const bool *shutdown, Mutex *mutex, ConditionVariable *condition_var, const Thread::Options &options=Thread::Options())
Definition ConsumerThread.h:48
ola::thread::Mutex
Definition Mutex.h:41
ola::thread::Thread
Definition Thread.h:52
ola::thread::Thread::Thread
Thread(const Options &options=Options())
Create a new thread with the specified thread options.
Definition Thread.cpp:75
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