Skip to content

Commit

Permalink
Merge pull request #143 from melted/eliminate_pthread_dep
Browse files Browse the repository at this point in the history
Remove dependency on pthreads on Windows
  • Loading branch information
melted authored May 24, 2020
2 parents 8f3e8b8 + 8d16980 commit 21f1e54
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
9 changes: 9 additions & 0 deletions support/c/idris_support.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#ifdef _WIN32
extern char **_environ;
#include "windows/win_utils.h"
#define environ _environ
#else
extern char** environ;
Expand Down Expand Up @@ -42,19 +43,27 @@ void idris2_putStr(char* f) {
}

void idris2_sleep(int sec) {
#ifdef _WIN32
win32_sleep(sec*1000);
#else
struct timespec t;
t.tv_sec = sec;
t.tv_nsec = 0;

nanosleep(&t, NULL);
#endif
}

void idris2_usleep(int usec) {
#ifdef _WIN32
win32_sleep(usec/1000);
#else
struct timespec t;
t.tv_sec = usec / 1000000;
t.tv_nsec = (usec % 1000000) * 1000;

nanosleep(&t, NULL);
#endif
}

int idris2_time() {
Expand Down
4 changes: 4 additions & 0 deletions support/c/windows/win_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,7 @@ void win32_gettime(int64_t* sec, int64_t* nsec)
*sec = t.QuadPart / 10000000;
*sec -= 11644473600; // LDAP epoch to Unix epoch
}

void win32_sleep(int ms) {
Sleep(ms);
}
1 change: 1 addition & 0 deletions support/c/windows/win_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ int win_fpoll(FILE *h);
FILE *win32_u8fopen(const char *path, const char *mode);
FILE *win32_u8popen(const char *path, const char *mode);
void win32_gettime(int64_t* sec, int64_t* nsec);
void win32_sleep(int ms);

0 comments on commit 21f1e54

Please sign in to comment.