/RISCOS/sleep.c

http://unladen-swallow.googlecode.com/ · C · 41 lines · 32 code · 6 blank · 3 comment · 4 complexity · 17ad3979cc25cb5b34b2317cb7ed7069 MD5 · raw file

  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"
  8. int riscos_sleep(double delay)
  9. {
  10. os_t starttime, endtime, time; /* monotonic times (centiseconds) */
  11. int *pollword, ret;
  12. osbool claimed;
  13. /* calculate end time */
  14. starttime = os_read_monotonic_time();
  15. if (starttime + 100.0*delay >INT_MAX)
  16. endtime = INT_MAX;
  17. else
  18. endtime = (os_t)(starttime + 100.0*delay);
  19. /* allocate (in RMA) and set pollword for xupcall_sleep */
  20. pollword = osmodule_alloc(4);
  21. *pollword = 1;
  22. time = starttime;
  23. ret = 0;
  24. while ( time<endtime && time>=starttime ) {
  25. xupcall_sleep (pollword, &claimed);
  26. if (PyErr_CheckSignals()) {
  27. ret = 1;
  28. break;
  29. }
  30. time = os_read_monotonic_time();
  31. }
  32. /* deallocate pollword */
  33. osmodule_free(pollword);
  34. return ret;
  35. }