Rework Unix delay_s()/delay_ms()
Make delay_ms() sleep through the entire specified interval unless Ctrl-C is pressed; Using this feature, simplify Ctrl-C checking in places.
This commit is contained in:
parent
5909c6d60b
commit
16a25f206a
|
@ -184,8 +184,7 @@ static device_status_t fet3_poll(device_t dev_base)
|
|||
/* We don't support breakpoints yet, so there's nothing to poll
|
||||
* for.
|
||||
*/
|
||||
delay_ms(500);
|
||||
if (ctrlc_check())
|
||||
if(delay_ms(500) < 0)
|
||||
return DEVICE_STATUS_INTR;
|
||||
|
||||
return DEVICE_STATUS_RUNNING;
|
||||
|
|
|
@ -578,7 +578,7 @@ static device_status_t goodfet_poll(device_t dev_base)
|
|||
{
|
||||
(void)dev_base;
|
||||
|
||||
if (delay_ms(100) < 0 || ctrlc_check())
|
||||
if (delay_ms(100) < 0)
|
||||
return DEVICE_STATUS_INTR;
|
||||
|
||||
return DEVICE_STATUS_RUNNING;
|
||||
|
|
|
@ -301,7 +301,7 @@ static int pif_ctl(device_t dev_base, device_ctl_t type)
|
|||
/*----------------------------------------------------------------------------*/
|
||||
static device_status_t pif_poll(device_t dev_base)
|
||||
{
|
||||
if (delay_ms(100) < 0 || ctrlc_check())
|
||||
if (delay_ms(100) < 0)
|
||||
return DEVICE_STATUS_INTR;
|
||||
|
||||
return DEVICE_STATUS_RUNNING;
|
||||
|
|
|
@ -531,7 +531,7 @@ static device_status_t tilib_poll(device_t dev_base)
|
|||
{
|
||||
struct tilib_device *dev = (struct tilib_device *)dev_base;
|
||||
|
||||
if ((delay_ms(50) < 0) || ctrlc_check())
|
||||
if (delay_ms(50) < 0)
|
||||
return DEVICE_STATUS_INTR;
|
||||
|
||||
if (event_fetch(dev) & MID_HALT_ANY)
|
||||
|
|
23
util/util.c
23
util/util.c
|
@ -21,7 +21,6 @@
|
|||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
#include <assert.h>
|
||||
#include <time.h>
|
||||
|
||||
|
@ -29,6 +28,7 @@
|
|||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
#include "ctrlc.h"
|
||||
#include "util.h"
|
||||
#include "output.h"
|
||||
|
||||
|
@ -283,17 +283,28 @@ int delay_ms(unsigned int s)
|
|||
#else
|
||||
int delay_s(unsigned int s)
|
||||
{
|
||||
return sleep(s);
|
||||
return delay_ms(1000 * s);
|
||||
}
|
||||
|
||||
int delay_ms(unsigned int s)
|
||||
{
|
||||
struct timespec ts;
|
||||
struct timespec rq, rm;
|
||||
int ret;
|
||||
|
||||
ts.tv_sec = s / 1000;
|
||||
ts.tv_nsec = (s % 1000) * 1000000;
|
||||
rm.tv_sec = s / 1000;
|
||||
rm.tv_nsec = (s % 1000) * 1000000;
|
||||
|
||||
return nanosleep(&ts, NULL);
|
||||
do {
|
||||
if (ctrlc_check()) {
|
||||
ret = -1;
|
||||
break;
|
||||
}
|
||||
rq.tv_sec = rm.tv_sec;
|
||||
rq.tv_nsec = rm.tv_nsec;
|
||||
ret = nanosleep(&rq, &rm);
|
||||
} while(ret == -1 && errno == EINTR);
|
||||
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
|
Loading…
Reference in New Issue