source: benchmark/basic/tls_fetch_add.c @ ed9a1ae

ADTast-experimentalpthread-emulation
Last change on this file since ed9a1ae was dc708c1, checked in by Thierry Delisle <tdelisle@…>, 22 months ago

Removed other instance of thread_local

  • Property mode set to 100644
File size: 800 bytes
Line 
1#include <stdbool.h>
2#include <stdio.h>
3
4#include "bench.h"
5
6// Does not do a fetch & add. It mimics the cfa protocol to disable interrupts locally, by writing true or false to a
7// thread_local Boolean. This means the entire protocol is just to "mov" instructions making it extremely cheap.
8
9_Thread_local volatile bool value;
10
11void __attribute__((noinline)) do_call() {
12        __atomic_store_n( &value, true, __ATOMIC_RELAXED );
13        __atomic_signal_fence(__ATOMIC_ACQUIRE);
14        asm volatile ("");
15        __atomic_store_n( &value, false, __ATOMIC_RELAXED );
16        __atomic_signal_fence(__ATOMIC_RELEASE);
17}
18
19int main( int argc, char * argv[] ) {
20        BENCH_START()
21        BENCH(
22                for (size_t i = 0; i < times; i++) {
23                        do_call();
24                },
25                result
26        )
27        printf( "%g\n", result );
28}
29
30// Local Variables: //
31// tab-width: 4 //
32// End: //
Note: See TracBrowser for help on using the repository browser.