Skip to main content

AlwaysRefCounted

Trait AlwaysRefCounted 

Source
pub unsafe trait AlwaysRefCounted {
    // Required methods
    fn inc_ref(&self);
    unsafe fn dec_ref(obj: NonNull<Self>);
}
Expand description

Types that are always reference counted.

It allows such types to define their own custom ref increment and decrement functions. Additionally, it allows users to convert from a shared reference &T to an owned reference ARef<T>.

This is usually implemented by wrappers to existing structures on the C side of the code. For Rust code, the recommendation is to use Arc to create reference-counted instances of a type.

§Safety

Implementers must ensure that increments to the reference count keep the object alive in memory at least until matching decrements are performed.

Implementers must also ensure that all instances are reference-counted. (Otherwise they won’t be able to honour the requirement that AlwaysRefCounted::inc_ref keep the object alive.)

Required Methods§

Source

fn inc_ref(&self)

Increments the reference count on the object.

Source

unsafe fn dec_ref(obj: NonNull<Self>)

Decrements the reference count on the object.

Frees the object when the count reaches zero.

§Safety

Callers must ensure that there was a previous matching increment to the reference count, and that the object is no longer used after its reference count is decremented (as it may result in the object being freed), unless the caller owns another increment on the refcount (e.g., it calls AlwaysRefCounted::inc_ref twice, then calls AlwaysRefCounted::dec_ref once).

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl AlwaysRefCounted for Credential

Source§

impl AlwaysRefCounted for kernel::auxiliary::Device

Source§

impl AlwaysRefCounted for kernel::device::Device

Source§

impl AlwaysRefCounted for kernel::pci::Device

Source§

impl AlwaysRefCounted for kernel::platform::Device

Source§

impl AlwaysRefCounted for kernel::serdev::Device

Source§

impl AlwaysRefCounted for Fence

Source§

impl AlwaysRefCounted for File

Source§

impl AlwaysRefCounted for FwNode

Source§

impl AlwaysRefCounted for I2cAdapter

Source§

impl AlwaysRefCounted for I2cClient

Source§

impl AlwaysRefCounted for Interface

Source§

impl AlwaysRefCounted for LocalFile

Source§

impl AlwaysRefCounted for Mm

Source§

impl AlwaysRefCounted for MmWithUser

Source§

impl AlwaysRefCounted for MmWithUserAsync

Source§

impl AlwaysRefCounted for OPP

SAFETY: The type invariants guarantee that OPP is always refcounted.

Source§

impl AlwaysRefCounted for PidNamespace

Source§

impl AlwaysRefCounted for Task

Source§

impl<T: Driver> AlwaysRefCounted for kernel::drm::device::Device<T>

Source§

impl<T: DriverGpuVm> AlwaysRefCounted for GpuVm<T>

Source§

impl<T: DriverGpuVm> AlwaysRefCounted for GpuVmBo<T>

Source§

impl<T: Operations> AlwaysRefCounted for kernel::fwctl::Device<T>

Source§

impl<T: Operations> AlwaysRefCounted for Request<T>

Source§

impl<T: PwmOps> AlwaysRefCounted for Chip<T>

Source§

impl<T> AlwaysRefCounted for kernel::drm::gem::shmem::Object<T>
where Self: IntoGEMObject, T: DriverObject,

Source§

impl<T> AlwaysRefCounted for kernel::drm::gem::Object<T>
where Self: IntoGEMObject, T: DriverObject,