From c6667c06c34a25a8a21a1805b4f454f2d05d337c Mon Sep 17 00:00:00 2001 From: Jeff Olson Date: Wed, 11 Apr 2012 22:14:16 -0700 Subject: [PATCH] add needed fields for global libuv loop + bindings to manage from rust adding two pointers fields to rust_kernel :( .. have to do manual malloc/free for one of the fields, which feels wrong --- src/rt/rust_kernel.cpp | 7 +++++++ src/rt/rust_kernel.h | 9 +++++++++ src/rt/rust_uv.cpp | 21 +++++++++++++++++++++ src/rt/rustrt.def.in | 4 ++++ 4 files changed, 41 insertions(+) diff --git a/src/rt/rust_kernel.cpp b/src/rt/rust_kernel.cpp index a629f2ff4af..2a4315bd842 100644 --- a/src/rt/rust_kernel.cpp +++ b/src/rt/rust_kernel.cpp @@ -24,6 +24,13 @@ rust_kernel::rust_kernel(rust_env *env) : non_weak_tasks(0), env(env) { + // set up storage of pointers needed to + // access the global loop. + global_loop_chan = 0; + global_async_handle = (void**)::malloc( // FIXME -- can use this->malloc() + sizeof(void*)); // .. what do? + *global_async_handle = (void*)0; + // Create the single threaded scheduler that will run on the platform's // main thread rust_manual_sched_launcher_factory launchfac; diff --git a/src/rt/rust_kernel.h b/src/rt/rust_kernel.h index 1ccd423928d..a93ed118a35 100644 --- a/src/rt/rust_kernel.h +++ b/src/rt/rust_kernel.h @@ -73,6 +73,10 @@ class rust_kernel { rust_scheduler* get_scheduler_by_id_nolock(rust_sched_id id); void end_weak_tasks(); + // Used to communicate with the process-side, global libuv loop + uintptr_t global_loop_chan; + void** global_async_handle; + public: struct rust_env *env; @@ -117,6 +121,11 @@ public: void unweaken_task(rust_port_id chan); bool send_to_port(rust_port_id chan, void *sptr); + + uintptr_t* get_global_loop() { return &global_loop_chan; } + void** get_global_async_handle() { return global_async_handle; } + void set_global_async_handle(void* handle) { + *global_async_handle = handle; } }; template struct kernel_owned { diff --git a/src/rt/rust_uv.cpp b/src/rt/rust_uv.cpp index de73e87f579..17b1db4fccf 100644 --- a/src/rt/rust_uv.cpp +++ b/src/rt/rust_uv.cpp @@ -425,3 +425,24 @@ rust_uv_ip4_addr(const char* ip, int port) { LOG(task, stdlib, "after creating .. port: %d\n", addr.sin_port); return addr; } + +extern "C" uintptr_t* +rust_uv_get_kernel_global_chan_ptr() { + uintptr_t* result = rust_get_current_task()->kernel->get_global_loop(); + printf("global loop: %lu\n", (unsigned long int)result); + printf("global loop val: %lu\n", (unsigned long int)*result); + return result; +} + +extern "C" void** +rust_uv_get_kernel_global_async_handle() { + return rust_get_current_task()->kernel->get_global_async_handle(); +} +extern "C" void +rust_uv_set_kernel_global_async_handle(uv_async_t* handle) { + rust_get_current_task()->kernel->set_global_async_handle((void*)handle); +} +extern "C" void +rust_uv_free_kernel_global_async_handle() { + free((void*)rust_get_current_task()->kernel->get_global_async_handle()); +} diff --git a/src/rt/rustrt.def.in b/src/rt/rustrt.def.in index a17f35c64ae..323b0fdc0f7 100644 --- a/src/rt/rustrt.def.in +++ b/src/rt/rustrt.def.in @@ -134,6 +134,10 @@ rust_uv_get_data_for_req rust_uv_set_data_for_req rust_uv_get_base_from_buf rust_uv_get_len_from_buf +rust_uv_get_kernel_global_chan_ptr +rust_uv_get_kernel_global_async_handle +rust_uv_set_kernel_global_async_handle +rust_uv_free_kernel_global_async_handle rust_dbg_lock_create rust_dbg_lock_destroy rust_dbg_lock_lock