summaryrefslogtreecommitdiff
path: root/thread.c
diff options
context:
space:
mode:
authorKlaus Schmidinger <vdr@tvdr.de>2000-12-08 16:23:32 +0100
committerKlaus Schmidinger <vdr@tvdr.de>2000-12-08 16:23:32 +0100
commit6b0658a9775aba758b4f6e2e7ef854126ef1e597 (patch)
tree6117bc6c1c770c91214404eb7f9ebdac71f4ce9d /thread.c
parentc8a1be81af458ba096239461d69245c914070516 (diff)
downloadvdr-6b0658a9775aba758b4f6e2e7ef854126ef1e597.tar.gz
vdr-6b0658a9775aba758b4f6e2e7ef854126ef1e597.tar.bz2
Switched to PES recording
Diffstat (limited to 'thread.c')
-rw-r--r--thread.c33
1 files changed, 30 insertions, 3 deletions
diff --git a/thread.c b/thread.c
index 8705fe2f..d56e8808 100644
--- a/thread.c
+++ b/thread.c
@@ -4,12 +4,15 @@
* See the main source file 'vdr.c' for copyright information and
* how to reach the author.
*
- * $Id: thread.c 1.5 2000/11/22 17:11:04 kls Exp $
+ * $Id: thread.c 1.6 2000/12/03 15:35:02 kls Exp $
*/
#include "thread.h"
+#include <errno.h>
#include <signal.h>
+#include <sys/wait.h>
#include <unistd.h>
+#include "tools.h"
// --- cThread ---------------------------------------------------------------
@@ -25,7 +28,7 @@ cThread::cThread(void)
signalHandlerInstalled = true;
}
running = false;
- parentPid = lockingPid = 0;
+ parentPid = threadPid = lockingPid = 0;
locked = 0;
}
@@ -40,6 +43,7 @@ void cThread::SignalHandler(int signum)
void *cThread::StartThread(cThread *Thread)
{
+ Thread->threadPid = getpid();
Thread->Action();
return NULL;
}
@@ -54,8 +58,31 @@ bool cThread::Start(void)
return true; //XXX return value of pthread_create()???
}
-void cThread::Stop(void)
+bool cThread::Active(void)
{
+ if (threadPid) {
+ if (kill(threadPid, SIGIO) < 0) { // couldn't find another way of checking whether the thread is still running - any ideas?
+ if (errno == ESRCH)
+ threadPid = 0;
+ else
+ LOG_ERROR;
+ }
+ else
+ return true;
+ }
+ return false;
+}
+
+void cThread::Cancel(int WaitSeconds)
+{
+ if (WaitSeconds > 0) {
+ for (time_t t0 = time(NULL) + WaitSeconds; time(NULL) < t0; ) {
+ if (!Active())
+ return;
+ usleep(10000);
+ }
+ esyslog(LOG_ERR, "ERROR: thread %d won't end (waited %d seconds) - cancelling it...", threadPid, WaitSeconds);
+ }
pthread_cancel(thread);
}