Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- diff --git a/vm/src/unix/os/os_unix.cpp b/vm/src/unix/os/os_unix.cpp
- index f415691..10255cf 100644
- --- a/vm/src/unix/os/os_unix.cpp
- +++ b/vm/src/unix/os/os_unix.cpp
- @@ -632,12 +632,35 @@ int OS::min_core(caddr_t addr, size_t len, char *vec) {
- # error which?
- #endif
- +static pthread_t time_thread;
- +static pthread_mutex_t mutex1 = PTHREAD_MUTEX_INITIALIZER;
- +static timeval mytime;
- +
- +static void* time_func(void*) {
- + while (1) {
- + pthread_mutex_lock(&mutex1);
- + gettimeofday(&mytime, 0);
- + pthread_mutex_unlock(&mutex1);
- +
- + usleep(100000);
- + }
- + return 0;
- +}
- +
- void OS::real_time(smi buf[]) {
- - struct timeval t;
- - gettimeofday(&t, 0); // changed for OS X, maybe should use unix headers after all?
- - buf[0] = t.tv_sec / seconds_per_day; //days
- - buf[1] = (t.tv_sec % seconds_per_day) * 1000 + (t.tv_usec / 1000); //msecs
- + static int init = 0;
- + if (!init) {
- + gettimeofday(&mytime, 0);
- + pthread_create (&time_thread, NULL, time_func, NULL);
- + init = 1;
- + }
- + pthread_mutex_lock(&mutex1);
- + int tv_sec = mytime.tv_sec;
- + int tv_usec = mytime.tv_usec;
- + pthread_mutex_unlock(&mutex1);
- + buf[0] = tv_sec / seconds_per_day; //days
- + buf[1] = (tv_sec % seconds_per_day) * 1000 + (tv_usec / 1000); //msecs
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement