Open Lighting Architecture  0.9.2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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;
47  ConsumerThread(std::queue<Action> *callback_queue,
48  const bool *shutdown,
49  Mutex *mutex,
50  ConditionVariable *condition_var)
51  : Thread(),
52  m_callback_queue(callback_queue),
53  m_shutdown(shutdown),
54  m_mutex(mutex),
55  m_condition_var(condition_var) {
56  }
57  ~ConsumerThread() {}
58  void *Run();
59 
60  private:
61  std::queue<Action> *m_callback_queue;
62  const bool *m_shutdown;
63  Mutex *m_mutex;
64  ConditionVariable *m_condition_var;
65 
66  void EmptyQueue();
67 
68  DISALLOW_COPY_AND_ASSIGN(ConsumerThread);
69 };
70 } // namespace thread
71 } // namespace ola
72 #endif // INCLUDE_OLA_THREAD_CONSUMERTHREAD_H_