gstreamer/auto/
task_pool.rs

1// This file was generated by gir (https://github.com/gtk-rs/gir)
2// from gir-files (https://github.com/gtk-rs/gir-files)
3// from gst-gir-files (https://gitlab.freedesktop.org/gstreamer/gir-files-rs.git)
4// DO NOT EDIT
5
6use crate::{ffi, Object};
7use glib::{prelude::*, translate::*};
8
9glib::wrapper! {
10    /// This object provides an abstraction for creating threads. The default
11    /// implementation uses a regular GThreadPool to start tasks.
12    ///
13    /// Subclasses can be made to create custom threads.
14    ///
15    /// # Implements
16    ///
17    /// [`TaskPoolExt`][trait@crate::prelude::TaskPoolExt], [`GstObjectExt`][trait@crate::prelude::GstObjectExt], [`trait@glib::ObjectExt`], [`TaskPoolExtManual`][trait@crate::prelude::TaskPoolExtManual]
18    #[doc(alias = "GstTaskPool")]
19    pub struct TaskPool(Object<ffi::GstTaskPool, ffi::GstTaskPoolClass>) @extends Object;
20
21    match fn {
22        type_ => || ffi::gst_task_pool_get_type(),
23    }
24}
25
26impl TaskPool {
27    pub const NONE: Option<&'static TaskPool> = None;
28
29    /// Create a new default task pool. The default task pool will use a regular
30    /// GThreadPool for threads.
31    ///
32    /// # Returns
33    ///
34    /// a new [`TaskPool`][crate::TaskPool]. `gst_object_unref()` after usage.
35    #[doc(alias = "gst_task_pool_new")]
36    pub fn new() -> TaskPool {
37        assert_initialized_main_thread!();
38        unsafe { from_glib_full(ffi::gst_task_pool_new()) }
39    }
40}
41
42impl Default for TaskPool {
43    fn default() -> Self {
44        Self::new()
45    }
46}
47
48unsafe impl Send for TaskPool {}
49unsafe impl Sync for TaskPool {}
50
51/// Trait containing all [`struct@TaskPool`] methods.
52///
53/// # Implementors
54///
55/// [`TaskPool`][struct@crate::TaskPool]
56pub trait TaskPoolExt: IsA<TaskPool> + 'static {
57    /// Wait for all tasks to be stopped. This is mainly used internally
58    /// to ensure proper cleanup of internal data structures in test suites.
59    ///
60    /// MT safe.
61    #[doc(alias = "gst_task_pool_cleanup")]
62    fn cleanup(&self) {
63        unsafe {
64            ffi::gst_task_pool_cleanup(self.as_ref().to_glib_none().0);
65        }
66    }
67
68    /// Prepare the taskpool for accepting [`TaskPoolExtManual::push()`][crate::prelude::TaskPoolExtManual::push()] operations.
69    ///
70    /// MT safe.
71    #[doc(alias = "gst_task_pool_prepare")]
72    fn prepare(&self) -> Result<(), glib::Error> {
73        unsafe {
74            let mut error = std::ptr::null_mut();
75            let _ = ffi::gst_task_pool_prepare(self.as_ref().to_glib_none().0, &mut error);
76            if error.is_null() {
77                Ok(())
78            } else {
79                Err(from_glib_full(error))
80            }
81        }
82    }
83}
84
85impl<O: IsA<TaskPool>> TaskPoolExt for O {}