1 // TaskManager.h 2 3 #ifndef NET_FS_TASK_MANAGER_H 4 #define NET_FS_TASK_MANAGER_H 5 6 #include <OS.h> 7 8 #include <HashString.h> 9 #include <util/DoublyLinkedList.h> 10 11 // Task 12 class Task : public DoublyLinkedListLinkImpl<Task> { 13 public: 14 Task(const char* name); 15 virtual ~Task(); 16 17 status_t Run(); 18 void Terminate(); 19 20 bool IsDone() const; 21 22 virtual status_t Execute() = 0; 23 virtual void Stop(); 24 25 protected: 26 void SetDone(bool done); 27 28 private: 29 static int32 _ThreadEntry(void* data); 30 int32 _Thread(); 31 32 private: 33 HashString fName; 34 thread_id fThread; 35 bool fTerminating; 36 bool fDone; 37 }; 38 39 // TaskManager 40 class TaskManager { 41 public: 42 TaskManager(); 43 ~TaskManager(); 44 45 status_t RunTask(Task* task); 46 void RemoveDoneTasks(); 47 void TerminateAllTasks(); 48 49 private: 50 DoublyLinkedList<Task> fTasks; 51 }; 52 53 #endif // NET_FS_TASK_MANAGER_H 54