diff options
author | Ho-Eun Ryu <ho-eun.ryu@windriver.com> | 2009-09-25 14:26:49 +0900 |
---|---|---|
committer | Patrick Tjin <pattjin@google.com> | 2014-07-21 22:03:24 -0700 |
commit | 9eb5f262eb3e810d633fb4ebfb1e06940cadc778 (patch) | |
tree | a311aae98dce13c77ffdb2a796da3f0d71208638 /utils | |
parent | f512d67ca4d720eaedbde875aa58cb9e9cae7a76 (diff) | |
download | wrs_omxil_core-9eb5f262eb3e810d633fb4ebfb1e06940cadc778.tar.gz |
utils:workqueue: introduce Start/StopWork()
WorkQueu doesn't start work thread implicitly. you should call
Start/StopWork() where you want at
Diffstat (limited to 'utils')
-rw-r--r-- | utils/inc/workqueue.h | 4 | ||||
-rw-r--r-- | utils/src/workqueue.cpp | 26 |
2 files changed, 18 insertions, 12 deletions
diff --git a/utils/inc/workqueue.h b/utils/inc/workqueue.h index 884f711..5f4b18c 100644 --- a/utils/inc/workqueue.h +++ b/utils/inc/workqueue.h @@ -24,6 +24,10 @@ public: */ ~WorkQueue(); + /* start & stop work thread */ + int StartWork(void); + void StopWork(void); + /* the class inheriting WorkQueue uses this method */ void ScheduleWork(void); /* the class implementing WorkableInterface uses this method */ diff --git a/utils/src/workqueue.cpp b/utils/src/workqueue.cpp index 25ac65e..ca101e0 100644 --- a/utils/src/workqueue.cpp +++ b/utils/src/workqueue.cpp @@ -7,29 +7,31 @@ WorkQueue::WorkQueue() pthread_mutex_init(&wlock, NULL); pthread_cond_init(&wcond, NULL); - - Start(); } WorkQueue::~WorkQueue() { - struct list *entry, *temp; + StopWork(); - stop = true; + pthread_cond_destroy(&wcond); + pthread_mutex_destroy(&wlock); +} + +int WorkQueue::StartWork(void) +{ + return Start(); +} + +void WorkQueue::StopWork(void) +{ + FlushWork(); pthread_mutex_lock(&wlock); - /* race condition against Run() */ - /* - list_foreach_safe(works.next, entry, temp) - __list_delete(works.next, entry); - */ + stop = true; pthread_cond_signal(&wcond); /* wakeup Run() if it's sleeping */ pthread_mutex_unlock(&wlock); Join(); - - pthread_cond_destroy(&wcond); - pthread_mutex_destroy(&wlock); } void WorkQueue::Run(void) |