Fix thread starting before pte_osThreadStart

This commit is contained in:
Jeremy Soller
2019-03-30 16:18:07 -06:00
parent 3f98962054
commit 17372b4f69
+22 -18
View File
@@ -63,27 +63,31 @@ pub unsafe extern "C" fn pte_osThreadCreate(
ppte_osThreadHandle: *mut pte_osThreadHandle,
) -> pte_osResult {
// XXX error handling
let id = Sys::pte_clone();
if id < 0 {
return PTE_OS_GENERAL_FAILURE;
}
let mutex = Box::into_raw(Box::new(0));
if id == 0 {
// Wait until pte_osThreadStart
pte_osMutexLock(mutex);
entryPoint(argv);
pte_osThreadExit();
} else {
pte_osMutexLock(&mut pid_mutexes_lock);
if pid_mutexes.is_none() {
pid_mutexes = Some(BTreeMap::new());
// Create a locked mutex, unlocked by pte_osThreadStart
let mutex = Box::into_raw(Box::new(2));
{
let id = Sys::pte_clone();
if id < 0 {
return PTE_OS_GENERAL_FAILURE;
}
if id == 0 {
// Wait until pte_osThreadStart
pte_osMutexLock(mutex);
entryPoint(argv);
pte_osThreadExit();
} else {
pte_osMutexLock(&mut pid_mutexes_lock);
if pid_mutexes.is_none() {
pid_mutexes = Some(BTreeMap::new());
}
pid_mutexes.as_mut().unwrap().insert(id, mutex);
pte_osMutexUnlock(&mut pid_mutexes_lock);
*ppte_osThreadHandle = id;
}
pid_mutexes.as_mut().unwrap().insert(id, mutex);
pte_osMutexUnlock(&mut pid_mutexes_lock);
*ppte_osThreadHandle = id;
}
PTE_OS_OK
}