Created
April 17, 2013 00:36
-
-
Save stepancheg/5400848 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| extern mod std; | |
| use core::comm; | |
| use std::time; | |
| fn to_us(ts: &time::Timespec) -> u64 { | |
| ts.sec * 1000000 as u64 + ((ts.nsec / 1000) as u64) | |
| } | |
| fn now_us() -> u64 { | |
| to_us(&time::get_time()) | |
| } | |
| fn main() { | |
| let (port1, chan1): (Port<int>, Chan<int>) = comm::stream(); | |
| let (port2, chan2): (Port<int>, Chan<int>) = comm::stream(); | |
| let steps = 100000; | |
| do spawn || { | |
| let mut i = 0; | |
| while i < steps { | |
| chan2.send(port1.recv()); | |
| i += 1; | |
| } | |
| }; | |
| let start = now_us(); | |
| let mut i = 0; | |
| while i < steps { | |
| chan1.send(i as int); | |
| port2.recv(); | |
| i += 1; | |
| } | |
| let d = now_us() - start; | |
| let per_step = d * 1000 / steps; | |
| io::println(u64::to_str(per_step)); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| diff --git a/src/rt/rust_sched_loop.cpp b/src/rt/rust_sched_loop.cpp | |
| index 90393ac..547b47a 100644 | |
| --- a/src/rt/rust_sched_loop.cpp | |
| +++ b/src/rt/rust_sched_loop.cpp | |
| @@ -13,10 +13,12 @@ | |
| #include "rust_util.h" | |
| #include "rust_scheduler.h" | |
| -#ifndef _WIN32 | |
| -pthread_key_t rust_sched_loop::task_key; | |
| -#else | |
| +#ifdef _WIN32 | |
| DWORD rust_sched_loop::task_key; | |
| +#elif 1 | |
| +__thread rust_task *rust_sched_loop::task_key; | |
| +#else | |
| +pthread_key_t rust_sched_loop::task_key; | |
| #endif | |
| const size_t C_STACK_SIZE = 2*1024*1024; | |
| @@ -343,32 +345,43 @@ rust_sched_loop::transition(rust_task *task, | |
| pump_loop(); | |
| } | |
| -#ifndef _WIN32 | |
| +#ifdef _WIN32 | |
| void | |
| rust_sched_loop::init_tls() { | |
| - int result = pthread_key_create(&task_key, NULL); | |
| - assert(!result && "Couldn't create the TLS key!"); | |
| + task_key = TlsAlloc(); | |
| + assert(task_key != TLS_OUT_OF_INDEXES && "Couldn't create the TLS key!"); | |
| tls_initialized = true; | |
| } | |
| void | |
| rust_sched_loop::place_task_in_tls(rust_task *task) { | |
| - int result = pthread_setspecific(task_key, task); | |
| - assert(!result && "Couldn't place the task in TLS!"); | |
| + BOOL result = TlsSetValue(task_key, task); | |
| + assert(result && "Couldn't place the task in TLS!"); | |
| + task->record_stack_limit(); | |
| +} | |
| +#elif 1 | |
| +void | |
| +rust_sched_loop::init_tls() { | |
| + tls_initialized = true; | |
| +} | |
| + | |
| +void | |
| +rust_sched_loop::place_task_in_tls(rust_task *task) { | |
| + task_key = task; | |
| task->record_stack_limit(); | |
| } | |
| #else | |
| void | |
| rust_sched_loop::init_tls() { | |
| - task_key = TlsAlloc(); | |
| - assert(task_key != TLS_OUT_OF_INDEXES && "Couldn't create the TLS key!"); | |
| + int result = pthread_key_create(&task_key, NULL); | |
| + assert(!result && "Couldn't create the TLS key!"); | |
| tls_initialized = true; | |
| } | |
| void | |
| rust_sched_loop::place_task_in_tls(rust_task *task) { | |
| - BOOL result = TlsSetValue(task_key, task); | |
| - assert(result && "Couldn't place the task in TLS!"); | |
| + int result = pthread_setspecific(task_key, task); | |
| + assert(!result && "Couldn't place the task in TLS!"); | |
| task->record_stack_limit(); | |
| } | |
| #endif | |
| diff --git a/src/rt/rust_sched_loop.h b/src/rt/rust_sched_loop.h | |
| index 736c09e..35f2071 100644 | |
| --- a/src/rt/rust_sched_loop.h | |
| +++ b/src/rt/rust_sched_loop.h | |
| @@ -55,10 +55,12 @@ private: | |
| static bool tls_initialized; | |
| -#ifndef __WIN32__ | |
| - static pthread_key_t task_key; | |
| -#else | |
| +#ifdef __WIN32__ | |
| static DWORD task_key; | |
| +#elif 1 | |
| + static __thread rust_task *task_key; | |
| +#else | |
| + static pthread_key_t task_key; | |
| #endif | |
| context c_context; | |
| @@ -162,6 +164,9 @@ inline rust_task* rust_sched_loop::try_get_task_tls() | |
| #ifdef __WIN32__ | |
| rust_task *task = reinterpret_cast<rust_task *> | |
| (TlsGetValue(task_key)); | |
| +#elif 1 | |
| + rust_task *task = reinterpret_cast<rust_task *> | |
| + (task_key); | |
| #else | |
| rust_task *task = reinterpret_cast<rust_task *> | |
| (pthread_getspecific(task_key)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment