blob: 98ac85ecf367129d29ca6951c41f35d7e5edf43b (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
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
42
43
44
45
46
47
48
49
50
51
52
53
|
#include "HsFFI.h"
#include "conc059_stub.h"
#include <stdbool.h>
#include <unistd.h>
#include <stdlib.h>
#include <errno.h>
#include <stdio.h>
#if mingw32_HOST_OS
#include <windows.h>
#endif
void millisleep(int milliseconds);
int main(int argc, char *argv[])
{
hs_init(&argc,&argv);
f(5000); // this should be considerably longer than the delay on the next
// line
millisleep(100);
printf("exiting...\n");
fflush(stdout);
hs_exit();
printf("exited.\n");
millisleep(1000);
exit(0);
}
void millisleep(int milliseconds) {
#if defined(mingw32_HOST_OS)
Sleep(milliseconds);
#else
struct timespec ts = {
.tv_sec = milliseconds / 1000,
.tv_nsec = (milliseconds % 1000) * 1000000
};
while (true) {
int ret = nanosleep(&ts, &ts);
if (ret == -1) {
if (errno != EINTR) {
printf("nanosleep failed\n");
exit(1);
} else {
continue;
}
} else {
return;
}
}
#endif
}
|