summaryrefslogtreecommitdiff
path: root/genindex/thread.c
diff options
context:
space:
mode:
authorRichard <richard@ha-server.local>2016-09-04 11:18:57 +0100
committerRichard <richard@ha-server.local>2016-09-04 11:18:57 +0100
commit83632745c43d406856a3b9948cb5ea4a5ec22666 (patch)
tree76b4e1210c2fdd8f732f17b119e315a2ec72d5e3 /genindex/thread.c
downloadvdr-convert-83632745c43d406856a3b9948cb5ea4a5ec22666.tar.gz
vdr-convert-83632745c43d406856a3b9948cb5ea4a5ec22666.tar.bz2
Initial import
Diffstat (limited to 'genindex/thread.c')
-rw-r--r--genindex/thread.c45
1 files changed, 45 insertions, 0 deletions
diff --git a/genindex/thread.c b/genindex/thread.c
new file mode 100644
index 0000000..6b7ea0f
--- /dev/null
+++ b/genindex/thread.c
@@ -0,0 +1,45 @@
+/*
+ * 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,v 1.1 2010/08/18 21:27:14 richard Exp $
+ *
+ * This was taken from the VDR package, which was released under the GPL.
+ * Stripped down to make the PES parser happy
+ */
+
+#include "thread.h"
+#include <unistd.h>
+
+// --- cMutex ----------------------------------------------------------------
+
+cMutex::cMutex(void)
+{
+ lockingPid = 0;
+ locked = 0;
+ pthread_mutex_init(&mutex, NULL);
+}
+
+cMutex::~cMutex()
+{
+ pthread_mutex_destroy(&mutex);
+}
+
+void cMutex::Lock(void)
+{
+ if (getpid() != lockingPid || !locked) {
+ pthread_mutex_lock(&mutex);
+ lockingPid = getpid();
+ }
+ locked++;
+}
+
+void cMutex::Unlock(void)
+{
+ if (!--locked) {
+ lockingPid = 0;
+ pthread_mutex_unlock(&mutex);
+ }
+}