Open Lighting Architecture
 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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/thread/Thread.h>
26 #include <queue>
27 
28 namespace ola {
29 namespace thread {
30 
31 using std::queue;
32 
38  public :
39  typedef BaseCallback0<void>* Action;
48  ConsumerThread(queue<Action> *callback_queue,
49  const bool *shutdown,
50  Mutex *mutex,
51  ConditionVariable *condition_var)
52  : Thread(),
53  m_callback_queue(callback_queue),
54  m_shutdown(shutdown),
55  m_mutex(mutex),
56  m_condition_var(condition_var) {
57  }
58  ~ConsumerThread() {}
59  void *Run();
60 
61  private:
62  queue<Action> *m_callback_queue;
63  const bool *m_shutdown;
64  Mutex *m_mutex;
65  ConditionVariable *m_condition_var;
66 
67  void EmptyQueue();
68 };
69 } // namespace thread
70 } // namespace ola
71 #endif // INCLUDE_OLA_THREAD_CONSUMERTHREAD_H_