1
0
mirror of https://github.com/janet-lang/janet synced 2024-06-24 22:23:15 +00:00

Update for old osx versions.

This commit is contained in:
Calvin Rose 2018-09-22 21:46:50 -04:00
parent d9752a9028
commit 7131379021
2 changed files with 28 additions and 11 deletions

View File

@ -34,6 +34,12 @@
#include <stdio.h>
#endif
/* For macos */
#ifdef __MACH__
#include <mach/clock.h>
#include <mach/mach.h>
#endif
static int os_which(JanetArgs args) {
#ifdef JANET_WINDOWS
JANET_RETURN_CSYMBOL(args, ":windows");
@ -208,10 +214,15 @@ static int os_exit(JanetArgs args) {
return 0;
}
/* Clock shim for windows */
static int os_time(JanetArgs args) {
JANET_FIXARITY(args, 0);
double dtime = (double)(time(NULL));
JANET_RETURN_REAL(args, dtime);
}
/* Clock shims */
#ifdef JANET_WINDOWS
static int clock_gettime(int x, struct timespec *spec) {
(void) x;
static int gettime(struct timespec *spec) {
int64_t wintime = 0LL;
GetSystemTimeAsFileTime((FILETIME*)&wintime);
/* Windows epoch is January 1, 1601 apparently*/
@ -221,14 +232,20 @@ static int clock_gettime(int x, struct timespec *spec) {
spec->tv_nsec = wintime % 10000000LL * 100;
return 0;
}
#define CLOCK_MONOTONIC 0
#endif
static int os_time(JanetArgs args) {
JANET_FIXARITY(args, 0);
double dtime = (double)(time(NULL));
JANET_RETURN_REAL(args, dtime);
#elif defined(__MACH__)
static int gettime(struct timespec *spec) {
clock_serv_t cclock;
mach_timespec_t mts;
host_get_clock_service(mach_host_self(), CALENDAR_CLOCK, &cclock);
clock_get_time(cclock, &mts);
mach_port_deallocate(mach_task_self(), cclock);
spec->tv_sec = mts.tv_sec;
spec->tv_nsec = mts.tv_nsec;
return 0;
}
#else
#define gettime(TV) clock_gettime(CLOCK_MONOTONIC, (TV))
#endif
static int os_clock(JanetArgs args) {
JANET_FIXARITY(args, 0);

View File

@ -1333,7 +1333,7 @@ int janet_init(void) {
* a collection pretty much every cycle, which is
* incredibly horrible for performance, but can help ensure
* there are no memory bugs during development */
janet_vm_gc_interval = 0x1000000;
janet_vm_gc_interval = 0x4000000;
janet_symcache_init();
/* Initialize gc list */
janet_vm_gc_marklist = NULL;