Module kernel::sync[][src]

Expand description

Synchronisation primitives.

This module contains the kernel APIs related to synchronisation that have been ported or wrapped for usage by Rust code in the kernel and is shared by all of them.


// SAFETY: `init` is called below.
let mut data = Pin::from(Box::new(unsafe { Mutex::new(0) }));
mutex_init!(data.as_mut(), "test::data");
*data.lock() = 10;
pr_info!("{}\n", *data.lock());



Exposes the kernel’s struct wait_queue_head as a condition variable. It allows the caller to atomically release the given lock and go to sleep. It reacquires the lock when it wakes up. And it wakes up when notified by another thread (via CondVar::notify_one or CondVar::notify_all) or because the thread received a signal.


Allows mutual exclusion primitives that implement the Lock trait to automatically unlock when a guard goes out of scope. It also provides a safe and convenient way to access the data protected by the lock.


Allows access to some data to be serialised by a lock that does not wrap it.


Exposes the kernel’s struct mutex. When multiple threads attempt to lock the same mutex, only one at a time is allowed to progress, the others will block (sleep) until the mutex is unlocked, at which point another thread will be allowed to wake up and make progress.


A reference-counted pointer to an instance of T.


A borrowed Ref with manually-managed lifetime.


Exposes the kernel’s spinlock_t. When multiple CPUs attempt to lock the same spinlock, only one at a time is allowed to progress, the others will block (spinning) until the spinlock is unlocked, at which point another CPU will be allowed to make progress.



A generic mutual exclusion primitive.


A trait for types that need a lock class during initialisation.



Reschedules the caller’s task if needed.