Skip to content

Commit f7b260a

Browse files
authored
Merge pull request #806 from fbq/dev/wakeup
rust: task: Add wake_up() function
2 parents 07278d5 + 65abcef commit f7b260a

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

rust/kernel/task.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -180,13 +180,22 @@ impl Task {
180180

181181
// SAFETY: Since the kthread creation succeeded and we haven't run it yet, we know the task
182182
// is valid.
183-
let task = unsafe { &*(ktask as *const Task) }.into();
183+
let task: ARef<_> = unsafe { &*(ktask as *const Task) }.into();
184+
185+
// Wakes up the thread, otherwise it won't run.
186+
task.wake_up();
184187

185-
// SAFETY: Since the kthread creation succeeded, we know `ktask` is valid.
186-
unsafe { bindings::wake_up_process(ktask) };
187188
guard.dismiss();
188189
Ok(task)
189190
}
191+
192+
/// Wakes up the task.
193+
pub fn wake_up(&self) {
194+
// SAFETY: By the type invariant, we know that `self.0.get()` is non-null and valid.
195+
// And `wake_up_process` is safe to be called for any valid task, even if the task is
196+
// running.
197+
unsafe { bindings::wake_up_process(self.0.get()) };
198+
}
190199
}
191200

192201
// SAFETY: The type invariants guarantee that `Task` is always ref-counted.

0 commit comments

Comments
 (0)