Skip to content

Commit 99582f8

Browse files
committed
std: Hardcode pthread constants and structures
This allows for easier static initialization of a pthread mutex, although the windows mutexes still sadly suffer. Note that this commit removes the clone() method from a mutex because it no longer makes sense for pthreads mutexes. This also removes the Once type for now, but it'll get added back shortly.
1 parent 24631c8 commit 99582f8

File tree

3 files changed

+228
-335
lines changed

3 files changed

+228
-335
lines changed

src/libgreen/sched.rs

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1416,7 +1416,8 @@ mod test {
14161416

14171417
#[test]
14181418
fn test_spawn_sched_blocking() {
1419-
use std::unstable::mutex::Mutex;
1419+
use std::unstable::mutex::{Mutex, MUTEX_INIT};
1420+
static mut LOCK: Mutex = MUTEX_INIT;
14201421

14211422
// Testing that a task in one scheduler can block in foreign code
14221423
// without affecting other schedulers
@@ -1425,19 +1426,15 @@ mod test {
14251426
let (start_po, start_ch) = Chan::new();
14261427
let (fin_po, fin_ch) = Chan::new();
14271428

1428-
let lock = unsafe { Mutex::new() };
1429-
let lock2 = unsafe { lock.clone() };
1430-
14311429
let mut handle = pool.spawn_sched();
14321430
handle.send(PinnedTask(pool.task(TaskOpts::new(), proc() {
1433-
let mut lock = lock2;
14341431
unsafe {
1435-
lock.lock();
1432+
LOCK.lock();
14361433

14371434
start_ch.send(());
1438-
lock.wait(); // block the scheduler thread
1439-
lock.signal(); // let them know we have the lock
1440-
lock.unlock();
1435+
LOCK.wait(); // block the scheduler thread
1436+
LOCK.signal(); // let them know we have the lock
1437+
LOCK.unlock();
14411438
}
14421439

14431440
fin_ch.send(());
@@ -1469,12 +1466,11 @@ mod test {
14691466
child_ch.send(20);
14701467
pingpong(&parent_po, &child_ch);
14711468
unsafe {
1472-
let mut lock = lock;
1473-
lock.lock();
1474-
lock.signal(); // wakeup waiting scheduler
1475-
lock.wait(); // wait for them to grab the lock
1476-
lock.unlock();
1477-
lock.destroy(); // now we're guaranteed they have no locks
1469+
LOCK.lock();
1470+
LOCK.signal(); // wakeup waiting scheduler
1471+
LOCK.wait(); // wait for them to grab the lock
1472+
LOCK.unlock();
1473+
LOCK.destroy(); // now we're guaranteed they have no locks
14781474
}
14791475
})));
14801476
drop(handle);

0 commit comments

Comments
 (0)