blob: c85eb8651faf5916886b51e89962447bc23de1c6 [file] [log] [blame]
Guido van Rossume877f8b2001-10-24 20:13:15 +00001#include "oslib/osmodule.h"
Guido van Rossumbceccf52001-04-10 22:07:43 +00002#include <stdio.h>
3#include "kernel.h"
4#include <limits.h>
5#include <errno.h>
Guido van Rossume877f8b2001-10-24 20:13:15 +00006#include "oslib/taskwindow.h"
Guido van Rossumbceccf52001-04-10 22:07:43 +00007#include "Python.h"
8
9
Martin v. Löwisa94568a2003-05-10 07:36:56 +000010int riscos_sleep(double delay)
Guido van Rossumbceccf52001-04-10 22:07:43 +000011{
12 os_t starttime, endtime, time; /* monotonic times (centiseconds) */
13 int *pollword, ret;
Martin v. Löwisa94568a2003-05-10 07:36:56 +000014 osbool claimed;
Guido van Rossumbceccf52001-04-10 22:07:43 +000015
16 /* calculate end time */
17 starttime = os_read_monotonic_time();
18 if (starttime + 100.0*delay >INT_MAX)
19 endtime = INT_MAX;
20 else
21 endtime = (os_t)(starttime + 100.0*delay);
22
23 /* allocate (in RMA) and set pollword for xupcall_sleep */
24 pollword = osmodule_alloc(4);
25 *pollword = 1;
26
27 time = starttime;
28 ret = 0;
29 while ( time<endtime && time>=starttime ) {
30 xupcall_sleep (pollword, &claimed);
31 if (PyErr_CheckSignals()) {
32 ret = 1;
33 break;
34 }
35 time = os_read_monotonic_time();
36 }
37
38 /* deallocate pollword */
39 osmodule_free(pollword);
40 return ret;
41}