ffead.server.doc
TaskPool.h
1 /*
2  Copyright 2009-2012, Sumeet Chhetri
3 
4  Licensed under the Apache License, Version 2.0 (the "License");
5  you may not use this file except in compliance with the License.
6  You may obtain a copy of the License at
7 
8  http://www.apache.org/licenses/LICENSE-2.0
9 
10  Unless required by applicable law or agreed to in writing, software
11  distributed under the License is distributed on an "AS IS" BASIS,
12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  See the License for the specific language governing permissions and
14  limitations under the License.
15 */
16 /*
17  * TaskPool.h
18  *
19  * Created on: Mar 23, 2010
20  * Author: sumeet
21  */
22 
23 #ifndef TASKPOOL_H_
24 #define TASKPOOL_H_
25 #include "vector"
26 #include "queue"
27 #include "list"
28 #include "Task.h"
29 #include "Mutex.h"
30 #include "Thread.h"
31 #include "TimeUnit.h"
32 #include "Timer.h"
33 
34 class TaskPool {
35  std::queue<Task*> *tasks;
36  list<Task*> *ptasks;
37  vector<Task*> *scheduledtasks;
38  vector<Timer*> *scheduledTimers;
39  Mutex *m_mutex;
40  bool console;
41  Thread *mthread;
42  static void* run(void *arg);
43  friend class ThreadPool;
44  bool runFlag, complete, thrdStarted;
45 public:
46  TaskPool();
47  void start();
48  void addTask(Task &task);
49  void addTask(Task *task);
50  void addPTask(Task &task);
51  void addPTask(Task *task);
52  Task* getTask();
53  Task* getPTask();
54  bool tasksPending();
55  bool tasksPPending();
56  ~TaskPool();
57 };
58 
59 #endif /* TASKPOOL_H_ */