[][src]Macro alloc_tls::alloc_tls_fast_with

macro_rules! alloc_tls_fast_with {
    ($slot:expr, $name:ident, $blk:block) => { ... };
}

Access the TLS slot with maximum performance.

alloc_tls_fast_with is the macro version of TLSSlot's with method. In practice, we have found that that method is not always optimized as much as it could be, and using a macro is friendlier to the optimizer.

$slot is the TLSSlot to be accessed. $blk is a block of code that will be executed, and the TLS value will be bound to a variable named $name in that block.

Note that this macro uses core intrinsics; in order to use it, you must put #![feature(core_intrinsics)] at the root of your crate.

Safety

alloc_tls_fast_with must be called from an unsafe block. It is unsafe because if f panics, it causes undefined behavior.

Example

alloc_thread_local!{ static FOO: usize = 0; }
unsafe {
    alloc_tls_fast_with!(FOO, foo, {
        println!("foo: {}", foo);
    });
}