Issue #7701: Fix crash in binascii.b2a_uu() in debug mode when given a
[python.git] / RISCOS / sleep.c
blobc85eb8651faf5916886b51e89962447bc23de1c6
1 #include "oslib/osmodule.h"
2 #include <stdio.h>
3 #include "kernel.h"
4 #include <limits.h>
5 #include <errno.h>
6 #include "oslib/taskwindow.h"
7 #include "Python.h"
10 int riscos_sleep(double delay)
12 os_t starttime, endtime, time; /* monotonic times (centiseconds) */
13 int *pollword, ret;
14 osbool claimed;
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);
23 /* allocate (in RMA) and set pollword for xupcall_sleep */
24 pollword = osmodule_alloc(4);
25 *pollword = 1;
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;
35 time = os_read_monotonic_time();
38 /* deallocate pollword */
39 osmodule_free(pollword);
40 return ret;