source: libcfa/src/bits/defs.hfa @ a7d696f

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

added pthread symbol interpose

Signed-off-by: z277zhu <z277zhu@…>

  • Property mode set to 100644
File size: 3.6 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#include <pthread.h>
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#endif
47void __cabi_abort( const char fmt[], ... ) __attribute__ (( format(printf, 1, 2), __nothrow__, __leaf__, __noreturn__ ));
48int real_pthread_create(pthread_t *_thread, const pthread_attr_t *attr, void *(*start_routine) (void *), void *arg);
49int real_pthread_join(pthread_t _thread, void **retval);
50pthread_t real_pthread_self(void);
51int real_pthread_mutex_init(pthread_mutex_t *_mutex, const pthread_mutexattr_t *attr);
52int real_pthread_mutex_destroy(pthread_mutex_t *_mutex);
53int real_pthread_mutex_lock(pthread_mutex_t *_mutex);
54int real_pthread_mutex_unlock(pthread_mutex_t *_mutex);
55int real_pthread_mutex_trylock(pthread_mutex_t *_mutex);
56int real_pthread_cond_init(pthread_cond_t *cond, const pthread_condattr_t *attr);
57int real_pthread_cond_wait(pthread_cond_t *cond, pthread_mutex_t *_mutex);
58int real_pthread_cond_signal(pthread_cond_t *cond);
59int real_pthread_cond_broadcast(pthread_cond_t *cond);
60int real_pthread_cond_destroy(pthread_cond_t *cond);
61int real_pthread_attr_init(pthread_attr_t *attr);
62int real_pthread_attr_destroy(pthread_attr_t *attr);
63int real_pthread_attr_setstack( pthread_attr_t *attr, void *stackaddr, size_t stacksize );
64int real_pthread_attr_getstacksize( const pthread_attr_t *attr, size_t *stacksize );
65#ifdef __cforall
66}
67#endif
68
69#if defined(__cforall_thread__)
70#define OPTIONAL_THREAD
71#else
72#define OPTIONAL_THREAD __attribute__((weak))
73#endif
74
75static inline long long int rdtscl(void) {
76        #if defined( __i386 ) || defined( __x86_64 )
77        unsigned int lo, hi;
78        __asm__ __volatile__ ("rdtsc" : "=a"(lo), "=d"(hi));
79        return ( (unsigned long long)lo)|( ((unsigned long long)hi)<<32 );
80        #elif defined( __aarch64__ ) || defined( __arm__ )
81        // https://github.com/google/benchmark/blob/v1.1.0/src/cycleclock.h#L116
82        long long int virtual_timer_value;
83        asm volatile("mrs %0, cntvct_el0" : "=r"(virtual_timer_value));
84        return virtual_timer_value;
85        #else
86                #error unsupported hardware architecture
87        #endif
88}
89
90// pause to prevent excess processor bus usage
91#if defined( __i386 ) || defined( __x86_64 )
92        #define Pause() __asm__ __volatile__ ( "pause" : : : )
93#elif defined( __ARM_ARCH )
94        #define Pause() __asm__ __volatile__ ( "YIELD" : : : )
95#else
96        #error unsupported architecture
97#endif
98
99#define CFA_IO_LAZY (1_l64u << 32_l64u)
Note: See TracBrowser for help on using the repository browser.