This commit is contained in:
Clark Gaebel 2014-09-17 15:36:50 -07:00
parent 1b251db732
commit 670ca9894e
7 changed files with 59 additions and 8 deletions

View file

@ -44,6 +44,7 @@ pub mod smallvec;
pub mod sort;
pub mod str;
pub mod task;
pub mod tid;
pub mod time;
pub mod vec;
pub mod workqueue;

View file

@ -2,7 +2,7 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#[deriving(Eq, PartialEq, Clone, Encodable, Hash)]
#[deriving(Eq, PartialEq, Clone, Encodable, Hash, Show)]
pub enum Namespace {
Null,
HTML,

18
components/util/tid.rs Normal file
View file

@ -0,0 +1,18 @@
use std::sync::atomics::{AtomicUint, INIT_ATOMIC_UINT, SeqCst};
static mut next_tid: AtomicUint = INIT_ATOMIC_UINT;
local_data_key!(task_local_tid: uint)
/// Every task gets one, that's unique.
pub fn tid() -> uint {
let ret =
match task_local_tid.replace(None) {
None => unsafe { next_tid.fetch_add(1, SeqCst) },
Some(x) => x,
};
task_local_tid.replace(Some(ret));
ret
}