Changeset 5a40e4e for libcfa/src


Ignore:
Timestamp:
Sep 9, 2021, 3:56:32 PM (3 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, ast-experimental, enum, forall-pointer-decay, master, pthread-emulation, qualifiedEnum
Children:
d0b9247
Parents:
dd1cc02 (diff), d8d512e (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' of plg.uwaterloo.ca:software/cfa/cfa-cc

Location:
libcfa/src
Files:
7 added
10 edited

Legend:

Unmodified
Added
Removed
  • libcfa/src/Makefile.am

    rdd1cc02 r5a40e4e  
    4848        math.hfa \
    4949        time_t.hfa \
     50        bits/algorithm.hfa \
    5051        bits/align.hfa \
    5152        bits/containers.hfa \
     
    7778        memory.hfa \
    7879        parseargs.hfa \
     80        parseconfig.hfa \
    7981        rational.hfa \
    8082        stdlib.hfa \
     
    8587        containers/pair.hfa \
    8688        containers/result.hfa \
     89        containers/string.hfa \
     90        containers/string_res.hfa \
    8791        containers/vector.hfa \
    8892        device/cpu.hfa
     
    9094libsrc = ${inst_headers_src} ${inst_headers_src:.hfa=.cfa} \
    9195        assert.cfa \
    92         bits/algorithm.hfa \
    9396        bits/debug.cfa \
    9497        exception.c \
     
    106109        concurrency/invoke.h \
    107110        concurrency/future.hfa \
    108         concurrency/kernel/fwd.hfa
     111        concurrency/kernel/fwd.hfa \
     112        concurrency/mutex_stmt.hfa
    109113
    110114inst_thread_headers_src = \
  • libcfa/src/concurrency/kernel/startup.cfa

    rdd1cc02 r5a40e4e  
    235235
    236236        register_tls( mainProcessor );
     237        mainThread->last_cpu = __kernel_getcpu();
    237238
    238239        //initialize the global state variables
     
    478479        state = Start;
    479480        self_cor{ info };
    480         last_cpu = __kernel_getcpu();
    481481        curr_cor = &self_cor;
    482482        curr_cluster = mainCluster;
  • libcfa/src/concurrency/locks.hfa

    rdd1cc02 r5a40e4e  
    324324        }
    325325
    326         // linear backoff bounded by spin_count
    327         spin = spin_start;
    328         int spin_counter = 0;
    329         int yield_counter = 0;
    330         for ( ;; ) {
    331                 if(try_lock_contention(this)) return true;
    332                 if(spin_counter < spin_count) {
    333                         for (int i = 0; i < spin; i++) Pause();
    334                         if (spin < spin_end) spin += spin;
    335                         else spin_counter++;
    336                 } else if (yield_counter < yield_count) {
    337                         // after linear backoff yield yield_count times
    338                         yield_counter++;
    339                         yield();
    340                 } else { break; }
    341         }
    342 
    343         // block until signalled
    344         while (block(this)) if(try_lock_contention(this)) return true;
    345 
    346         // this should never be reached as block(this) always returns true
    347         return false;
    348 }
    349 
    350 static inline bool lock_improved(linear_backoff_then_block_lock & this) with(this) {
    351         // if owner just return
    352         if (active_thread() == owner) return true;
    353         size_t compare_val = 0;
    354         int spin = spin_start;
    355         // linear backoff
    356         for( ;; ) {
    357                 compare_val = 0;
    358                 if (internal_try_lock(this, compare_val)) return true;
    359                 if (2 == compare_val) break;
    360                 for (int i = 0; i < spin; i++) Pause();
    361                 if (spin >= spin_end) break;
    362                 spin += spin;
    363         }
    364 
    365         // linear backoff bounded by spin_count
    366         spin = spin_start;
    367         int spin_counter = 0;
    368         int yield_counter = 0;
    369         for ( ;; ) {
    370                 compare_val = 0;
    371                 if(internal_try_lock(this, compare_val)) return true;
    372                 if (2 == compare_val) break;
    373                 if(spin_counter < spin_count) {
    374                         for (int i = 0; i < spin; i++) Pause();
    375                         if (spin < spin_end) spin += spin;
    376                         else spin_counter++;
    377                 } else if (yield_counter < yield_count) {
    378                         // after linear backoff yield yield_count times
    379                         yield_counter++;
    380                         yield();
    381                 } else { break; }
    382         }
    383 
    384326        if(2 != compare_val && try_lock_contention(this)) return true;
    385327        // block until signalled
     
    402344static inline void on_notify(linear_backoff_then_block_lock & this, struct thread$ * t ) { unpark(t); }
    403345static inline size_t on_wait(linear_backoff_then_block_lock & this) { unlock(this); return 0; }
    404 static inline void on_wakeup(linear_backoff_then_block_lock & this, size_t recursion ) { lock_improved(this); }
     346static inline void on_wakeup(linear_backoff_then_block_lock & this, size_t recursion ) { lock(this); }
    405347
    406348//-----------------------------------------------------------------------------
  • libcfa/src/concurrency/monitor.cfa

    rdd1cc02 r5a40e4e  
    367367
    368368        // __cfaabi_dbg_print_safe( "MGUARD : entered\n" );
     369}
     370
     371void ?{}( monitor_guard_t & this, monitor$ * m [], __lock_size_t count ) {
     372        this{ m, count, 0p };
    369373}
    370374
     
    986990}
    987991
     992//-----------------------------------------------------------------------------
     993// Enter routine for mutex stmt
     994// Can't be accepted since a mutex stmt is effectively an anonymous routine
     995// Thus we do not need a monitor group
     996void lock( monitor$ * this ) {
     997        thread$ * thrd = active_thread();
     998
     999        // Lock the monitor spinlock
     1000        lock( this->lock __cfaabi_dbg_ctx2 );
     1001
     1002        __cfaabi_dbg_print_safe( "Kernel : %10p Entering mon %p (%p)\n", thrd, this, this->owner);
     1003
     1004        if( unlikely(0 != (0x1 & (uintptr_t)this->owner)) ) {
     1005                abort( "Attempt by thread \"%.256s\" (%p) to access joined monitor %p.", thrd->self_cor.name, thrd, this );
     1006        }
     1007        else if( !this->owner ) {
     1008                // No one has the monitor, just take it
     1009                __set_owner( this, thrd );
     1010
     1011                __cfaabi_dbg_print_safe( "Kernel :  mon is free \n" );
     1012        }
     1013        else if( this->owner == thrd) {
     1014                // We already have the monitor, just note how many times we took it
     1015                this->recursion += 1;
     1016
     1017                __cfaabi_dbg_print_safe( "Kernel :  mon already owned \n" );
     1018        }
     1019        else {
     1020                __cfaabi_dbg_print_safe( "Kernel :  blocking \n" );
     1021
     1022                // Some one else has the monitor, wait in line for it
     1023                /* paranoid */ verify( thrd->link.next == 0p );
     1024                append( this->entry_queue, thrd );
     1025                /* paranoid */ verify( thrd->link.next == 1p );
     1026
     1027                unlock( this->lock );
     1028                park();
     1029
     1030                __cfaabi_dbg_print_safe( "Kernel : %10p Entered  mon %p\n", thrd, this);
     1031
     1032                /* paranoid */ verifyf( active_thread() == this->owner, "Expected owner to be %p, got %p (r: %i, m: %p)", active_thread(), this->owner, this->recursion, this );
     1033                return;
     1034        }
     1035
     1036        __cfaabi_dbg_print_safe( "Kernel : %10p Entered  mon %p\n", thrd, this);
     1037
     1038        /* paranoid */ verifyf( active_thread() == this->owner, "Expected owner to be %p, got %p (r: %i, m: %p)", active_thread(), this->owner, this->recursion, this );
     1039        /* paranoid */ verify( this->lock.lock );
     1040
     1041        // Release the lock and leave
     1042        unlock( this->lock );
     1043        return;
     1044}
     1045
     1046// Leave routine for mutex stmt
     1047// Is just a wrapper around __leave for the is_lock trait to see
     1048void unlock( monitor$ * this ) { __leave( this ); }
     1049
    9881050// Local Variables: //
    9891051// mode: c //
  • libcfa/src/concurrency/monitor.hfa

    rdd1cc02 r5a40e4e  
    4848
    4949void ?{}( monitor_guard_t & this, monitor$ ** m, __lock_size_t count, void (*func)() );
     50void ?{}( monitor_guard_t & this, monitor$ ** m, __lock_size_t count );
    5051void ^?{}( monitor_guard_t & this );
    5152
     
    148149void __waitfor_internal( const __waitfor_mask_t & mask, int duration );
    149150
     151// lock and unlock routines for mutex statements to use
     152void lock( monitor$ * this );
     153void unlock( monitor$ * this );
     154
    150155// Local Variables: //
    151156// mode: c //
  • libcfa/src/concurrency/thread.cfa

    rdd1cc02 r5a40e4e  
    3434        preempted = __NO_PREEMPTION;
    3535        corctx_flag = false;
     36        disable_interrupts();
    3637        last_cpu = __kernel_getcpu();
     38        enable_interrupts();
    3739        curr_cor = &self_cor;
    3840        self_mon.owner = &this;
  • libcfa/src/fstream.cfa

    rdd1cc02 r5a40e4e  
    124124void open( ofstream & os, const char name[], const char mode[] ) {
    125125        FILE * file = fopen( name, mode );
    126         #ifdef __CFA_DEBUG__
     126        // #ifdef __CFA_DEBUG__
    127127        if ( file == 0p ) {
    128128                throw (Open_Failure){ os };
    129129                // abort | IO_MSG "open output file \"" | name | "\"" | nl | strerror( errno );
    130130        } // if
    131         #endif // __CFA_DEBUG__
     131        // #endif // __CFA_DEBUG__
    132132        (os){ file };
    133133} // open
     
    262262void open( ifstream & is, const char name[], const char mode[] ) {
    263263        FILE * file = fopen( name, mode );
    264         #ifdef __CFA_DEBUG__
     264        // #ifdef __CFA_DEBUG__
    265265        if ( file == 0p ) {
    266266                throw (Open_Failure){ is };
    267267                // abort | IO_MSG "open input file \"" | name | "\"" | nl | strerror( errno );
    268268        } // if
    269         #endif // __CFA_DEBUG__
     269        // #endif // __CFA_DEBUG__
    270270        is.file$ = file;
    271271} // open
  • libcfa/src/heap.cfa

    rdd1cc02 r5a40e4e  
    1010// Created On       : Tue Dec 19 21:58:35 2017
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sat May 22 08:46:39 2021
    13 // Update Count     : 1036
     12// Last Modified On : Mon Aug  9 19:03:02 2021
     13// Update Count     : 1040
    1414//
    1515
     
    102102} // prtUnfreed
    103103
     104extern int cfa_main_returned;                                                   // from bootloader.cf
    104105extern "C" {
    105106        void heapAppStart() {                                                           // called by __cfaabi_appready_startup
     
    109110        void heapAppStop() {                                                            // called by __cfaabi_appready_startdown
    110111                fclose( stdin ); fclose( stdout );
    111                 prtUnfreed();
     112                if ( cfa_main_returned ) prtUnfreed();                  // do not check unfreed storage if exit called
    112113        } // heapAppStop
    113114} // extern "C"
  • libcfa/src/memory.cfa

    rdd1cc02 r5a40e4e  
    155155
    156156forall(T &)
     157T * release(unique_ptr(T) & this) {
     158        T * data = this.data;
     159        this.data = 0p;
     160        return data;
     161}
     162
     163forall(T &)
    157164int ?==?(unique_ptr(T) const & this, unique_ptr(T) const & that) {
    158165        return this.data == that.data;
  • libcfa/src/memory.hfa

    rdd1cc02 r5a40e4e  
    9494
    9595forall(T &)
     96T * release(unique_ptr(T) & this);
     97
     98forall(T &)
    9699int ?==?(unique_ptr(T) const & this, unique_ptr(T) const & that);
    97100forall(T &)
Note: See TracChangeset for help on using the changeset viewer.