1use std::ffi::c_void;
2
3extern "C" {
4 fn proxy_dyn_get_thread_context() -> *const c_void;
5 fn proxy_dyn_set_limited_thread_context(thread_context: *const c_void);
6}
7
8#[derive(Clone, Copy)]
9pub struct ThreadContext(*const c_void);
10
11unsafe impl Send for ThreadContext {}
12unsafe impl Sync for ThreadContext {}
13
14impl ThreadContext {
15 pub fn current() -> Option<Self> {
16 let raw = unsafe { proxy_dyn_get_thread_context() };
17 if raw.is_null() {
18 return None;
19 }
20 Some(Self(raw))
21 }
22
23 pub fn enter(self) {
24 unsafe { proxy_dyn_set_limited_thread_context(self.0) };
25 }
26}