Skip to content
This repository has been archived by the owner on Dec 9, 2018. It is now read-only.

Commit

Permalink
Mark thread stuff as unimplemented!() on unsupported platforms
Browse files Browse the repository at this point in the history
  • Loading branch information
tbu- committed Apr 15, 2017
1 parent 7760a04 commit 3cfc3cc
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/libc/internal/mips.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pub unsafe fn set_thread_pointer(thread_data: *mut ()) {
let _ = thread_data; // TODO(steed, #127): Set thread-local pointer.
}
3 changes: 3 additions & 0 deletions src/libc/internal/mips64.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pub unsafe fn set_thread_pointer(thread_data: *mut ()) {
let _ = thread_data; // TODO(steed, #127): Set thread-local pointer.
}
3 changes: 3 additions & 0 deletions src/libc/internal/powerpc64.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pub unsafe fn set_thread_pointer(thread_data: *mut ()) {
let _ = thread_data; // TODO(steed, #127): Set thread-local pointer.
}
3 changes: 3 additions & 0 deletions src/libc/internal/sparc64.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pub unsafe fn set_thread_pointer(thread_data: *mut ()) {
let _ = thread_data; // TODO(steed, #127): Set thread-local pointer.
}
69 changes: 69 additions & 0 deletions src/libc/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
#![allow(non_camel_case_types)]

#![cfg_attr(not(any(target_arch = "aarch64",
target_arch = "arm",
target_arch = "powerpc",
target_arch = "x86",
target_arch = "x86_64")),
allow(unused))]

use cmp;
use linux;
use mem;
Expand Down Expand Up @@ -183,6 +190,36 @@ pub unsafe fn pthread_getattr_np(pthread: pthread_t,
}
*/

#[cfg(not(any(target_arch = "aarch64",
target_arch = "arm",
target_arch = "powerpc",
target_arch = "x86",
target_arch = "x86_64")))]
pub unsafe fn pthread_create(pthread: *mut pthread_t,
attr: *const pthread_attr_t,
start_routine: extern "C" fn(*mut c_void) -> *mut c_void,
arg: *mut c_void)
-> c_int
{
if false {
let flags = CLONE_VM | CLONE_FS | CLONE_FILES | CLONE_SIGHAND
| CLONE_THREAD | CLONE_SYSVSEM | CLONE_SETTLS
| CLONE_CHILD_CLEARTID | CLONE_PARENT_SETTID;
mmap(ptr::null_mut(), 0, PROT_READ | PROT_WRITE, MAP_PRIVATE |
MAP_ANON, -1, 0);
}
unimplemented!();
}
// Heavily simplified (i.e. less features) version of pthread_create.
// musl: src/thread/pthread_create.c
//
// Doesn't care about signals, thread-local storage and perhaps other things
// yet.
#[cfg(any(target_arch = "aarch64",
target_arch = "arm",
target_arch = "powerpc",
target_arch = "x86",
target_arch = "x86_64"))]
pub unsafe fn pthread_create(pthread: *mut pthread_t,
attr: *const pthread_attr_t,
start_routine: extern "C" fn(*mut c_void) -> *mut c_void,
Expand Down Expand Up @@ -232,6 +269,11 @@ pub unsafe fn pthread_create(pthread: *mut pthread_t,
0
}

#[cfg(any(target_arch = "aarch64",
target_arch = "arm",
target_arch = "powerpc",
target_arch = "x86",
target_arch = "x86_64"))]
extern {
// Defined in internal/<arch>.rs.
//
Expand Down Expand Up @@ -280,13 +322,40 @@ pub unsafe fn pthread_detach(thread: pthread_t) -> c_int {
}
*/

#[cfg(not(any(target_arch = "aarch64",
target_arch = "arm",
target_arch = "powerpc",
target_arch = "x86",
target_arch = "x86_64")))]
pub unsafe fn pthread_join(pthread: pthread_t, retval: *mut *mut c_void)
-> c_int
{
if false {
let thread = pthread.thread;
linux::futex(&mut (*thread).thread_id as *mut _ as *mut u32,
linux::FUTEX_WAIT,
(*thread).thread_id as u32,
ptr::null(),
ptr::null_mut(),
0);
}
unimplemented!();
}

#[cfg(any(target_arch = "aarch64",
target_arch = "arm",
target_arch = "powerpc",
target_arch = "x86",
target_arch = "x86_64"))]
pub unsafe fn pthread_join(pthread: pthread_t, retval: *mut *mut c_void)
-> c_int
{
assert!(retval.is_null());
let thread = pthread.thread;

let tmp = (*thread).thread_id;
// 0 would mean that the thread has exited already (CLONE_CHILD_CLEARTID
// flag on the clone syscall).
if tmp == 0 {
return 0;
}
Expand Down

0 comments on commit 3cfc3cc

Please sign in to comment.