source: libcfa/src/bits/defs.hfa @ 20be782

ADTast-experimentalpthread-emulation
Last change on this file since 20be782 was 20be782, checked in by z277zhu <z277zhu@…>, 21 months ago

add pthread

  • Property mode set to 100644
File size: 3.2 KB
Line 
1//
2// Cforall Version 1.0.0 Copyright (C) 2016 University of Waterloo
3//
4// The contents of this file are covered under the licence agreement in the
5// file "LICENCE" distributed with Cforall.
6//
7// defs.hfa -- Commen macros, functions and typedefs
8// Most files depend on them and they are always useful to have.
9//
10//  *** Must not contain code specific to libcfathread ***
11//
12// Author           : Thierry Delisle
13// Created On       : Thu Nov  9 13:24:10 2017
14// Last Modified By : Peter A. Buhr
15// Last Modified On : Sat Oct 24 10:53:15 2020
16// Update Count     : 21
17//
18
19#pragma once
20
21#include <stdint.h>
22#include <assert.h>
23
24
25#define likely(x)   __builtin_expect(!!(x), 1)
26#define unlikely(x) __builtin_expect(!!(x), 0)
27#define thread_local _Thread_local
28
29typedef void (*fptr_t)();
30typedef int_fast16_t __lock_size_t;
31
32#ifdef __cforall
33#define __cfa_anonymous_object(x) inline struct x
34#define __cfa_dlink(x) inline dlink(x)
35#else
36#define __cfa_anonymous_object(x) struct x __cfa_anonymous_object
37#define __cfa_dlink(x) struct { struct x * next; struct x * back; } __dlink_substitute
38#endif
39
40#define libcfa_public __attribute__((visibility("default")))
41
42#ifdef __cforall
43void abort( const char fmt[], ... ) __attribute__ (( format(printf, 1, 2), __nothrow__, __leaf__, __noreturn__ ));
44void abort( bool signalAbort, const char fmt[], ... ) __attribute__ (( format(printf, 2, 3), __nothrow__, __leaf__, __noreturn__ ));
45extern "C" {
46        #include <pthread.h>
47        void __cabi_abort( const char fmt[], ... ) __attribute__ (( format(printf, 1, 2), __nothrow__, __leaf__, __noreturn__ ));
48        int real_pthread_create(pthread_t *_thread, const pthread_attr_t *attr, void *(*start_routine) (void *), void *arg);
49        int real_pthread_join(pthread_t _thread, void **retval);
50        pthread_t real_pthread_self(void);
51        int real_pthread_attr_init(pthread_attr_t *attr);
52        int real_pthread_attr_destroy(pthread_attr_t *attr);
53        int real_pthread_attr_setstack( pthread_attr_t *attr, void *stackaddr, size_t stacksize );
54        int real_pthread_attr_getstacksize( const pthread_attr_t *attr, size_t *stacksize );
55        //int real_pthread_sigqueue(pthread_t _thread, int sig, const union sigval value);
56        //int real_pthread_sigmask( int /* how */, const sigset_t * /* set */, sigset_t * /* oset */ );
57}
58#endif
59
60#if defined(__cforall_thread__)
61#define OPTIONAL_THREAD
62#else
63#define OPTIONAL_THREAD __attribute__((weak))
64#endif
65
66static inline long long int rdtscl(void) {
67        #if defined( __i386 ) || defined( __x86_64 )
68        unsigned int lo, hi;
69        __asm__ __volatile__ ("rdtsc" : "=a"(lo), "=d"(hi));
70        return ( (unsigned long long)lo)|( ((unsigned long long)hi)<<32 );
71        #elif defined( __aarch64__ ) || defined( __arm__ )
72        // https://github.com/google/benchmark/blob/v1.1.0/src/cycleclock.h#L116
73        long long int virtual_timer_value;
74        asm volatile("mrs %0, cntvct_el0" : "=r"(virtual_timer_value));
75        return virtual_timer_value;
76        #else
77                #error unsupported hardware architecture
78        #endif
79}
80
81// pause to prevent excess processor bus usage
82#if defined( __i386 ) || defined( __x86_64 )
83        #define Pause() __asm__ __volatile__ ( "pause" : : : )
84#elif defined( __ARM_ARCH )
85        #define Pause() __asm__ __volatile__ ( "YIELD" : : : )
86#else
87        #error unsupported architecture
88#endif
89
90#define CFA_IO_LAZY (1_l64u << 32_l64u)
Note: See TracBrowser for help on using the repository browser.