diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 14:29:10 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 14:29:10 +0000 |
commit | 2aa4a82499d4becd2284cdb482213d541b8804dd (patch) | |
tree | b80bf8bf13c3766139fbacc530efd0dd9d54394c /third_party/rust/pulse/src/threaded_mainloop.rs | |
parent | Initial commit. (diff) | |
download | firefox-2aa4a82499d4becd2284cdb482213d541b8804dd.tar.xz firefox-2aa4a82499d4becd2284cdb482213d541b8804dd.zip |
Adding upstream version 86.0.1.upstream/86.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'third_party/rust/pulse/src/threaded_mainloop.rs')
-rw-r--r-- | third_party/rust/pulse/src/threaded_mainloop.rs | 92 |
1 files changed, 92 insertions, 0 deletions
diff --git a/third_party/rust/pulse/src/threaded_mainloop.rs b/third_party/rust/pulse/src/threaded_mainloop.rs new file mode 100644 index 0000000000..865aaac76b --- /dev/null +++ b/third_party/rust/pulse/src/threaded_mainloop.rs @@ -0,0 +1,92 @@ +// Copyright © 2017 Mozilla Foundation +// +// This program is made available under an ISC-style license. See the +// accompanying file LICENSE for details. + +use ErrorCode; +use Result; +use ffi; +use mainloop_api; +use mainloop_api::MainloopApi; + +#[derive(Debug)] +pub struct ThreadedMainloop(*mut ffi::pa_threaded_mainloop); + +impl ThreadedMainloop { + pub unsafe fn from_raw_ptr(raw: *mut ffi::pa_threaded_mainloop) -> Self { + ThreadedMainloop(raw) + } + + pub fn new() -> Self { + unsafe { ThreadedMainloop::from_raw_ptr(ffi::pa_threaded_mainloop_new()) } + } + + pub fn raw_mut(&self) -> &mut ffi::pa_threaded_mainloop { + unsafe { &mut *self.0 } + } + + pub fn is_null(&self) -> bool { + self.0.is_null() + } + + pub fn start(&self) -> Result<()> { + match unsafe { ffi::pa_threaded_mainloop_start(self.raw_mut()) } { + 0 => Ok(()), + _ => Err(ErrorCode::from_error_code(ffi::PA_ERR_UNKNOWN)), + } + } + + pub fn stop(&self) { + unsafe { + ffi::pa_threaded_mainloop_stop(self.raw_mut()); + } + } + + pub fn lock(&self) { + unsafe { + ffi::pa_threaded_mainloop_lock(self.raw_mut()); + } + } + + pub fn unlock(&self) { + unsafe { + ffi::pa_threaded_mainloop_unlock(self.raw_mut()); + } + } + + pub fn wait(&self) { + unsafe { + ffi::pa_threaded_mainloop_wait(self.raw_mut()); + } + } + + pub fn signal(&self) { + unsafe { + ffi::pa_threaded_mainloop_signal(self.raw_mut(), 0); + } + } + + pub fn get_api(&self) -> MainloopApi { + unsafe { mainloop_api::from_raw_ptr(ffi::pa_threaded_mainloop_get_api(self.raw_mut())) } + } + + pub fn in_thread(&self) -> bool { + unsafe { ffi::pa_threaded_mainloop_in_thread(self.raw_mut()) != 0 } + } +} + +impl ::std::default::Default for ThreadedMainloop { + fn default() -> Self { + ThreadedMainloop(::std::ptr::null_mut()) + } +} + +impl ::std::ops::Drop for ThreadedMainloop { + fn drop(&mut self) { + if !self.is_null() { + unsafe { + ffi::pa_threaded_mainloop_free(self.raw_mut()); + } + } + } +} |