Skip to content
Snippets Groups Projects
Commit b2452bfc authored by deuce's avatar deuce
Browse files

Change od_sleep() behaviour to select STDIN then call od_kernel() if there

is data waiting.

od_kernel is now ran once every second rather than every 250 ms (One second
granularity is fine for all other kernel tasks afaik)
parent 6d02d9f3
No related branches found
No related tags found
No related merge requests found
...@@ -304,6 +304,10 @@ tODResult ODInQueueGetNextEvent(tODInQueueHandle hInQueue, ...@@ -304,6 +304,10 @@ tODResult ODInQueueGetNextEvent(tODInQueueHandle hInQueue,
tODInputEvent *pEvent, tODMilliSec Timeout) tODInputEvent *pEvent, tODMilliSec Timeout)
{ {
tInputQueueInfo *pInputQueueInfo = ODHANDLE2PTR(hInQueue, tInputQueueInfo); tInputQueueInfo *pInputQueueInfo = ODHANDLE2PTR(hInQueue, tInputQueueInfo);
#ifdef ODPLAT_NIX
struct timeval tv;
fd_set in;
#endif
ASSERT(pInputQueueInfo != NULL); ASSERT(pInputQueueInfo != NULL);
ASSERT(pEvent != NULL); ASSERT(pEvent != NULL);
......
...@@ -185,13 +185,13 @@ tODResult ODKrnlInitialize(void) ...@@ -185,13 +185,13 @@ tODResult ODKrnlInitialize(void)
sigaddset(&block,SIGHUP); sigaddset(&block,SIGHUP);
sigprocmask(SIG_BLOCK,&block,NULL); sigprocmask(SIG_BLOCK,&block,NULL);
/* Run kernel on SIGALRM */ /* Run kernel on SIGALRM (Every 1 second) */
act.sa_handler=sig_run_kernel; act.sa_handler=sig_run_kernel;
act.sa_flags=0; act.sa_flags=0;
sigemptyset(&(act.sa_mask)); sigemptyset(&(act.sa_mask));
sigaction(SIGALRM,&act,NULL); sigaction(SIGALRM,&act,NULL);
itv.it_interval.tv_sec=0; itv.it_interval.tv_sec=1;
itv.it_interval.tv_usec=250000; itv.it_interval.tv_usec=0;
itv.it_value.tv_sec=0; itv.it_value.tv_sec=0;
itv.it_value.tv_usec=250000; itv.it_value.tv_usec=250000;
setitimer(ITIMER_REAL,&itv,NULL); setitimer(ITIMER_REAL,&itv,NULL);
......
...@@ -779,6 +779,7 @@ ODAPIDEF void ODCALL od_sleep(tODMilliSec Milliseconds) ...@@ -779,6 +779,7 @@ ODAPIDEF void ODCALL od_sleep(tODMilliSec Milliseconds)
{ {
#ifdef ODPLAT_NIX #ifdef ODPLAT_NIX
struct timeval tv; struct timeval tv;
fd_set in;
#endif #endif
/* Log function entry if running in trace mode. */ /* Log function entry if running in trace mode. */
TRACE(TRACE_API, "od_sleep()"); TRACE(TRACE_API, "od_sleep()");
...@@ -810,13 +811,16 @@ ODAPIDEF void ODCALL od_sleep(tODMilliSec Milliseconds) ...@@ -810,13 +811,16 @@ ODAPIDEF void ODCALL od_sleep(tODMilliSec Milliseconds)
#endif /* ODPLAT_WIN32 */ #endif /* ODPLAT_WIN32 */
#ifdef ODPLAT_NIX #ifdef ODPLAT_NIX
/* Prevent 100% CPU usage! */ FD_ZERO(&in);
if(Milliseconds==0)
Milliseconds=1;
tv.tv_sec=Milliseconds/1000; tv.tv_sec=Milliseconds/1000;
tv.tv_usec=(Milliseconds%1000)*1000; tv.tv_usec=(Milliseconds%1000)*1000;
select(0,NULL,NULL,NULL,&tv); if(Milliseconds==0) {
tv.tv_usec=1000;
FD_SET(1,&in);
}
if(select(2,Milliseconds?NULL:&in,NULL,NULL,&tv)>0)
od_kernel();
#endif #endif
OD_API_EXIT(); OD_API_EXIT();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment