Open Lighting Architecture  Latest Git
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 
29 namespace ola {
30 namespace thread {
31 
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  DISALLOW_COPY_AND_ASSIGN(ConsumerThread);
71 };
72 } // namespace thread
73 } // namespace ola
74 #endif // INCLUDE_OLA_THREAD_CONSUMERTHREAD_H_
Definition: Thread.h:52
void * Run()
Definition: ConsumerThread.cpp:31
Definition: ConsumerThread.h:36
Thread options.
Definition: Thread.h:60
Helper macros.
The namespace containing all OLA symbols.
Definition: Credentials.cpp:44
ConsumerThread(std::queue< Action > *callback_queue, const bool *shutdown, Mutex *mutex, ConditionVariable *condition_var, const Thread::Options &options=Thread::Options())
Definition: ConsumerThread.h:48
Definition: Mutex.h:41
Definition: Mutex.h:81