diff options
Diffstat (limited to 'components/util/tid.rs')
-rw-r--r-- | components/util/tid.rs | 18 |
1 files changed, 18 insertions, 0 deletions
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 +} |