diff options
-rw-r--r-- | CONTRIBUTORS | 1 | ||||
-rw-r--r-- | HISTORY | 2 | ||||
-rw-r--r-- | diseqc.c | 5 | ||||
-rw-r--r-- | dvbdevice.c | 4 | ||||
-rw-r--r-- | sections.c | 5 | ||||
-rw-r--r-- | thread.c | 12 | ||||
-rw-r--r-- | thread.h | 6 |
7 files changed, 25 insertions, 10 deletions
diff --git a/CONTRIBUTORS b/CONTRIBUTORS index a7e0d386..86f1e289 100644 --- a/CONTRIBUTORS +++ b/CONTRIBUTORS @@ -257,6 +257,7 @@ Werner Fink <werner@suse.de> for modifying handling of audio packets in cDvbPlayer for better sync with external AC3 replay for changing thread handling to make it work with NPTL ("Native Posix Thread Library") + for suggesting to replace usleep() calls with a pthread_cond_timedwait() based wait Rolf Hakenes <hakenes@hippomi.de> for providing 'libdtv' and adapting the EIT mechanisms to it @@ -3069,3 +3069,5 @@ Video Disk Recorder Revision History cThread::Start() (suggested by Ludwig Nussel). Also removed 'running' from cThread and using only childTid to indicate whether a thread is actually running. +- Added cCondWait::Sleep() and using it to replace all usleep() calls (based + on a suggestion by Werner Fink). @@ -4,12 +4,13 @@ * See the main source file 'vdr.c' for copyright information and * how to reach the author. * - * $Id: diseqc.c 1.2 2002/12/07 13:44:56 kls Exp $ + * $Id: diseqc.c 1.3 2004/10/24 11:04:56 kls Exp $ */ #include "diseqc.h" #include <ctype.h> #include "sources.h" +#include "thread.h" // -- cDiseqc ---------------------------------------------------------------- @@ -61,7 +62,7 @@ char *cDiseqc::Wait(char *s) int n = strtol(s, &p, 10); if (!errno && p != s && n >= 0) { if (!parsing) - usleep(n * 1000); + cCondWait::SleepMs(n); return p; } esyslog("ERROR: illegal value for wait time in '%s'", s - 1); diff --git a/dvbdevice.c b/dvbdevice.c index bfe2aaf6..3f38a0a4 100644 --- a/dvbdevice.c +++ b/dvbdevice.c @@ -4,7 +4,7 @@ * See the main source file 'vdr.c' for copyright information and * how to reach the author. * - * $Id: dvbdevice.c 1.99 2004/10/24 08:50:15 kls Exp $ + * $Id: dvbdevice.c 1.100 2004/10/24 11:06:37 kls Exp $ */ #include "dvbdevice.h" @@ -1075,7 +1075,7 @@ void cDvbDevice::StillPicture(const uchar *Data, int Length) #define MIN_IFRAME 400000 for (int i = MIN_IFRAME / Length + 1; i > 0; i--) { safe_write(fd_video, Data, Length); - usleep(1); // allows the buffer to be displayed in case the progress display is active + cCondWait::SleepMs(1); // allows the buffer to be displayed in case the progress display is active } #endif } @@ -4,13 +4,14 @@ * See the main source file 'vdr.c' for copyright information and * how to reach the author. * - * $Id: sections.c 1.9 2004/10/16 13:45:02 kls Exp $ + * $Id: sections.c 1.10 2004/10/24 11:05:12 kls Exp $ */ #include "sections.h" #include <unistd.h> #include "channels.h" #include "device.h" +#include "thread.h" // --- cFilterHandle---------------------------------------------------------- @@ -185,7 +186,7 @@ void cSectionHandler::Action(void) if (poll(pfd, NumFilters, 1000) > 0) { bool DeviceHasLock = device->HasLock(); if (!DeviceHasLock) - usleep(100000); + cCondWait::SleepMs(100); for (int i = 0; i < NumFilters; i++) { if (pfd[i].revents & POLLIN) { cFilterHandle *fh = NULL; @@ -4,7 +4,7 @@ * See the main source file 'vdr.c' for copyright information and * how to reach the author. * - * $Id: thread.c 1.34 2004/10/24 10:27:47 kls Exp $ + * $Id: thread.c 1.35 2004/10/24 11:05:56 kls Exp $ */ #include "thread.h" @@ -32,6 +32,12 @@ cCondWait::~cCondWait() pthread_mutex_destroy(&mutex); } +void cCondWait::SleepMs(int TimeoutMs) +{ + cCondWait w; + w.Wait(TimeoutMs); +} + bool cCondWait::Wait(int TimeoutMs) { pthread_mutex_lock(&mutex); @@ -265,7 +271,7 @@ void cThread::Cancel(int WaitSeconds) for (time_t t0 = time(NULL) + WaitSeconds; time(NULL) < t0; ) { if (!Active()) return; - usleep(10000); + cCondWait::SleepMs(10); } esyslog("ERROR: thread %ld won't end (waited %d seconds) - cancelling it...", childTid, WaitSeconds); } @@ -433,7 +439,7 @@ int cPipe::Close(void) else if (ret == pid) break; i--; - usleep(100000); + cCondWait::SleepMs(100); } if (!i) { kill(pid, SIGKILL); @@ -4,7 +4,7 @@ * See the main source file 'vdr.c' for copyright information and * how to reach the author. * - * $Id: thread.h 1.23 2004/10/24 10:28:48 kls Exp $ + * $Id: thread.h 1.24 2004/10/24 11:00:32 kls Exp $ */ #ifndef __THREAD_H @@ -22,6 +22,10 @@ private: public: cCondWait(void); ~cCondWait(); + static void SleepMs(int TimeoutMs); + ///< Creates a cCondWait object and uses it to sleep for TimeoutMs + ///< milliseconds, immediately giving up the calling thread's time + ///< slice and thus avoiding a "busy wait". bool Wait(int TimeoutMs = 0); ///< Waits at most TimeoutMs milliseconds for a call to Signal(), or ///< forever if TimeoutMs is 0. |