Read local time immediately after select()

This removes a small inaccuracy caused by delay between select() and
file handler calls.
This commit is contained in:
Miroslav Lichvar
2009-11-30 13:19:55 +01:00
parent 159a9519e8
commit e9ae3d0a0b
5 changed files with 20 additions and 6 deletions

13
sched.c
View File

@@ -71,6 +71,9 @@ typedef struct {
static FileHandlerEntry file_handlers[FD_SET_SIZE];
/* Last timestamp when a file descriptor became readable */
static struct timeval last_fdready;
/* ================================================== */
/* Variables to handler the timer queue */
@@ -225,6 +228,14 @@ SCH_RemoveInputFileHandler(int fd)
/* ================================================== */
void
SCH_GetFileReadyTime(struct timeval *tv)
{
*tv = last_fdready;
}
/* ================================================== */
#define TQE_ALLOC_QUANTUM 32
static TimerQueueEntry *
@@ -514,6 +525,7 @@ SCH_MainLoop(void)
int status;
struct timeval tv, *ptv;
struct timeval now;
double err;
if (!initialised) {
CROAK("Should be initialised");
@@ -551,6 +563,7 @@ SCH_MainLoop(void)
}
status = select(one_highest_fd, &rd, NULL, NULL, ptv);
LCL_ReadCookedTime(&last_fdready, &err);
if (status < 0) {
if (!need_to_exit)