Add dc_event_emitter_close() API

dc_event_emitter_close() can be used to terminate
event loop from another thread without dereferencing the
context which may be in use by the event loop at the same time.
This commit is contained in:
link2xt
2022-05-03 18:14:22 +00:00
parent 95a54a43ff
commit eb3242e077
4 changed files with 31 additions and 2 deletions

View File

@@ -640,6 +640,18 @@ pub unsafe extern "C" fn dc_event_emitter_unref(emitter: *mut dc_event_emitter_t
Box::from_raw(emitter);
}
#[no_mangle]
pub unsafe extern "C" fn dc_event_emitter_close(emitter: *mut dc_event_emitter_t) {
if emitter.is_null() {
eprintln!("ignoring careless call to dc_event_emitter_close()");
return;
}
let emitter = &mut *emitter;
block_on(emitter.close())
}
#[no_mangle]
pub unsafe extern "C" fn dc_get_next_event(events: *mut dc_event_emitter_t) -> *mut dc_event_t {
if events.is_null() {