workqueue.rs (3e0bc2855b573bcffa2a52955a878f537f5ac0cd) | workqueue.rs (b6cda913bba42e1fdad82df41d906ff603319743) |
---|---|
1// SPDX-License-Identifier: GPL-2.0 2 3//! Work queues. 4//! 5//! This file has two components: The raw work item API, and the safe work item API. 6//! 7//! One pattern that is used in both APIs is the `ID` const generic, which exists to allow a single 8//! type to define multiple `work_struct` fields. This is done by choosing an id for each field, --- 185 unchanged lines hidden (view full) --- 194 // closure. 195 // 196 // Furthermore, if the C workqueue code accesses the pointer after this call to 197 // `__enqueue`, then the work item was successfully enqueued, and `bindings::queue_work_on` 198 // will have returned true. In this case, `__enqueue` promises that the raw pointer will 199 // stay valid until we call the function pointer in the `work_struct`, so the access is ok. 200 unsafe { 201 w.__enqueue(move |work_ptr| { | 1// SPDX-License-Identifier: GPL-2.0 2 3//! Work queues. 4//! 5//! This file has two components: The raw work item API, and the safe work item API. 6//! 7//! One pattern that is used in both APIs is the `ID` const generic, which exists to allow a single 8//! type to define multiple `work_struct` fields. This is done by choosing an id for each field, --- 185 unchanged lines hidden (view full) --- 194 // closure. 195 // 196 // Furthermore, if the C workqueue code accesses the pointer after this call to 197 // `__enqueue`, then the work item was successfully enqueued, and `bindings::queue_work_on` 198 // will have returned true. In this case, `__enqueue` promises that the raw pointer will 199 // stay valid until we call the function pointer in the `work_struct`, so the access is ok. 200 unsafe { 201 w.__enqueue(move |work_ptr| { |
202 bindings::queue_work_on( 203 bindings::wq_misc_consts_WORK_CPU_UNBOUND as _, 204 queue_ptr, 205 work_ptr, 206 ) | 202 bindings::queue_work_on(bindings::WORK_CPU_UNBOUND as _, queue_ptr, work_ptr) |
207 }) 208 } 209 } 210 211 /// Tries to spawn the given function or closure as a work item. 212 /// 213 /// This method can fail because it allocates memory to store the work item. 214 pub fn try_spawn<T: 'static + Send + FnOnce()>(&self, func: T) -> Result<(), AllocError> { --- 37 unchanged lines hidden (view full) --- 252/// This is the low-level trait that is designed for being as general as possible. 253/// 254/// The `ID` parameter to this trait exists so that a single type can provide multiple 255/// implementations of this trait. For example, if a struct has multiple `work_struct` fields, then 256/// you will implement this trait once for each field, using a different id for each field. The 257/// actual value of the id is not important as long as you use different ids for different fields 258/// of the same struct. (Fields of different structs need not use different ids.) 259/// | 203 }) 204 } 205 } 206 207 /// Tries to spawn the given function or closure as a work item. 208 /// 209 /// This method can fail because it allocates memory to store the work item. 210 pub fn try_spawn<T: 'static + Send + FnOnce()>(&self, func: T) -> Result<(), AllocError> { --- 37 unchanged lines hidden (view full) --- 248/// This is the low-level trait that is designed for being as general as possible. 249/// 250/// The `ID` parameter to this trait exists so that a single type can provide multiple 251/// implementations of this trait. For example, if a struct has multiple `work_struct` fields, then 252/// you will implement this trait once for each field, using a different id for each field. The 253/// actual value of the id is not important as long as you use different ids for different fields 254/// of the same struct. (Fields of different structs need not use different ids.) 255/// |
260/// Note that the id is used only to select the right method to call during compilation. It wont be | 256/// Note that the id is used only to select the right method to call during compilation. It won't be |
261/// part of the final executable. 262/// 263/// # Safety 264/// 265/// Implementers must ensure that any pointers passed to a `queue_work_on` closure by `__enqueue` 266/// remain valid for the duration specified in the guarantees section of the documentation for 267/// `__enqueue`. 268pub unsafe trait RawWorkItem<const ID: u64> { --- 415 unchanged lines hidden --- | 257/// part of the final executable. 258/// 259/// # Safety 260/// 261/// Implementers must ensure that any pointers passed to a `queue_work_on` closure by `__enqueue` 262/// remain valid for the duration specified in the guarantees section of the documentation for 263/// `__enqueue`. 264pub unsafe trait RawWorkItem<const ID: u64> { --- 415 unchanged lines hidden --- |