diff options
| author | Graydon Hoare <graydon@pobox.com> | 2010-06-24 08:52:52 -0700 |
|---|---|---|
| committer | Graydon Hoare <graydon@pobox.com> | 2010-06-24 08:52:52 -0700 |
| commit | 4a1f86ccd7e823f63d12208baef79b1e74479203 (patch) | |
| tree | 985d18aa6aa6ee2c77c1f5129f551bc812bf5d51 /src/rt/rust_timer.cpp | |
| parent | 0016473117e4bc3c8959bf2fd49368844847d74c (diff) | |
| download | rust-4a1f86ccd7e823f63d12208baef79b1e74479203.tar.gz rust-4a1f86ccd7e823f63d12208baef79b1e74479203.zip | |
Merge timer loop functions, fix win32 build broken by logger change.
Diffstat (limited to 'src/rt/rust_timer.cpp')
| -rw-r--r-- | src/rt/rust_timer.cpp | 40 |
1 files changed, 17 insertions, 23 deletions
diff --git a/src/rt/rust_timer.cpp b/src/rt/rust_timer.cpp index 897b7730182..7950c02196a 100644 --- a/src/rt/rust_timer.cpp +++ b/src/rt/rust_timer.cpp @@ -21,55 +21,49 @@ #if defined(__WIN32__) static DWORD WINAPI -win32_timer_loop(void *ptr) +#elif defined(__GNUC__) +static void * +#else +#error "Platform not supported" +#endif +timer_loop(void *ptr) { // We were handed the rust_timer that owns us. rust_timer *timer = (rust_timer *)ptr; rust_dom &dom = timer->dom; - dom.log(LOG_TIMER, "in timer 0x%" PRIxPTR, (uintptr_t)timer); + dom.log(rust_log::TIMER, "in timer 0x%" PRIxPTR, (uintptr_t)timer); while (!timer->exit_flag) { +#if defined(__WIN32__) Sleep(TIME_SLICE_IN_MS); - dom.log(LOG_TIMER, +#else + usleep(TIME_SLICE_IN_MS * 1000); +#endif + dom.log(rust_log::TIMER, "timer 0x%" PRIxPTR " interrupting domain 0x%" PRIxPTR, (uintptr_t)timer, (uintptr_t)&dom); dom.interrupt_flag = 1; } +#if defined(__WIN32__) ExitThread(0); - return 0; -} - -#elif defined(__GNUC__) -static void * -pthread_timer_loop(void *ptr) -{ - // We were handed the rust_timer that owns us. - rust_timer *timer = (rust_timer *)ptr; - rust_dom &dom(timer->dom); - while (!timer->exit_flag) { - usleep(TIME_SLICE_IN_MS * 1000); - dom.interrupt_flag = 1; - } +#else pthread_exit(NULL); +#endif return 0; - } -#else -#error "Platform not supported" -#endif rust_timer::rust_timer(rust_dom &dom) : dom(dom), exit_flag(0) { dom.log(rust_log::TIMER, "creating timer for domain 0x%" PRIxPTR, &dom); #if defined(__WIN32__) - thread = CreateThread(NULL, 0, win32_timer_loop, this, 0, NULL); + thread = CreateThread(NULL, 0, timer_loop, this, 0, NULL); dom.win32_require("CreateThread", thread != NULL); #else pthread_attr_init(&attr); pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE); - pthread_create(&thread, &attr, pthread_timer_loop, (void *)this); + pthread_create(&thread, &attr, timer_loop, (void *)this); #endif } |
