Advertisement
Guest User

Untitled

a guest
Apr 22nd, 2014
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.34 KB | None | 0 0
  1. diff --git a/vm/src/unix/os/os_unix.cpp b/vm/src/unix/os/os_unix.cpp
  2. index f415691..10255cf 100644
  3. --- a/vm/src/unix/os/os_unix.cpp
  4. +++ b/vm/src/unix/os/os_unix.cpp
  5. @@ -632,12 +632,35 @@ int OS::min_core(caddr_t addr, size_t len, char *vec) {
  6. # error which?
  7. #endif
  8.  
  9. +static pthread_t time_thread;
  10. +static pthread_mutex_t mutex1 = PTHREAD_MUTEX_INITIALIZER;
  11. +static timeval mytime;
  12. +
  13. +static void* time_func(void*) {
  14. + while (1) {
  15. + pthread_mutex_lock(&mutex1);
  16. + gettimeofday(&mytime, 0);
  17. + pthread_mutex_unlock(&mutex1);
  18. +
  19. + usleep(100000);
  20. + }
  21. + return 0;
  22. +}
  23. +
  24.  
  25. void OS::real_time(smi buf[]) {
  26. - struct timeval t;
  27. - gettimeofday(&t, 0); // changed for OS X, maybe should use unix headers after all?
  28. - buf[0] = t.tv_sec / seconds_per_day; //days
  29. - buf[1] = (t.tv_sec % seconds_per_day) * 1000 + (t.tv_usec / 1000); //msecs
  30. + static int init = 0;
  31. + if (!init) {
  32. + gettimeofday(&mytime, 0);
  33. + pthread_create (&time_thread, NULL, time_func, NULL);
  34. + init = 1;
  35. + }
  36. + pthread_mutex_lock(&mutex1);
  37. + int tv_sec = mytime.tv_sec;
  38. + int tv_usec = mytime.tv_usec;
  39. + pthread_mutex_unlock(&mutex1);
  40. + buf[0] = tv_sec / seconds_per_day; //days
  41. + buf[1] = (tv_sec % seconds_per_day) * 1000 + (tv_usec / 1000); //msecs
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement