mirror of
https://github.com/VDR4Arch/vdr.git
synced 2023-10-10 13:36:52 +02:00
Added cCondWait::Sleep() and using it to replace all usleep() calls
This commit is contained in:
parent
70e6038056
commit
9f51fcad22
@ -257,6 +257,7 @@ Werner Fink <werner@suse.de>
|
|||||||
for modifying handling of audio packets in cDvbPlayer for better sync with external
|
for modifying handling of audio packets in cDvbPlayer for better sync with external
|
||||||
AC3 replay
|
AC3 replay
|
||||||
for changing thread handling to make it work with NPTL ("Native Posix Thread Library")
|
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>
|
Rolf Hakenes <hakenes@hippomi.de>
|
||||||
for providing 'libdtv' and adapting the EIT mechanisms to it
|
for providing 'libdtv' and adapting the EIT mechanisms to it
|
||||||
|
2
HISTORY
2
HISTORY
@ -3069,3 +3069,5 @@ Video Disk Recorder Revision History
|
|||||||
cThread::Start() (suggested by Ludwig Nussel). Also removed 'running' from
|
cThread::Start() (suggested by Ludwig Nussel). Also removed 'running' from
|
||||||
cThread and using only childTid to indicate whether a thread is actually
|
cThread and using only childTid to indicate whether a thread is actually
|
||||||
running.
|
running.
|
||||||
|
- Added cCondWait::Sleep() and using it to replace all usleep() calls (based
|
||||||
|
on a suggestion by Werner Fink).
|
||||||
|
5
diseqc.c
5
diseqc.c
@ -4,12 +4,13 @@
|
|||||||
* See the main source file 'vdr.c' for copyright information and
|
* See the main source file 'vdr.c' for copyright information and
|
||||||
* how to reach the author.
|
* 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 "diseqc.h"
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include "sources.h"
|
#include "sources.h"
|
||||||
|
#include "thread.h"
|
||||||
|
|
||||||
// -- cDiseqc ----------------------------------------------------------------
|
// -- cDiseqc ----------------------------------------------------------------
|
||||||
|
|
||||||
@ -61,7 +62,7 @@ char *cDiseqc::Wait(char *s)
|
|||||||
int n = strtol(s, &p, 10);
|
int n = strtol(s, &p, 10);
|
||||||
if (!errno && p != s && n >= 0) {
|
if (!errno && p != s && n >= 0) {
|
||||||
if (!parsing)
|
if (!parsing)
|
||||||
usleep(n * 1000);
|
cCondWait::SleepMs(n);
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
esyslog("ERROR: illegal value for wait time in '%s'", s - 1);
|
esyslog("ERROR: illegal value for wait time in '%s'", s - 1);
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
* See the main source file 'vdr.c' for copyright information and
|
* See the main source file 'vdr.c' for copyright information and
|
||||||
* how to reach the author.
|
* 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"
|
#include "dvbdevice.h"
|
||||||
@ -1075,7 +1075,7 @@ void cDvbDevice::StillPicture(const uchar *Data, int Length)
|
|||||||
#define MIN_IFRAME 400000
|
#define MIN_IFRAME 400000
|
||||||
for (int i = MIN_IFRAME / Length + 1; i > 0; i--) {
|
for (int i = MIN_IFRAME / Length + 1; i > 0; i--) {
|
||||||
safe_write(fd_video, Data, Length);
|
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
|
#endif
|
||||||
}
|
}
|
||||||
|
@ -4,13 +4,14 @@
|
|||||||
* See the main source file 'vdr.c' for copyright information and
|
* See the main source file 'vdr.c' for copyright information and
|
||||||
* how to reach the author.
|
* 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 "sections.h"
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include "channels.h"
|
#include "channels.h"
|
||||||
#include "device.h"
|
#include "device.h"
|
||||||
|
#include "thread.h"
|
||||||
|
|
||||||
// --- cFilterHandle----------------------------------------------------------
|
// --- cFilterHandle----------------------------------------------------------
|
||||||
|
|
||||||
@ -185,7 +186,7 @@ void cSectionHandler::Action(void)
|
|||||||
if (poll(pfd, NumFilters, 1000) > 0) {
|
if (poll(pfd, NumFilters, 1000) > 0) {
|
||||||
bool DeviceHasLock = device->HasLock();
|
bool DeviceHasLock = device->HasLock();
|
||||||
if (!DeviceHasLock)
|
if (!DeviceHasLock)
|
||||||
usleep(100000);
|
cCondWait::SleepMs(100);
|
||||||
for (int i = 0; i < NumFilters; i++) {
|
for (int i = 0; i < NumFilters; i++) {
|
||||||
if (pfd[i].revents & POLLIN) {
|
if (pfd[i].revents & POLLIN) {
|
||||||
cFilterHandle *fh = NULL;
|
cFilterHandle *fh = NULL;
|
||||||
|
12
thread.c
12
thread.c
@ -4,7 +4,7 @@
|
|||||||
* See the main source file 'vdr.c' for copyright information and
|
* See the main source file 'vdr.c' for copyright information and
|
||||||
* how to reach the author.
|
* 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"
|
#include "thread.h"
|
||||||
@ -32,6 +32,12 @@ cCondWait::~cCondWait()
|
|||||||
pthread_mutex_destroy(&mutex);
|
pthread_mutex_destroy(&mutex);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void cCondWait::SleepMs(int TimeoutMs)
|
||||||
|
{
|
||||||
|
cCondWait w;
|
||||||
|
w.Wait(TimeoutMs);
|
||||||
|
}
|
||||||
|
|
||||||
bool cCondWait::Wait(int TimeoutMs)
|
bool cCondWait::Wait(int TimeoutMs)
|
||||||
{
|
{
|
||||||
pthread_mutex_lock(&mutex);
|
pthread_mutex_lock(&mutex);
|
||||||
@ -265,7 +271,7 @@ void cThread::Cancel(int WaitSeconds)
|
|||||||
for (time_t t0 = time(NULL) + WaitSeconds; time(NULL) < t0; ) {
|
for (time_t t0 = time(NULL) + WaitSeconds; time(NULL) < t0; ) {
|
||||||
if (!Active())
|
if (!Active())
|
||||||
return;
|
return;
|
||||||
usleep(10000);
|
cCondWait::SleepMs(10);
|
||||||
}
|
}
|
||||||
esyslog("ERROR: thread %ld won't end (waited %d seconds) - cancelling it...", childTid, WaitSeconds);
|
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)
|
else if (ret == pid)
|
||||||
break;
|
break;
|
||||||
i--;
|
i--;
|
||||||
usleep(100000);
|
cCondWait::SleepMs(100);
|
||||||
}
|
}
|
||||||
if (!i) {
|
if (!i) {
|
||||||
kill(pid, SIGKILL);
|
kill(pid, SIGKILL);
|
||||||
|
6
thread.h
6
thread.h
@ -4,7 +4,7 @@
|
|||||||
* See the main source file 'vdr.c' for copyright information and
|
* See the main source file 'vdr.c' for copyright information and
|
||||||
* how to reach the author.
|
* 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
|
#ifndef __THREAD_H
|
||||||
@ -22,6 +22,10 @@ private:
|
|||||||
public:
|
public:
|
||||||
cCondWait(void);
|
cCondWait(void);
|
||||||
~cCondWait();
|
~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);
|
bool Wait(int TimeoutMs = 0);
|
||||||
///< Waits at most TimeoutMs milliseconds for a call to Signal(), or
|
///< Waits at most TimeoutMs milliseconds for a call to Signal(), or
|
||||||
///< forever if TimeoutMs is 0.
|
///< forever if TimeoutMs is 0.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user