Adds FFI function to release a handle
	
		
			
	
		
	
	
		
	
		
			All checks were successful
		
		
	
	
		
			
				
	
				continuous-integration/drone/push Build is passing
				
			
		
		
	
	
				
					
				
			
		
			All checks were successful
		
		
	
	continuous-integration/drone/push Build is passing
				
			This commit is contained in:
		| @@ -9,6 +9,20 @@ use std::hash::Hash; | ||||
| use std::sync::atomic::AtomicUsize; | ||||
| use std::sync::{Arc, LazyLock}; | ||||
|  | ||||
| /// This function can be called from the FFI to release a handle when it is no longer needed. This | ||||
| /// does not drop the object per se, but will reduce the reference count of the object. If the object | ||||
| /// is then no longer referenced, it will be dropped. | ||||
| #[no_mangle] | ||||
| extern "C" fn ffi_release_handle(handle: usize) { | ||||
|     let mut write_lock = FFI_OBJECTS.write(); | ||||
|     let mut write_lock_inverse = FFI_OBJECTS_INVERSE.write(); | ||||
|  | ||||
|     let obj = write_lock.remove(&handle); | ||||
|     if let Some(obj) = obj { | ||||
|         write_lock_inverse.remove(&obj); | ||||
|     } | ||||
| } | ||||
|  | ||||
| /// A handle of an object that can be passed over FFI. We use this to avoid passing pointers over the | ||||
| /// FFI boundary. This allows us to be able to move the data around in memory without having to worry | ||||
| /// about the pointers being invalidated. It also allows us to have a type-safe interface. | ||||
|   | ||||
		Reference in New Issue
	
	Block a user