diff options
| author | Brian Anderson <banderson@mozilla.com> | 2013-05-28 18:39:52 -0700 |
|---|---|---|
| committer | Brian Anderson <banderson@mozilla.com> | 2013-05-28 18:39:52 -0700 |
| commit | dec9db10da062b1c528d46426d9f62e201d39bc6 (patch) | |
| tree | ad31d2bd44728b70b6c450151fac1e79fb167743 /src | |
| parent | 3f8095e55043f35e08adba5fe5b0a2d687ebc514 (diff) | |
| download | rust-dec9db10da062b1c528d46426d9f62e201d39bc6.tar.gz rust-dec9db10da062b1c528d46426d9f62e201d39bc6.zip | |
core::rt: Add SleeperList
Just a simple place to stuff handles to sleeping schedulers.
Diffstat (limited to 'src')
| -rw-r--r-- | src/libcore/rt/mod.rs | 3 | ||||
| -rw-r--r-- | src/libcore/rt/sleeper_list.rs | 46 |
2 files changed, 49 insertions, 0 deletions
diff --git a/src/libcore/rt/mod.rs b/src/libcore/rt/mod.rs index f136732c00b..82496ec5589 100644 --- a/src/libcore/rt/mod.rs +++ b/src/libcore/rt/mod.rs @@ -88,6 +88,9 @@ mod work_queue; /// A parallel queue. mod message_queue; +/// A parallel data structure for tracking sleeping schedulers. +mod sleeper_list; + /// Stack segments and caching. mod stack; diff --git a/src/libcore/rt/sleeper_list.rs b/src/libcore/rt/sleeper_list.rs new file mode 100644 index 00000000000..9507dec001d --- /dev/null +++ b/src/libcore/rt/sleeper_list.rs @@ -0,0 +1,46 @@ +// Copyright 2013 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +//! Maintains a shared list of sleeping schedulers. Schedulers +//! use this to wake each other up. + +use container::Container; +use vec::OwnedVector; +use option::{Option, Some, None}; +use cell::Cell; +use unstable::sync::{Exclusive, exclusive}; +use rt::sched::{Scheduler, SchedHandle}; + +pub struct SleeperList { + priv stack: ~Exclusive<~[SchedHandle]> +} + +impl SleeperList { + pub fn new() -> SleeperList { + SleeperList { + stack: ~exclusive(~[]) + } + } + + pub fn push(&mut self, handle: SchedHandle) { + let handle = Cell(handle); + self.stack.with(|s| s.push(handle.take())); + } + + pub fn pop(&mut self) -> Option<SchedHandle> { + do self.stack.with |s| { + if !s.is_empty() { + Some(s.pop()) + } else { + None + } + } + } +} |
