Trait kernel::workqueue::HasWork

source ·
pub unsafe trait HasWork<T, const ID: u64 = 0> {
    const OFFSET: usize;

    // Provided methods
    fn get_work_offset(&self) -> usize { ... }
    unsafe fn raw_get_work(ptr: *mut Self) -> *mut Work<T, ID> { ... }
    unsafe fn work_container_of(ptr: *mut Work<T, ID>) -> *mut Self
       where Self: Sized { ... }
}
Expand description

Declares that a type has a Work<T, ID> field.

The intended way of using this trait is via the impl_has_work! macro. You can use the macro like this:

use kernel::impl_has_work;
use kernel::prelude::*;
use kernel::workqueue::Work;

struct MyWorkItem {
    work_field: Work<MyWorkItem, 1>,
}

impl_has_work! {
    impl HasWork<MyWorkItem, 1> for MyWorkItem { self.work_field }
}

Note that since the Work type is annotated with an id, you can have several work_struct fields by using a different id for each one.

Safety

The OFFSET constant must be the offset of a field in Self of type Work<T, ID>. The methods on this trait must have exactly the behavior that the definitions given below have.

Required Associated Constants§

source

const OFFSET: usize

The offset of the Work<T, ID> field.

Provided Methods§

source

fn get_work_offset(&self) -> usize

Returns the offset of the Work<T, ID> field.

This method exists because the OFFSET constant cannot be accessed if the type is not Sized.

source

unsafe fn raw_get_work(ptr: *mut Self) -> *mut Work<T, ID>

Returns a pointer to the Work<T, ID> field.

Safety

The provided pointer must point at a valid struct of type Self.

source

unsafe fn work_container_of(ptr: *mut Work<T, ID>) -> *mut Selfwhere Self: Sized,

Returns a pointer to the struct containing the Work<T, ID> field.

Safety

The pointer must point at a Work<T, ID> field in a struct of type Self.

Implementors§