diff options
author | Clark Gaebel <cgaebel@mozilla.com> | 2014-09-17 15:36:50 -0700 |
---|---|---|
committer | Clark Gaebel <cgaebel@mozilla.com> | 2014-09-18 09:20:23 -0700 |
commit | 670ca9894e1ea433d9d487e39005601f12f435aa (patch) | |
tree | bdd22f8ae268323a59cfa97377852cc538a6043e /components/util | |
parent | 1b251db7323dce3b7838709c7d2dfb685d8b24a9 (diff) | |
download | servo-670ca9894e1ea433d9d487e39005601f12f435aa.tar.gz servo-670ca9894e1ea433d9d487e39005601f12f435aa.zip |
Fixed #3386.
Diffstat (limited to 'components/util')
-rw-r--r-- | components/util/lib.rs | 1 | ||||
-rw-r--r-- | components/util/namespace.rs | 2 | ||||
-rw-r--r-- | components/util/tid.rs | 18 |
3 files changed, 20 insertions, 1 deletions
diff --git a/components/util/lib.rs b/components/util/lib.rs index 9e6bddb9fab..a62c35ee576 100644 --- a/components/util/lib.rs +++ b/components/util/lib.rs @@ -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; diff --git a/components/util/namespace.rs b/components/util/namespace.rs index 8824accae00..b33012a9ef1 100644 --- a/components/util/namespace.rs +++ b/components/util/namespace.rs @@ -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, diff --git a/components/util/tid.rs b/components/util/tid.rs new file mode 100644 index 00000000000..fdd9a775bcd --- /dev/null +++ b/components/util/tid.rs @@ -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 +} |