Skip to main content

gstreamer_vulkan/
vulkan_command_pool.rs

1use crate::VulkanCommandPool;
2use crate::ffi;
3
4use glib::{prelude::*, translate::*};
5
6// rustdoc-stripper-ignore-next
7/// Represents a locked VulkanCommandPool. The command pool is unlocked when this struct is dropped.
8#[derive(Debug)]
9pub struct VulkanCommandPoolGuard<'a> {
10    obj: &'a VulkanCommandPool,
11}
12
13impl Drop for VulkanCommandPoolGuard<'_> {
14    fn drop(&mut self) {
15        unsafe {
16            ffi::gst_vulkan_command_pool_unlock(self.obj.to_glib_none().0);
17        }
18    }
19}
20impl PartialEq for VulkanCommandPoolGuard<'_> {
21    fn eq(&self, other: &Self) -> bool {
22        self.obj == other.obj
23    }
24}
25impl Eq for VulkanCommandPoolGuard<'_> {}
26
27pub trait VulkanCommandPoolExtManual: IsA<VulkanCommandPool> + 'static {
28    // rustdoc-stripper-ignore-next
29    /// Locks the command pool. A struct similar to `MutexGuard` is retured that unlocks the command pool once dropped.
30    // rustdoc-stripper-ignore-next-stop
31    /// This should be called to ensure no other thread will attempt to access
32    /// the pool's internal resources. Any modification of any of the allocated
33    /// [`VulkanCommandBuffer`][crate::VulkanCommandBuffer]'s need to be encapsulated in a
34    /// [`lock()`][Self::lock()]/[`unlock()`][Self::unlock()] pair to meet
35    /// the Vulkan API requirements that host access to the command pool is
36    /// externally synchronised.
37    #[doc(alias = "gst_vulkan_command_pool_lock")]
38    fn lock<'a>(&'a self) -> VulkanCommandPoolGuard<'a> {
39        unsafe {
40            ffi::gst_vulkan_command_pool_lock(self.as_ref().to_glib_none().0);
41        }
42        VulkanCommandPoolGuard {
43            obj: self.upcast_ref(),
44        }
45    }
46}
47impl<O: IsA<VulkanCommandPool>> VulkanCommandPoolExtManual for O {}