mirror of
https://github.com/servo/servo.git
synced 2025-08-05 21:50:18 +01:00
Fixed #3386.
This commit is contained in:
parent
1b251db732
commit
670ca9894e
7 changed files with 59 additions and 8 deletions
18
components/util/tid.rs
Normal file
18
components/util/tid.rs
Normal file
|
@ -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
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue