diff options
author | Aapo Alasuutari <aapo.alasuutari@gmail.com> | 2022-06-28 12:23:36 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-06-28 14:53:36 +0530 |
commit | 00f4521b205bf25c79f0fa7c9a6840941342bda4 (patch) | |
tree | b988db360143384ae216022846b518ceb262c80a /test_ffi/src/lib.rs | |
parent | e1c90963fbbf6571ae1b66971b83159681928ec3 (diff) |
feat(ext/ffi): Thread safe callbacks (#14942)
Diffstat (limited to 'test_ffi/src/lib.rs')
-rw-r--r-- | test_ffi/src/lib.rs | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/test_ffi/src/lib.rs b/test_ffi/src/lib.rs index b4908d9cd..d6f29cbb8 100644 --- a/test_ffi/src/lib.rs +++ b/test_ffi/src/lib.rs @@ -211,6 +211,19 @@ pub extern "C" fn call_stored_function_2(arg: u8) { } } +#[no_mangle] +pub extern "C" fn call_stored_function_thread_safe() { + std::thread::spawn(move || { + std::thread::sleep(std::time::Duration::from_millis(1500)); + unsafe { + if STORED_FUNCTION.is_none() { + return; + } + STORED_FUNCTION.unwrap()(); + } + }); +} + // FFI performance helper functions #[no_mangle] pub extern "C" fn nop() {} |