mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-28 20:55:39 +00:00
78741af324
Source-Repo: https://github.com/servo/servo Source-Revision: 3f9012864a2cd927cf17a8e11dfa6922add1b7df
27 lines
790 B
Rust
27 lines
790 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::atomic::{AtomicUint, ATOMIC_UINT_INIT, Ordering};
|
|
use std::rc::Rc;
|
|
use std::cell::RefCell;
|
|
|
|
static mut next_tid: AtomicUint = ATOMIC_UINT_INIT;
|
|
|
|
thread_local!(static TASK_LOCAL_TID: Rc<RefCell<Option<uint>>> = Rc::new(RefCell::new(None)));
|
|
|
|
/// Every task gets one, that's unique.
|
|
pub fn tid() -> uint {
|
|
TASK_LOCAL_TID.with(|ref k| {
|
|
let ret =
|
|
match *k.borrow() {
|
|
None => unsafe { next_tid.fetch_add(1, Ordering::SeqCst) },
|
|
Some(x) => x,
|
|
};
|
|
|
|
*k.borrow_mut() = Some(ret);
|
|
|
|
ret
|
|
})
|
|
}
|