summaryrefslogtreecommitdiff
path: root/thread.c
diff options
context:
space:
mode:
authorKlaus Schmidinger <kls (at) cadsoft (dot) de>2000-10-08 18:00:00 +0200
committerKlaus Schmidinger <kls (at) cadsoft (dot) de>2000-10-08 18:00:00 +0200
commita379eb714f7f5ef9a12efbe7588bb3509faba056 (patch)
treeea9a0720f305e8ee76ea7c60c996fd3a8bad0ce5 /thread.c
parentef8fe3f04c30caedeb17b11ac275581539f039c7 (diff)
downloadvdr-patch-lnbsharing-a379eb714f7f5ef9a12efbe7588bb3509faba056.tar.gz
vdr-patch-lnbsharing-a379eb714f7f5ef9a12efbe7588bb3509faba056.tar.bz2
Version 0.66vdr-0.66
- Remote control data is now received in a separate thread, which makes things a lot smoother. - Repeat and release of remote control keys is now explicitly distinguished. - In replay mode the search forward/back and skip functions now have two modes: Pressing the key shortly and releasing it starts the function, and pressing it again stops it. Pressing and holding down the key starts the function and releasing the key stops it. - The '@' character that marks an "instant recording" can now be turned off in the "Setup" menu (thanks to Matthias Schniedermeyer). - Pressing the "Back" button while replaying now stops replaying and brings up the "Recordings" menu (suggested by Carsten Koch). This can be used to easily delete a recording after watching it, or to switch to a different recording. - The "Recordings" menu now places the cursor on the last replayed recording, if that file still exists. - The "Blue" button in the "Main" menu can now be used to "Resume" a previously stopped replay session (suggested by Martin Hammerschmid). - The low and high LNB frequencies can now be changed in the "Setup" menu.
Diffstat (limited to 'thread.c')
-rw-r--r--thread.c105
1 files changed, 105 insertions, 0 deletions
diff --git a/thread.c b/thread.c
new file mode 100644
index 0000000..7304e68
--- /dev/null
+++ b/thread.c
@@ -0,0 +1,105 @@
+/*
+ * thread.c: A simple thread base class
+ *
+ * See the main source file 'vdr.c' for copyright information and
+ * how to reach the author.
+ *
+ * $Id: thread.c 1.2 2000/10/08 16:45:50 kls Exp $
+ */
+
+#include "thread.h"
+#include <signal.h>
+#include <unistd.h>
+
+// --- cThread ---------------------------------------------------------------
+
+// The signal handler is necessary to be able to use SIGIO to wake up any
+// pending 'select()' call.
+
+bool cThread::signalHandlerInstalled = false;
+
+cThread::cThread(void)
+{
+ if (!signalHandlerInstalled) {
+ signal(SIGIO, SignalHandler);
+ signalHandlerInstalled = true;
+ }
+ pthread_mutex_init(&mutex, NULL);
+ running = false;
+ parentPid = lockingPid = 0;
+ locked = 0;
+}
+
+cThread::~cThread()
+{
+ pthread_mutex_destroy(&mutex);
+}
+
+void cThread::SignalHandler(int signum)
+{
+ signal(signum, SignalHandler);
+}
+
+void *cThread::StartThread(cThread *Thread)
+{
+ Thread->Action();
+ return NULL;
+}
+
+bool cThread::Start(void)
+{
+ if (!running) {
+ running = true;
+ parentPid = getpid();
+ pthread_create(&thread, NULL, &StartThread, (void *)this);
+ }
+ return true; //XXX return value of pthread_create()???
+}
+
+void cThread::Stop(void)
+{
+ pthread_cancel(thread);
+}
+
+bool cThread::Lock(void)
+{
+ if (!lockingPid || lockingPid != getpid()) {
+ pthread_mutex_lock(&mutex);
+ lockingPid = getpid();
+ }
+ locked++;
+ return true;
+}
+
+void cThread::Unlock(void)
+{
+ if (!--locked) {
+ lockingPid = 0;
+ pthread_mutex_unlock(&mutex);
+ }
+}
+
+void cThread::WakeUp(void)
+{
+ kill(parentPid, SIGIO); // makes any waiting 'select()' call return immediately
+}
+
+// --- cThreadLock -----------------------------------------------------------
+
+cThreadLock::cThreadLock(cThread *Thread)
+{
+ thread = Thread;
+ locked = Thread->Lock();
+}
+
+cThreadLock::~cThreadLock()
+{
+ if (locked)
+ thread->Unlock();
+}
+
+bool cThreadLock::Locked(void)
+{
+ return locked;
+}
+