Changeset c66f6cb


Ignore:
Timestamp:
May 6, 2020, 2:03:13 PM (4 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
171ca0d
Parents:
08a994e
Message:

Added pthread error checking to the terminating semaphore.

Location:
libcfa/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • libcfa/src/bits/locks.hfa

    r08a994e rc66f6cb  
    112112        #endif
    113113
     114        extern "C" {
     115                char * strerror(int);
     116        }
     117        #define CHECKED(x) { int err = x; if( err != 0 ) abort("KERNEL ERROR: %s\n", strerror(err)); }
     118
    114119        struct __bin_sem_t {
    115120                pthread_mutex_t         lock;
     
    119124
    120125        static inline void ?{}(__bin_sem_t & this) with( this ) {
    121                 pthread_mutex_init(&lock, NULL);
    122                 pthread_cond_init (&cond, NULL);
     126                // Create the mutex with error checking
     127                pthread_mutexattr_t mattr;
     128                pthread_mutexattr_init( &mattr );
     129                pthread_mutexattr_settype( &mattr, PTHREAD_MUTEX_ERRORCHECK_NP);
     130                pthread_mutex_init(&lock, &mattr);
     131
     132                pthread_cond_init (&cond, 0p);
    123133                val = 0;
    124134        }
    125135
    126136        static inline void ^?{}(__bin_sem_t & this) with( this ) {
    127                 pthread_mutex_destroy(&lock);
    128                 pthread_cond_destroy (&cond);
     137                CHECKED( pthread_mutex_destroy(&lock) );
     138                CHECKED( pthread_cond_destroy (&cond) );
    129139        }
    130140
    131141        static inline void wait(__bin_sem_t & this) with( this ) {
    132142                verify(__cfaabi_dbg_in_kernel());
    133                 pthread_mutex_lock(&lock);
     143                CHECKED( pthread_mutex_lock(&lock) );
    134144                        while(val < 1) {
    135145                                pthread_cond_wait(&cond, &lock);
    136146                        }
    137147                        val -= 1;
    138                 pthread_mutex_unlock(&lock);
     148                CHECKED( pthread_mutex_unlock(&lock) );
    139149        }
    140150
     
    142152                bool needs_signal = false;
    143153
    144                 pthread_mutex_lock(&lock);
     154                CHECKED( pthread_mutex_lock(&lock) );
    145155                        if(val < 1) {
    146156                                val += 1;
     
    148158                                needs_signal = true;
    149159                        }
    150                 pthread_mutex_unlock(&lock);
     160                CHECKED( pthread_mutex_unlock(&lock) );
    151161
    152162                return needs_signal;
    153163        }
     164
     165        #undef CHECKED
    154166#endif
  • libcfa/src/concurrency/kernel.cfa

    r08a994e rc66f6cb  
    250250        }
    251251
    252         pthread_join( kernel_thread, 0p );
     252        int err = pthread_join( kernel_thread, 0p );
     253        if( err != 0 ) abort("KERNEL ERROR: joining processor %p caused error %s\n", &this, strerror(err));
     254
    253255        free( this.stack );
    254256}
     
    824826        // Destroy the main processor and its context in reverse order of construction
    825827        // These were manually constructed so we need manually destroy them
     828        void ^?{}(processor & this) with( this ){
     829                /* paranoid */ verify( this.do_terminate == true );
     830        }
     831
    826832        ^(*mainProcessor){};
    827833
Note: See TracChangeset for help on using the changeset viewer.