blob: 1e569731ff2dd223e4d6ec215c0441a04c94519d (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
/* 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, 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
}
|