From 83632745c43d406856a3b9948cb5ea4a5ec22666 Mon Sep 17 00:00:00 2001 From: Richard Date: Sun, 4 Sep 2016 11:18:57 +0100 Subject: Initial import --- genindex/thread.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 genindex/thread.c (limited to 'genindex/thread.c') 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 + +// --- 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); + } +} -- cgit v1.2.3