summaryrefslogtreecommitdiff
path: root/thread.c
diff options
context:
space:
mode:
authorKlaus Schmidinger <vdr@tvdr.de>2007-01-07 14:46:14 +0100
committerKlaus Schmidinger <vdr@tvdr.de>2007-01-07 14:46:14 +0100
commit87dd5139ff6666d64e7e343bcff632b342c4c814 (patch)
treec2b8f2f437a09e1ad2f740adc574f3f1833d8fe3 /thread.c
parentb4cab10eca558f6d90fa25a2a6e7fc3d90fac508 (diff)
downloadvdr-87dd5139ff6666d64e7e343bcff632b342c4c814.tar.gz
vdr-87dd5139ff6666d64e7e343bcff632b342c4c814.tar.bz2
CAM handling refactored; multiple recordings with one CAM; automatic CAM selection1.5.0
Diffstat (limited to 'thread.c')
-rw-r--r--thread.c30
1 files changed, 21 insertions, 9 deletions
diff --git a/thread.c b/thread.c
index 2e145e50..05f1d016 100644
--- a/thread.c
+++ b/thread.c
@@ -4,7 +4,7 @@
* See the main source file 'vdr.c' for copyright information and
* how to reach the author.
*
- * $Id: thread.c 1.58 2006/09/24 12:54:47 kls Exp $
+ * $Id: thread.c 1.59 2007/01/07 14:44:22 kls Exp $
*/
#include "thread.h"
@@ -249,17 +249,29 @@ void *cThread::StartThread(cThread *Thread)
return NULL;
}
+#define THREAD_STOP_TIMEOUT 3000 // ms to wait for a thread to stop before newly starting it
+#define THREAD_STOP_SLEEP 30 // ms to sleep while waiting for a thread to stop
+
bool cThread::Start(void)
{
- if (!active) {
- active = running = true;
- if (pthread_create(&childTid, NULL, (void *(*) (void *))&StartThread, (void *)this) == 0) {
- pthread_detach(childTid); // auto-reap
+ if (!running) {
+ if (active) {
+ // Wait until the previous incarnation of this thread has completely ended
+ // before starting it newly:
+ cTimeMs RestartTimeout;
+ while (!running && active && RestartTimeout.Elapsed() < THREAD_STOP_TIMEOUT)
+ cCondWait::SleepMs(THREAD_STOP_SLEEP);
}
- else {
- LOG_ERROR;
- active = running = false;
- return false;
+ if (!active) {
+ active = running = true;
+ if (pthread_create(&childTid, NULL, (void *(*) (void *))&StartThread, (void *)this) == 0) {
+ pthread_detach(childTid); // auto-reap
+ }
+ else {
+ LOG_ERROR;
+ active = running = false;
+ return false;
+ }
}
}
return true;