Crates.io | crossdylib |
lib.rs | crossdylib |
version | 3.0.0 |
source | src |
created_at | 2021-11-28 15:12:18.642607 |
updated_at | 2021-12-04 17:18:18.732053 |
description | Cross-platform shared state across shared libraries/modules |
homepage | |
repository | https://github.com/WilliamVenner/crossdylib |
max_upload_size | |
id | 488854 |
size | 10,525 |
This library can be used to achieve shared state across shared libraries/modules.
Supported platforms
a.dll
#[macro_use] extern crate crossdylib;
crossdylib! {
static THE_ANSWER: std::sync::Mutex<u32> = std::sync::Mutex::new(39);
}
#[no_mangle]
pub unsafe extern "C" fn increment() {
THE_ANSWER.sync().unwrap();
let mut lock = THE_ANSWER.lock().unwrap();
*lock += 1;
assert_eq!(*lock, 40);
}
b.dll
#[macro_use] extern crate crossdylib;
crossdylib! {
static THE_ANSWER: std::sync::Mutex<u32> = std::sync::Mutex::new(39);
}
#[no_mangle]
pub unsafe extern "C" fn increment() {
THE_ANSWER.sync().unwrap();
let mut lock = THE_ANSWER.lock().unwrap();
*lock += 1;
assert_eq!(*lock, 41);
}
main.exe
fn main() {
let a = Library::new("a.dll").unwrap();
a.get::<extern "C" fn()>("increment").unwrap()();
let b = Library::new("b.dll").unwrap();
b.get::<extern "C" fn()>("increment").unwrap()();
println!("Success");
}