1use glib_sys;
3use janus_plugin_sys as ffi;
4use std::ffi::CString;
5pub use ffi::janus_refcount as ReferenceCount;
6
7pub fn increase(refcount: &ReferenceCount) {
9 let field = &refcount.count;
10 unsafe {
11 if ffi::refcount_debug == 1 {
12 let msg = CString::new(format!("[rust:increase] {:p} ({:?})\n", refcount, field + 1)).unwrap();
13 ffi::janus_vprintf(msg.as_ptr());
14 }
15 glib_sys::g_atomic_int_inc(field as *const _ as *mut _);
16 }
17}
18
19pub fn decrease(refcount: &ReferenceCount) {
21 let field = &refcount.count;
22 unsafe {
23 if ffi::refcount_debug == 1 {
24 let msg = CString::new(format!("[rust:decrease] {:p} ({:?})\n", refcount, field - 1)).unwrap();
25 ffi::janus_vprintf(msg.as_ptr());
26 }
27 if glib_sys::g_atomic_int_dec_and_test(field as *const _ as *mut _) == 1 {
28 (refcount.free)(refcount);
29 }
30 }
31}