@@ -126,6 +126,27 @@ macro_rules! thread_try_new {
126
126
} } ;
127
127
}
128
128
129
+ /*
130
+ pub trait ThreadArg<A: Send> {
131
+ fn from_raw(ptr: *mut c_types::c_void) -> A;
132
+ fn into_raw(arg: A) -> *mut c_types::c_void;
133
+ }
134
+ pub trait ThreadFunc<A: Send> {
135
+ fn func(arg: A) -> KernelResult<()>;
136
+ }
137
+
138
+ extern "C" fn bridge<A, T: ThreadFunc<A>>(data: *mut c_types::c_void) -> i32
139
+ where A : Send
140
+ {
141
+ let arg = unsafe { core::intrinsics::transmute(data) };
142
+
143
+ match T::func(arg) {
144
+ Ok(_) => 0,
145
+ Err(e) => e.to_kernel_errno(),
146
+ }
147
+ }
148
+ */
149
+
129
150
/// Function passed to `kthread_create_on_node` as the thread function pointer.
130
151
#[ no_mangle]
131
152
unsafe extern "C" fn rust_thread_func ( data : * mut c_types:: c_void ) -> c_types:: c_int {
@@ -200,6 +221,33 @@ impl Thread {
200
221
Ok ( Thread { task } )
201
222
}
202
223
224
+ /*
225
+ pub fn try_new_thread_func<A, T: ThreadFunc<A>>(name: CStr, arg: A) -> KernelResult<Self>
226
+ where A: Send
227
+ {
228
+ let data = unsafe { core::intrinsics::transmute(arg) };
229
+
230
+ let result = unsafe { Self::try_new_c_style(name, bridge::<A,T>, data) };
231
+
232
+ if let Err(e) = result {
233
+ // Creation fails, we need to `transmute` back the `arg` because
234
+ // there is no new thread to own it, we should let the current
235
+ // thread own it.
236
+ //
237
+ // SAFETY: We `transmute` back waht we just `transmute`, and since
238
+ // the new thread is not created, so no one touches `data`.
239
+ unsafe {
240
+ core::intrinsics::transmute::<_, A>(data);
241
+ }
242
+
243
+ Err(e)
244
+ } else {
245
+ result
246
+ }
247
+
248
+ }
249
+ */
250
+
203
251
/// Creates a new thread.
204
252
///
205
253
/// # Examples
0 commit comments