sleep.c 866 Bytes
Newer Older
1
#include "oslib/osmodule.h"
2 3 4 5
#include <stdio.h>
#include "kernel.h"
#include <limits.h>
#include <errno.h>
6
#include "oslib/taskwindow.h"
7 8 9
#include "Python.h"


10
int riscos_sleep(double delay)
11 12 13
{
	os_t starttime, endtime, time; /* monotonic times (centiseconds) */
	int *pollword, ret;
14
	osbool claimed;
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41

        /* calculate end time */
	starttime = os_read_monotonic_time();
	if (starttime + 100.0*delay >INT_MAX)
		endtime = INT_MAX;
	else
		endtime = (os_t)(starttime + 100.0*delay);

	/* allocate (in RMA) and set pollword for xupcall_sleep */
	pollword = osmodule_alloc(4);
	*pollword = 1;

	time = starttime;
	ret = 0;
	while ( time<endtime && time>=starttime ) {
		xupcall_sleep (pollword, &claimed);
		if (PyErr_CheckSignals()) {
			ret = 1;
			break;
		}
		time = os_read_monotonic_time();
	}

	/* deallocate pollword */
	osmodule_free(pollword);
	return ret;
}