Changeset c18bf9e


Ignore:
Timestamp:
May 16, 2022, 12:08:36 PM (19 months ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, ast-experimental, master, pthread-emulation, qualifiedEnum
Children:
4bb5d36
Parents:
108345a
Message:

Visibility concurrency

Location:
libcfa/src
Files:
16 edited

Legend:

Unmodified
Added
Removed
  • libcfa/src/bits/weakso_locks.cfa

    r108345a rc18bf9e  
    1818#include "bits/weakso_locks.hfa"
    1919
     20#pragma GCC visibility push(default)
     21
    2022void  ?{}( blocking_lock &, bool, bool ) {}
    2123void ^?{}( blocking_lock & ) {}
  • libcfa/src/concurrency/alarm.cfa

    r108345a rc18bf9e  
    141141//=============================================================================================
    142142
    143 void sleep( Duration duration ) {
     143void sleep( Duration duration ) libcfa_public {
    144144        alarm_node_t node = { active_thread(), duration, 0`s };
    145145
  • libcfa/src/concurrency/clib/cfathread.cfa

    r108345a rc18bf9e  
    326326}
    327327
     328#pragma GCC visibility push(default)
     329
    328330//================================================================================
    329331// Main Api
    330332extern "C" {
    331         int cfathread_cluster_create(cfathread_cluster_t * cl) __attribute__((nonnull(1))) {
     333        int cfathread_cluster_create(cfathread_cluster_t * cl) __attribute__((nonnull(1))) libcfa_public {
    332334                *cl = new();
    333335                return 0;
    334336        }
    335337
    336         cfathread_cluster_t cfathread_cluster_self(void) {
     338        cfathread_cluster_t cfathread_cluster_self(void) libcfa_public {
    337339                return active_cluster();
    338340        }
    339341
    340         int cfathread_cluster_print_stats( cfathread_cluster_t cl ) {
     342        int cfathread_cluster_print_stats( cfathread_cluster_t cl ) libcfa_public {
    341343                #if !defined(__CFA_NO_STATISTICS__)
    342344                        print_stats_at_exit( *cl, CFA_STATS_READY_Q | CFA_STATS_IO );
  • libcfa/src/concurrency/coroutine.cfa

    r108345a rc18bf9e  
    4848//-----------------------------------------------------------------------------
    4949forall(T &)
    50 void copy(CoroutineCancelled(T) * dst, CoroutineCancelled(T) * src) {
     50void copy(CoroutineCancelled(T) * dst, CoroutineCancelled(T) * src) libcfa_public {
    5151        dst->virtual_table = src->virtual_table;
    5252        dst->the_coroutine = src->the_coroutine;
     
    5555
    5656forall(T &)
    57 const char * msg(CoroutineCancelled(T) *) {
     57const char * msg(CoroutineCancelled(T) *) libcfa_public {
    5858        return "CoroutineCancelled(...)";
    5959}
     
    6262forall(T & | is_coroutine(T))
    6363void __cfaehm_cancelled_coroutine(
    64                 T & cor, coroutine$ * desc, EHM_DEFAULT_VTABLE(CoroutineCancelled, (T)) ) {
     64                T & cor, coroutine$ * desc, EHM_DEFAULT_VTABLE(CoroutineCancelled, (T)) ) libcfa_public {
    6565        verify( desc->cancellation );
    6666        desc->state = Cancelled;
     
    8989
    9090void __stack_prepare( __stack_info_t * this, size_t create_size );
    91 void __stack_clean  ( __stack_info_t * this );
     91static void __stack_clean  ( __stack_info_t * this );
    9292
    9393//-----------------------------------------------------------------------------
     
    114114}
    115115
    116 void ?{}( coroutine$ & this, const char name[], void * storage, size_t storageSize ) with( this ) {
     116void ?{}( coroutine$ & this, const char name[], void * storage, size_t storageSize ) libcfa_public with( this ) {
    117117        (this.context){0p, 0p};
    118118        (this.stack){storage, storageSize};
     
    124124}
    125125
    126 void ^?{}(coroutine$& this) {
     126void ^?{}(coroutine$& this) libcfa_public {
    127127        if(this.state != Halted && this.state != Start && this.state != Primed) {
    128128                coroutine$ * src = active_coroutine();
     
    147147// Not inline since only ever called once per coroutine
    148148forall(T & | is_coroutine(T) | { EHM_DEFAULT_VTABLE(CoroutineCancelled, (T)); })
    149 void prime(T& cor) {
     149void prime(T& cor) libcfa_public {
    150150        coroutine$* this = get_coroutine(cor);
    151151        assert(this->state == Start);
     
    155155}
    156156
    157 [void *, size_t] __stack_alloc( size_t storageSize ) {
     157static [void *, size_t] __stack_alloc( size_t storageSize ) {
    158158        const size_t stack_data_size = libCeiling( sizeof(__stack_t), 16 ); // minimum alignment
    159159        assert(__page_size != 0l);
     
    193193}
    194194
    195 void __stack_clean  ( __stack_info_t * this ) {
     195static void __stack_clean  ( __stack_info_t * this ) {
    196196        void * storage = this->storage->limit;
    197197
     
    215215}
    216216
    217 void __stack_prepare( __stack_info_t * this, size_t create_size ) {
     217void __stack_prepare( __stack_info_t * this, size_t create_size ) libcfa_public {
    218218        const size_t stack_data_size = libCeiling( sizeof(__stack_t), 16 ); // minimum alignment
    219219        bool userStack;
  • libcfa/src/concurrency/coroutine.hfa

    r108345a rc18bf9e  
    113113
    114114extern void __stack_prepare( __stack_info_t * this, size_t size /* ignored if storage already allocated */);
    115 extern void __stack_clean  ( __stack_info_t * this );
    116 
    117115
    118116// Suspend implementation inlined for performance
  • libcfa/src/concurrency/exception.cfa

    r108345a rc18bf9e  
    6464extern "C" {
    6565
    66 struct exception_context_t * this_exception_context(void) {
     66struct exception_context_t * this_exception_context(void) libcfa_public {
    6767        return &__get_stack( active_coroutine() )->exception_context;
    6868}
    6969
    70 _Unwind_Reason_Code __cfaehm_cancellation_unwind( struct _Unwind_Exception * unwind_exception ) {
     70_Unwind_Reason_Code __cfaehm_cancellation_unwind( struct _Unwind_Exception * unwind_exception ) libcfa_public {
    7171        _Unwind_Stop_Fn stop_func;
    7272        void * stop_param;
  • libcfa/src/concurrency/kernel.cfa

    r108345a rc18bf9e  
    389389
    390390// KERNEL_ONLY
    391 void returnToKernel() {
     391static void returnToKernel() {
    392392        /* paranoid */ verify( ! __preemption_enabled() );
    393393        coroutine$ * proc_cor = get_coroutine(kernelTLS().this_processor->runner);
     
    547547}
    548548
    549 void unpark( thread$ * thrd, unpark_hint hint ) {
     549void unpark( thread$ * thrd, unpark_hint hint ) libcfa_public {
    550550        if( !thrd ) return;
    551551
     
    558558}
    559559
    560 void park( void ) {
     560void park( void ) libcfa_public {
    561561        __disable_interrupts_checked();
    562562                /* paranoid */ verify( kernelTLS().this_thread->preempted == __NO_PREEMPTION );
     
    601601
    602602// KERNEL ONLY
    603 bool force_yield( __Preemption_Reason reason ) {
     603bool force_yield( __Preemption_Reason reason ) libcfa_public {
    604604        __disable_interrupts_checked();
    605605                thread$ * thrd = kernelTLS().this_thread;
     
    849849//-----------------------------------------------------------------------------
    850850// Debug
    851 bool threading_enabled(void) __attribute__((const)) {
     851bool threading_enabled(void) __attribute__((const)) libcfa_public {
    852852        return true;
    853853}
     
    856856// Statistics
    857857#if !defined(__CFA_NO_STATISTICS__)
    858         void print_halts( processor & this ) {
     858        void print_halts( processor & this ) libcfa_public {
    859859                this.print_halts = true;
    860860        }
     
    873873        }
    874874
    875         void crawl_cluster_stats( cluster & this ) {
     875        static void crawl_cluster_stats( cluster & this ) {
    876876                // Stop the world, otherwise stats could get really messed-up
    877877                // this doesn't solve all problems but does solve many
     
    889889
    890890
    891         void print_stats_now( cluster & this, int flags ) {
     891        void print_stats_now( cluster & this, int flags ) libcfa_public {
    892892                crawl_cluster_stats( this );
    893893                __print_stats( this.stats, flags, "Cluster", this.name, (void*)&this );
  • libcfa/src/concurrency/kernel.hfa

    r108345a rc18bf9e  
    4949
    5050// Coroutine used py processors for the 2-step context switch
    51 coroutine processorCtx_t {
     51
     52struct processorCtx_t {
     53        struct coroutine$ self;
    5254        struct processor * proc;
    5355};
  • libcfa/src/concurrency/kernel/cluster.cfa

    r108345a rc18bf9e  
    4949
    5050// returns the maximum number of processors the RWLock support
    51 __attribute__((weak)) unsigned __max_processors() {
     51__attribute__((weak)) unsigned __max_processors() libcfa_public {
    5252        const char * max_cores_s = getenv("CFA_MAX_PROCESSORS");
    5353        if(!max_cores_s) {
  • libcfa/src/concurrency/kernel/private.hfa

    r108345a rc18bf9e  
    109109//-----------------------------------------------------------------------------
    110110// Processor
    111 void main(processorCtx_t *);
     111void main(processorCtx_t &);
     112static inline coroutine$* get_coroutine(processorCtx_t & this) { return &this.self; }
    112113
    113114void * __create_pthread( pthread_t *, void * (*)(void *), void * );
  • libcfa/src/concurrency/kernel/startup.cfa

    r108345a rc18bf9e  
    120120#endif
    121121
    122 cluster              * mainCluster;
     122cluster              * mainCluster libcfa_public;
    123123processor            * mainProcessor;
    124124thread$              * mainThread;
     
    169169};
    170170
    171 void ?{}( current_stack_info_t & this ) {
     171static void ?{}( current_stack_info_t & this ) {
    172172        __stack_context_t ctx;
    173173        CtxGet( ctx );
     
    209209        // Construct the processor context of the main processor
    210210        void ?{}(processorCtx_t & this, processor * proc) {
    211                 (this.__cor){ "Processor" };
    212                 this.__cor.starter = 0p;
     211                (this.self){ "Processor" };
     212                this.self.starter = 0p;
    213213                this.proc = proc;
    214214        }
     
    526526// Construct the processor context of non-main processors
    527527static void ?{}(processorCtx_t & this, processor * proc, current_stack_info_t * info) {
    528         (this.__cor){ info };
     528        (this.self){ info };
    529529        this.proc = proc;
    530530}
     
    578578}
    579579
    580 void ?{}(processor & this, const char name[], cluster & _cltr, thread$ * initT) {
     580void ?{}(processor & this, const char name[], cluster & _cltr, thread$ * initT) libcfa_public {
    581581        ( this.terminated ){};
    582582        ( this.runner ){};
     
    591591}
    592592
    593 void ?{}(processor & this, const char name[], cluster & _cltr) {
     593void ?{}(processor & this, const char name[], cluster & _cltr) libcfa_public {
    594594        (this){name, _cltr, 0p};
    595595}
    596596
    597597extern size_t __page_size;
    598 void ^?{}(processor & this) with( this ){
     598void ^?{}(processor & this) libcfa_public with( this ) {
    599599        /* paranoid */ verify( !__atomic_load_n(&do_terminate, __ATOMIC_ACQUIRE) );
    600600        __cfadbg_print_safe(runtime_core, "Kernel : core %p signaling termination\n", &this);
     
    623623}
    624624
    625 void ?{}(cluster & this, const char name[], Duration preemption_rate, unsigned num_io, const io_context_params & io_params) with( this ) {
     625void ?{}(cluster & this, const char name[], Duration preemption_rate, unsigned num_io, const io_context_params & io_params) libcfa_public with( this ) {
    626626        this.name = name;
    627627        this.preemption_rate = preemption_rate;
     
    658658}
    659659
    660 void ^?{}(cluster & this) {
     660void ^?{}(cluster & this) libcfa_public {
    661661        destroy(this.io.arbiter);
    662662
  • libcfa/src/concurrency/locks.cfa

    r108345a rc18bf9e  
    2424#include <stdlib.hfa>
    2525
     26#pragma GCC visibility push(default)
     27
    2628//-----------------------------------------------------------------------------
    2729// info_thread
     
    116118}
    117119
    118 void pop_and_set_new_owner( blocking_lock & this ) with( this ) {
     120static void pop_and_set_new_owner( blocking_lock & this ) with( this ) {
    119121        thread$ * t = &try_pop_front( blocked_threads );
    120122        owner = t;
     
    192194        void ^?{}( alarm_node_wrap(L) & this ) { }
    193195
    194         void timeout_handler ( alarm_node_wrap(L) & this ) with( this ) {
     196        static void timeout_handler ( alarm_node_wrap(L) & this ) with( this ) {
    195197                // This condition_variable member is called from the kernel, and therefore, cannot block, but it can spin.
    196198                lock( cond->lock __cfaabi_dbg_ctx2 );
     
    216218
    217219        // this casts the alarm node to our wrapped type since we used type erasure
    218         void alarm_node_wrap_cast( alarm_node_t & a ) { timeout_handler( (alarm_node_wrap(L) &)a ); }
     220        static void alarm_node_wrap_cast( alarm_node_t & a ) { timeout_handler( (alarm_node_wrap(L) &)a ); }
    219221}
    220222
     
    233235        void ^?{}( condition_variable(L) & this ){ }
    234236
    235         void process_popped( condition_variable(L) & this, info_thread(L) & popped ) with( this ) {
     237        static void process_popped( condition_variable(L) & this, info_thread(L) & popped ) with( this ) {
    236238                if(&popped != 0p) {
    237239                        popped.signalled = true;
     
    278280        int counter( condition_variable(L) & this ) with(this) { return count; }
    279281
    280         size_t queue_and_get_recursion( condition_variable(L) & this, info_thread(L) * i ) with(this) {
     282        static size_t queue_and_get_recursion( condition_variable(L) & this, info_thread(L) * i ) with(this) {
    281283                // add info_thread to waiting queue
    282284                insert_last( blocked_threads, *i );
     
    291293
    292294        // helper for wait()'s' with no timeout
    293         void queue_info_thread( condition_variable(L) & this, info_thread(L) & i ) with(this) {
     295        static void queue_info_thread( condition_variable(L) & this, info_thread(L) & i ) with(this) {
    294296                lock( lock __cfaabi_dbg_ctx2 );
    295297                size_t recursion_count = queue_and_get_recursion(this, &i);
     
    308310
    309311        // helper for wait()'s' with a timeout
    310         void queue_info_thread_timeout( condition_variable(L) & this, info_thread(L) & info, Duration t, Alarm_Callback callback ) with(this) {
     312        static void queue_info_thread_timeout( condition_variable(L) & this, info_thread(L) & info, Duration t, Alarm_Callback callback ) with(this) {
    311313                lock( lock __cfaabi_dbg_ctx2 );
    312314                size_t recursion_count = queue_and_get_recursion(this, &info);
     
    343345        // fast_cond_var
    344346        void  ?{}( fast_cond_var(L) & this ){
    345                 this.blocked_threads{}; 
     347                this.blocked_threads{};
    346348                #ifdef __CFA_DEBUG__
    347349                this.lock_used = 0p;
  • libcfa/src/concurrency/monitor.cfa

    r108345a rc18bf9e  
    4444static inline void restore( monitor$ * ctx [], __lock_size_t count, __spinlock_t * locks [], unsigned int /*in */ recursions [], __waitfor_mask_t /*in */ masks [] );
    4545
     46static inline void ?{}(__condition_node_t & this, thread$ * waiting_thread, __lock_size_t count, uintptr_t user_info );
     47static inline void ?{}(__condition_criterion_t & this );
     48static inline void ?{}(__condition_criterion_t & this, monitor$ * target, __condition_node_t * owner );
     49
    4650static inline void init     ( __lock_size_t count, monitor$ * monitors [], __condition_node_t & waiter, __condition_criterion_t criteria [] );
    4751static inline void init_push( __lock_size_t count, monitor$ * monitors [], __condition_node_t & waiter, __condition_criterion_t criteria [] );
     
    243247
    244248// Leave single monitor
    245 void __leave( monitor$ * this ) {
     249static void __leave( monitor$ * this ) {
    246250        // Lock the monitor spinlock
    247251        lock( this->lock __cfaabi_dbg_ctx2 );
     
    278282
    279283// Leave single monitor for the last time
    280 void __dtor_leave( monitor$ * this, bool join ) {
     284static void __dtor_leave( monitor$ * this, bool join ) {
    281285        __cfaabi_dbg_debug_do(
    282286                if( active_thread() != this->owner ) {
     
    344348// Ctor for monitor guard
    345349// Sorts monitors before entering
    346 void ?{}( monitor_guard_t & this, monitor$ * m [], __lock_size_t count, fptr_t func ) {
     350void ?{}( monitor_guard_t & this, monitor$ * m [], __lock_size_t count, fptr_t func ) libcfa_public {
    347351        thread$ * thrd = active_thread();
    348352
     
    369373}
    370374
    371 void ?{}( monitor_guard_t & this, monitor$ * m [], __lock_size_t count ) {
     375void ?{}( monitor_guard_t & this, monitor$ * m [], __lock_size_t count ) libcfa_public {
    372376        this{ m, count, 0p };
    373377}
     
    375379
    376380// Dtor for monitor guard
    377 void ^?{}( monitor_guard_t & this ) {
     381void ^?{}( monitor_guard_t & this ) libcfa_public {
    378382        // __cfaabi_dbg_print_safe( "MGUARD : leaving %d\n", this.count);
    379383
     
    389393// Ctor for monitor guard
    390394// Sorts monitors before entering
    391 void ?{}( monitor_dtor_guard_t & this, monitor$ * m [], fptr_t func, bool join ) {
     395void ?{}( monitor_dtor_guard_t & this, monitor$ * m [], fptr_t func, bool join ) libcfa_public {
    392396        // optimization
    393397        thread$ * thrd = active_thread();
     
    409413
    410414// Dtor for monitor guard
    411 void ^?{}( monitor_dtor_guard_t & this ) {
     415void ^?{}( monitor_dtor_guard_t & this ) libcfa_public {
    412416        // Leave the monitors in order
    413417        __dtor_leave( this.m, this.join );
     
    419423//-----------------------------------------------------------------------------
    420424// Internal scheduling types
    421 void ?{}(__condition_node_t & this, thread$ * waiting_thread, __lock_size_t count, uintptr_t user_info ) {
     425static void ?{}(__condition_node_t & this, thread$ * waiting_thread, __lock_size_t count, uintptr_t user_info ) {
    422426        this.waiting_thread = waiting_thread;
    423427        this.count = count;
     
    426430}
    427431
    428 void ?{}(__condition_criterion_t & this ) with( this ) {
     432static void ?{}(__condition_criterion_t & this ) with( this ) {
    429433        ready  = false;
    430434        target = 0p;
     
    433437}
    434438
    435 void ?{}(__condition_criterion_t & this, monitor$ * target, __condition_node_t & owner ) {
     439static void ?{}(__condition_criterion_t & this, monitor$ * target, __condition_node_t & owner ) {
    436440        this.ready  = false;
    437441        this.target = target;
     
    442446//-----------------------------------------------------------------------------
    443447// Internal scheduling
    444 void wait( condition & this, uintptr_t user_info = 0 ) {
     448void wait( condition & this, uintptr_t user_info = 0 ) libcfa_public {
    445449        brand_condition( this );
    446450
     
    496500}
    497501
    498 bool signal( condition & this ) {
     502bool signal( condition & this ) libcfa_public {
    499503        if( is_empty( this ) ) { return false; }
    500504
     
    538542}
    539543
    540 bool signal_block( condition & this ) {
     544bool signal_block( condition & this ) libcfa_public {
    541545        if( !this.blocked.head ) { return false; }
    542546
     
    586590
    587591// Access the user_info of the thread waiting at the front of the queue
    588 uintptr_t front( condition & this ) {
     592uintptr_t front( condition & this ) libcfa_public {
    589593        verifyf( !is_empty(this),
    590594                "Attempt to access user data on an empty condition.\n"
     
    608612//              setup mask
    609613//              block
    610 void __waitfor_internal( const __waitfor_mask_t & mask, int duration ) {
     614void __waitfor_internal( const __waitfor_mask_t & mask, int duration ) libcfa_public {
    611615        // This statment doesn't have a contiguous list of monitors...
    612616        // Create one!
     
    994998// Can't be accepted since a mutex stmt is effectively an anonymous routine
    995999// Thus we do not need a monitor group
    996 void lock( monitor$ * this ) {
     1000void lock( monitor$ * this ) libcfa_public {
    9971001        thread$ * thrd = active_thread();
    9981002
     
    10461050// Leave routine for mutex stmt
    10471051// Is just a wrapper around __leave for the is_lock trait to see
    1048 void unlock( monitor$ * this ) { __leave( this ); }
     1052void unlock( monitor$ * this ) libcfa_public { __leave( this ); }
    10491053
    10501054// Local Variables: //
  • libcfa/src/concurrency/monitor.hfa

    r108345a rc18bf9e  
    119119}
    120120
    121 void ?{}(__condition_node_t & this, thread$ * waiting_thread, __lock_size_t count, uintptr_t user_info );
    122 void ?{}(__condition_criterion_t & this );
    123 void ?{}(__condition_criterion_t & this, monitor$ * target, __condition_node_t * owner );
     121// void ?{}(__condition_node_t & this, thread$ * waiting_thread, __lock_size_t count, uintptr_t user_info );
     122// void ?{}(__condition_criterion_t & this );
     123// void ?{}(__condition_criterion_t & this, monitor$ * target, __condition_node_t * owner );
    124124
    125125struct condition {
  • libcfa/src/concurrency/preemption.cfa

    r108345a rc18bf9e  
    3838#endif
    3939
    40 __attribute__((weak)) Duration default_preemption() {
     40__attribute__((weak)) Duration default_preemption() libcfa_public {
    4141        const char * preempt_rate_s = getenv("CFA_DEFAULT_PREEMPTION");
    4242        if(!preempt_rate_s) {
     
    238238//----------
    239239// special case for preemption since used often
    240 __attribute__((optimize("no-reorder-blocks"))) bool __preemption_enabled() {
     240__attribute__((optimize("no-reorder-blocks"))) bool __preemption_enabled() libcfa_public {
    241241        // create a assembler label before
    242242        // marked as clobber all to avoid movement
     
    276276// Get data from the TLS block
    277277// struct asm_region __cfaasm_get;
    278 uintptr_t __cfatls_get( unsigned long int offset ) __attribute__((__noinline__)); //no inline to avoid problems
     278uintptr_t __cfatls_get( unsigned long int offset ) __attribute__((__noinline__, visibility("default"))); //no inline to avoid problems
    279279uintptr_t __cfatls_get( unsigned long int offset ) {
    280280        // create a assembler label before
     
    295295extern "C" {
    296296        // Disable interrupts by incrementing the counter
    297         void disable_interrupts() {
     297        __attribute__((__noinline__, visibility("default"))) void disable_interrupts() libcfa_public {
    298298                // create a assembler label before
    299299                // marked as clobber all to avoid movement
     
    326326        // Enable interrupts by decrementing the counter
    327327        // If counter reaches 0, execute any pending __cfactx_switch
    328         void enable_interrupts( bool poll ) {
     328        void enable_interrupts( bool poll ) libcfa_public {
    329329                // Cache the processor now since interrupts can start happening after the atomic store
    330330                processor   * proc = __cfaabi_tls.this_processor;
     
    362362//-----------------------------------------------------------------------------
    363363// Kernel Signal Debug
    364 void __cfaabi_check_preemption() {
     364void __cfaabi_check_preemption() libcfa_public {
    365365        bool ready = __preemption_enabled();
    366366        if(!ready) { abort("Preemption should be ready"); }
  • libcfa/src/concurrency/thread.cfa

    r108345a rc18bf9e  
    2626
    2727extern uint32_t __global_random_seed, __global_random_prime, __global_random_mask;
     28
     29#pragma GCC visibility push(default)
    2830
    2931//-----------------------------------------------------------------------------
Note: See TracChangeset for help on using the changeset viewer.