diff options
| author | Jeff Olson <olson.jeffery@gmail.com> | 2012-05-14 07:01:23 -0700 |
|---|---|---|
| committer | Brian Anderson <banderson@mozilla.com> | 2012-05-22 22:29:16 -0700 |
| commit | 8769409612be396c77184a603ea344851b5a0e76 (patch) | |
| tree | 73281a7678c6a73bdf715db2d60cadd637a0d235 /src/rt/rust_uv.cpp | |
| parent | 733881d8522ac7b3873cc16b25ce4c6d83edfdd0 (diff) | |
| download | rust-8769409612be396c77184a603ea344851b5a0e76.tar.gz rust-8769409612be396c77184a603ea344851b5a0e76.zip | |
rt: adding rust_uv_* binding for kernel malloc and free'ing :/
I need these in the context of doing various malloc/free operations for libuv structs that need to live in the heap, because of API workflow (there's no stack to put them in). This has cropped up several times when impl'ing the high-level API for things like timers, but I've decided to take the plunge and use this approach for the net::tcp module. Technically, this can be avoided by spawning a new task that contains the needed memory structures on its stack and then having it block for the duration of the time we need that memory to be valid (this is what I did in std::timer). Exposing this API provides a much lower overhead way to address the issue, albeit with safety concerns. The main mitigation policy should be to use malloc/free with libuv handles only when the handles, are then associated with a resource or class-with-dtor. So we have a finite lifetime for the object and can gaurantee a free(), barring a runtime crash (in which case you have bigger problems!)
Diffstat (limited to 'src/rt/rust_uv.cpp')
| -rw-r--r-- | src/rt/rust_uv.cpp | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/src/rt/rust_uv.cpp b/src/rt/rust_uv.cpp index f3806aac6eb..c7720efe56a 100644 --- a/src/rt/rust_uv.cpp +++ b/src/rt/rust_uv.cpp @@ -450,3 +450,13 @@ rust_uv_get_kernel_global_chan_ptr() { LOG(task, stdlib,"global loop val: %lu", (unsigned long int)*result); return result; } + +extern "C" void* +rust_uv_current_kernel_malloc(size_t size) { + return current_kernel_malloc(size, "rust_uv_current_kernel_malloc"); +} + +extern "C" void* +rust_uv_current_kernel_free(void* mem) { + return current_kernel_free(mem); +} |
