mirror of
https://github.com/VDR4Arch/vdr.git
synced 2023-10-10 13:36:52 +02:00
Mutexes are now created with PTHREAD_MUTEX_ERRORCHECK_NP
This commit is contained in:
parent
b658b1fe16
commit
e7b6b2fff7
@ -178,6 +178,8 @@ Stefan Huelswitt <huels@iname.com>
|
||||
for fixing a possible access of invalid file handles in cSIProcessor::Action()
|
||||
for fixing extracting the ES data in cDvbDevice::StillPicture()
|
||||
for changing thread handling to make it work with NPTL ("Native Posix Thread Library")
|
||||
for creating mutexes with PTHREAD_MUTEX_ERRORCHECK_NP, which made the 'lockingTid'
|
||||
stuff obsolete
|
||||
|
||||
Ulrich Röder <roeder@efr-net.de>
|
||||
for pointing out that there are channels that have a symbol rate higher than
|
||||
|
2
HISTORY
2
HISTORY
@ -2446,3 +2446,5 @@ Video Disk Recorder Revision History
|
||||
instead of explicit 'dsyslog()' calls inside their Action() function in order
|
||||
to support logging the thread ids.
|
||||
- Added "Slovak Link" and "Czech Link" to 'ca.conf' (thanks to Emil Petersky).
|
||||
- Mutexes are now created with PTHREAD_MUTEX_ERRORCHECK_NP, which makes the
|
||||
'lockingTid' stuff obsolete (thanks to Stefan Huelswitt).
|
||||
|
18
thread.c
18
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.27 2003/10/18 12:14:55 kls Exp $
|
||||
* $Id: thread.c 1.28 2003/10/18 13:00:04 kls Exp $
|
||||
*/
|
||||
|
||||
#include "thread.h"
|
||||
@ -32,7 +32,7 @@ cCondVar::~cCondVar()
|
||||
|
||||
void cCondVar::Wait(cMutex &Mutex)
|
||||
{
|
||||
if (Mutex.locked && pthread_equal(Mutex.lockingTid, pthread_self())) {
|
||||
if (Mutex.locked) {
|
||||
int locked = Mutex.locked;
|
||||
Mutex.locked = 0; // have to clear the locked count here, as pthread_cond_wait
|
||||
// does an implizit unlock of the mutex
|
||||
@ -45,7 +45,7 @@ bool cCondVar::TimedWait(cMutex &Mutex, int TimeoutMs)
|
||||
{
|
||||
bool r = true; // true = condition signaled false = timeout
|
||||
|
||||
if (Mutex.locked && pthread_equal(Mutex.lockingTid, pthread_self())) {
|
||||
if (Mutex.locked) {
|
||||
struct timeval now; // unfortunately timedwait needs the absolute time, not the delta :-(
|
||||
if (gettimeofday(&now, NULL) == 0) { // get current time
|
||||
now.tv_usec += TimeoutMs * 1000; // add the timeout
|
||||
@ -63,7 +63,6 @@ bool cCondVar::TimedWait(cMutex &Mutex, int TimeoutMs)
|
||||
if (pthread_cond_timedwait(&cond, &Mutex.mutex, &abstime) == ETIMEDOUT)
|
||||
r = false;
|
||||
Mutex.locked = locked;
|
||||
Mutex.lockingTid = pthread_self();
|
||||
}
|
||||
}
|
||||
return r;
|
||||
@ -85,9 +84,9 @@ void cCondVar::Signal(void)
|
||||
|
||||
cMutex::cMutex(void)
|
||||
{
|
||||
lockingTid = 0;
|
||||
locked = 0;
|
||||
pthread_mutex_init(&mutex, NULL);
|
||||
pthread_mutexattr_t attr = { PTHREAD_MUTEX_ERRORCHECK_NP };
|
||||
pthread_mutex_init(&mutex, &attr);
|
||||
}
|
||||
|
||||
cMutex::~cMutex()
|
||||
@ -97,20 +96,15 @@ cMutex::~cMutex()
|
||||
|
||||
void cMutex::Lock(void)
|
||||
{
|
||||
if (!pthread_equal(lockingTid, pthread_self()) || !locked) {
|
||||
pthread_mutex_lock(&mutex);
|
||||
lockingTid = pthread_self();
|
||||
}
|
||||
locked++;
|
||||
}
|
||||
|
||||
void cMutex::Unlock(void)
|
||||
{
|
||||
if (!--locked) {
|
||||
lockingTid = 0;
|
||||
if (!--locked)
|
||||
pthread_mutex_unlock(&mutex);
|
||||
}
|
||||
}
|
||||
|
||||
// --- cThread ---------------------------------------------------------------
|
||||
|
||||
|
3
thread.h
3
thread.h
@ -4,7 +4,7 @@
|
||||
* See the main source file 'vdr.c' for copyright information and
|
||||
* how to reach the author.
|
||||
*
|
||||
* $Id: thread.h 1.17 2003/10/18 12:13:10 kls Exp $
|
||||
* $Id: thread.h 1.18 2003/10/18 12:56:20 kls Exp $
|
||||
*/
|
||||
|
||||
#ifndef __THREAD_H
|
||||
@ -32,7 +32,6 @@ class cMutex {
|
||||
friend class cCondVar;
|
||||
private:
|
||||
pthread_mutex_t mutex;
|
||||
pthread_t lockingTid;
|
||||
int locked;
|
||||
public:
|
||||
cMutex(void);
|
||||
|
Loading…
Reference in New Issue
Block a user