File tree Expand file tree Collapse file tree 1 file changed +11
-4
lines changed Expand file tree Collapse file tree 1 file changed +11
-4
lines changed Original file line number Diff line number Diff line change @@ -97,6 +97,15 @@ unsafe impl Sync for Task {}
97
97
type Pid = bindings:: pid_t ;
98
98
99
99
impl Task {
100
+ /// Returns a raw pointer to the current task.
101
+ ///
102
+ /// It is up to the user to use the pointer correctly.
103
+ #[ inline]
104
+ pub fn current_raw ( ) -> * mut bindings:: task_struct {
105
+ // SAFETY: Getting the current pointer is always safe.
106
+ unsafe { bindings:: get_current ( ) }
107
+ }
108
+
100
109
/// Returns a task reference for the currently executing task/thread.
101
110
///
102
111
/// The recommended way to get the current task/thread is to use the
@@ -119,14 +128,12 @@ impl Task {
119
128
}
120
129
}
121
130
122
- // SAFETY: Just an FFI call with no additional safety requirements.
123
- let ptr = unsafe { bindings:: get_current ( ) } ;
124
-
131
+ let current = Task :: current_raw ( ) ;
125
132
TaskRef {
126
133
// SAFETY: If the current thread is still running, the current task is valid. Given
127
134
// that `TaskRef` is not `Send`, we know it cannot be transferred to another thread
128
135
// (where it could potentially outlive the caller).
129
- task : unsafe { & * ptr . cast ( ) } ,
136
+ task : unsafe { & * current . cast ( ) } ,
130
137
_not_send : NotThreadSafe ,
131
138
}
132
139
}
You can’t perform that action at this time.
0 commit comments