Files
tubestation/servo/components/util/tid.rs
Clark Gaebel 4d2b8f0444 servo: Merge #3427 - added valid license to tid.rs (from cgaebel:add-license-to-tid)
Source-Repo: https://github.com/servo/servo
Source-Revision: 877de7f694dddd02fcc855a571f99e7c46f7501d
2014-09-19 17:19:42 -07:00

23 lines
635 B
Rust

/* This Source Code Form is subject to the terms of the Mozilla Public
* 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/. */
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
}