source: benchmark/basic/tls_fetch_add.c @ 2980ccb8

Last change on this file since 2980ccb8 was 1bcbf02, checked in by Thierry Delisle <tdelisle@…>, 2 years ago

Changed declarations using _Thread_local to use thread.
I'm fairly sure they do exactly the same, but
thread is:

  • more consistent with uC++.
  • Shorter.
  • Better documented.
  • Property mode set to 100644
File size: 795 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 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.