source: benchmark/basic/tls_fetch_add.c @ 2316525

ADTarm-ehast-experimentalenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprpthread-emulationqualifiedEnum
Last change on this file since 2316525 was 525b5ef, checked in by Peter A. Buhr <pabuhr@…>, 4 years ago

add documentation

  • Property mode set to 100644
File size: 835 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#define thread_local _Thread_local
10
11thread_local volatile bool value;
12
13void __attribute__((noinline)) do_call() {
14        __atomic_store_n( &value, true, __ATOMIC_RELAXED );
15        __atomic_signal_fence(__ATOMIC_ACQUIRE);
16        asm volatile ("");
17        __atomic_store_n( &value, false, __ATOMIC_RELAXED );
18        __atomic_signal_fence(__ATOMIC_RELEASE);
19}
20
21int main( int argc, char * argv[] ) {
22        BENCH_START()
23        BENCH(
24                for (size_t i = 0; i < times; i++) {
25                        do_call();
26                },
27                result
28        )
29        printf( "%g\n", result );
30}
31
32// Local Variables: //
33// tab-width: 4 //
34// End: //
Note: See TracBrowser for help on using the repository browser.