about summary refs log tree commit diff
path: root/src/rt/rust_sched_loop.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/rt/rust_sched_loop.h')
-rw-r--r--src/rt/rust_sched_loop.h32
1 files changed, 25 insertions, 7 deletions
diff --git a/src/rt/rust_sched_loop.h b/src/rt/rust_sched_loop.h
index 61ed25bf8fa..9c059ac6230 100644
--- a/src/rt/rust_sched_loop.h
+++ b/src/rt/rust_sched_loop.h
@@ -38,6 +38,14 @@ private:
 
     const int id;
 
+    static bool tls_initialized;
+
+#ifndef __WIN32__
+    static pthread_key_t task_key;
+#else
+    static DWORD task_key;
+#endif
+
     context c_context;
 
     bool should_exit;
@@ -62,13 +70,6 @@ private:
 public:
     rust_kernel *kernel;
     rust_scheduler *sched;
-    static bool tls_initialized;
-
-#ifndef __WIN32__
-    static pthread_key_t task_key;
-#else
-    static DWORD task_key;
-#endif
 
     // NB: this is used to filter *runtime-originating* debug
     // logging, on a per-scheduler basis. It's not likely what
@@ -116,6 +117,8 @@ public:
     void init_tls();
     void place_task_in_tls(rust_task *task);
 
+    static rust_task *get_task_tls();
+
     // Called by each task when they are ready to be destroyed
     void release_task(rust_task *task);
 
@@ -132,6 +135,21 @@ rust_sched_loop::get_log() {
     return _log;
 }
 
+inline rust_task* rust_sched_loop::get_task_tls()
+{
+    if (!tls_initialized)
+        return NULL;
+#ifdef __WIN32__
+    rust_task *task = reinterpret_cast<rust_task *>
+        (TlsGetValue(task_key));
+#else
+    rust_task *task = reinterpret_cast<rust_task *>
+        (pthread_getspecific(task_key));
+#endif
+    assert(task && "Couldn't get the task from TLS!");
+    return task;
+}
+
 // NB: Runs on the Rust stack
 inline stk_seg *
 rust_sched_loop::borrow_c_stack() {