aboutsummaryrefslogtreecommitdiffstats
path: root/components/util
diff options
context:
space:
mode:
Diffstat (limited to 'components/util')
-rw-r--r--components/util/lib.rs1
-rw-r--r--components/util/namespace.rs2
-rw-r--r--components/util/tid.rs18
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
+}