mirror of
https://github.com/vdr-projects/vdr.git
synced 2025-03-01 10:50:46 +00:00
CAM handling refactored; multiple recordings with one CAM; automatic CAM selection
This commit is contained in:
30
thread.c
30
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;
|
||||
|
Reference in New Issue
Block a user