Mailing List archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[vdr] Re: Threading issues on RH9
Hi,
On Saturday 31 May 2003 4:51 pm, Jon Burgess wrote:
> I have been having problems with getting vdr-1.1.33 to work reliably on
> a RH9 with a standard RH kernel (2.4.20-9).
>
> The problem with VDR seems to stem from the fact that the RH kernel
> includes the new NPTL "Native Posix Thread Library". This has changed a
> few things which breaks the VDR threading.
speculative fix included, compiles and works with gcc-3.3 on my box, but i
don't have NPTL, no guarantees !
Andreas
===== ringbuffer.c 1.10 vs edited =====
--- 1.10/ringbuffer.c Mon May 12 19:38:11 2003
+++ edited/ringbuffer.c Sat May 31 21:10:15 2003
@@ -75,7 +75,7 @@
{
margin = Margin;
buffer = NULL;
- getThreadPid = -1;
+ getThreadId = 0;
if (Size > 1) { // 'Size - 1' must not be 0!
buffer = MALLOC(uchar, Size);
if (!buffer)
@@ -125,7 +125,7 @@
int percent = maxFill * 100 / (Size() - 1) / 5 * 5;
if (abs(lastPercent - percent) >= 5) {
if (percent > 75)
- dsyslog("buffer usage: %d%% (pid=%d)", percent, getThreadPid);
+ dsyslog("buffer usage: %d%% (pid=%d)", percent, getThreadId);
lastPercent = percent;
}
}
@@ -159,8 +159,8 @@
{
uchar *p = NULL;
Lock();
- if (getThreadPid < 0)
- getThreadPid = getpid();
+ if (getThreadId <= 0)
+ getThreadId = pthread_self();
int rest = Size() - tail;
if (rest < margin && head < tail) {
int t = margin - rest;
===== ringbuffer.h 1.7 vs edited =====
--- 1.7/ringbuffer.h Mon May 12 19:35:10 2003
+++ edited/ringbuffer.h Sat May 31 21:07:42 2003
@@ -46,7 +46,7 @@
int margin, head, tail;
int lastGet;
uchar *buffer;
- pid_t getThreadPid;
+ pthread_t getThreadId;
public:
cRingBufferLinear(int Size, int Margin = 0, bool Statistics = false);
///< Creates a linear ring buffer.
===== thread.c 1.7 vs edited =====
--- 1.7/thread.c Sun May 18 14:45:13 2003
+++ edited/thread.c Sat May 31 21:37:37 2003
@@ -30,7 +30,7 @@
void cCondVar::Wait(cMutex &Mutex)
{
- if (Mutex.locked && Mutex.lockingPid == getpid()) {
+ if (Mutex.locked && pthread_equal(Mutex.lockedBy, pthread_self()) != 0) {
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
@@ -43,7 +43,7 @@
{
bool r = true; // true = condition signaled false = timeout
- if (Mutex.locked && Mutex.lockingPid == getpid()) {
+ if (Mutex.locked && pthread_equal(Mutex.lockedBy, pthread_self()) != 0) {
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
@@ -61,7 +61,7 @@
if (pthread_cond_timedwait(&cond, &Mutex.mutex, &abstime) ==
ETIMEDOUT)
r = false;
Mutex.locked = locked;
- Mutex.lockingPid = getpid();
+ Mutex.lockedBy = pthread_self();
}
}
return r;
@@ -83,7 +83,7 @@
cMutex::cMutex(void)
{
- lockingPid = 0;
+ lockedBy = 0;
locked = 0;
pthread_mutex_init(&mutex, NULL);
}
@@ -95,9 +95,9 @@
void cMutex::Lock(void)
{
- if (getpid() != lockingPid || !locked) {
+ if (pthread_equal(pthread_self(), lockedBy) == 0 || !locked) {
pthread_mutex_lock(&mutex);
- lockingPid = getpid();
+ lockedBy = pthread_self();
}
locked++;
}
@@ -105,7 +105,7 @@
void cMutex::Unlock(void)
{
if (!--locked) {
- lockingPid = 0;
+ lockedBy = 0;
pthread_mutex_unlock(&mutex);
}
}
@@ -125,7 +125,7 @@
signalHandlerInstalled = true;
}
running = false;
- parentPid = threadPid = 0;
+ parentId = threadId = 0;
}
cThread::~cThread()
@@ -139,7 +139,7 @@
void *cThread::StartThread(cThread *Thread)
{
- Thread->threadPid = getpid();
+ Thread->threadId = pthread_self();
Thread->Action();
return NULL;
}
@@ -148,7 +148,7 @@
{
if (!running) {
running = true;
- parentPid = getpid();
+ parentId = pthread_self();
pthread_create(&thread, NULL, (void *(*) (void *))&StartThread, (void
*)this);
pthread_setschedparam(thread, SCHED_RR, 0);
usleep(10000); // otherwise calling Active() immediately after Start()
causes a "pure virtual method called" error
@@ -158,10 +158,11 @@
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;
+ if (threadId) {
+ int err;
+ if ((err = pthread_kill(threadId, 0)) != 0) { // couldn't find another
way of checking whether the thread is still running - any ideas? - 0 should
work, according to the specs
+ if (err == ESRCH)
+ threadId = 0;
else
LOG_ERROR;
}
@@ -180,14 +181,14 @@
return;
usleep(10000);
}
- esyslog("ERROR: thread %d won't end (waited %d seconds) - cancelling
it...", threadPid, WaitSeconds);
+ esyslog("ERROR: thread %ld won't end (waited %d seconds) - cancelling
it...", threadId, WaitSeconds);
}
pthread_cancel(thread);
}
void cThread::WakeUp(void)
{
- kill(parentPid, SIGIO); // makes any waiting 'select()' call return
immediately
+ pthread_kill(parentId, SIGIO); // makes any waiting 'select()' call return
immediately
}
bool cThread::EmergencyExit(bool Request)
===== thread.h 1.4 vs edited =====
--- 1.4/thread.h Sat May 3 16:03:36 2003
+++ edited/thread.h Sat May 31 21:03:57 2003
@@ -32,7 +32,7 @@
friend class cCondVar;
private:
pthread_mutex_t mutex;
- pid_t lockingPid;
+ pthread_t lockedBy;
int locked;
public:
cMutex(void);
@@ -46,7 +46,7 @@
private:
pthread_t thread;
cMutex mutex;
- pid_t parentPid, threadPid;
+ pthread_t parentId, threadId;
bool running;
static bool emergencyExitRequested;
static bool signalHandlerInstalled;
--
Info:
To unsubscribe send a mail to ecartis@linuxtv.org with "unsubscribe vdr" as subject.
Home |
Main Index |
Thread Index