Ignore:
Timestamp:
Jun 7, 2018, 11:14:07 AM (6 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, with_gc
Children:
ae3bb3d
Parents:
214e8da
Message:

Immetidate fix for halting processors, drifting still an issue

File:
1 edited

Legend:

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

    r214e8da rea8b2f7  
    1818#include "bits/debug.h"
    1919#include "bits/defs.h"
     20#include <assert.h>
     21
     22#ifdef __cforall
     23        extern "C" {
     24                #include <pthread.h>
     25        }
     26#endif
    2027
    2128// pause to prevent excess processor bus usage
     
    112119                __atomic_clear( &this.lock, __ATOMIC_RELEASE );
    113120        }
     121
     122
     123        #ifdef __CFA_WITH_VERIFY__
     124                extern bool __cfaabi_dbg_in_kernel();
     125        #endif
     126
     127        struct __bin_sem_t {
     128                int_fast8_t     counter;
     129                pthread_mutex_t lock;
     130                pthread_cond_t  cond;
     131        };
     132
     133        static inline void ?{}(__bin_sem_t & this) with( this ) {
     134                counter = 0;
     135                pthread_mutex_init(&lock, NULL);
     136                pthread_cond_init (&cond, NULL);
     137        }
     138
     139        static inline void ^?{}(__bin_sem_t & this) with( this ) {
     140                pthread_mutex_destroy(&lock);
     141                pthread_cond_destroy (&cond);
     142        }
     143
     144        static inline void wait(__bin_sem_t & this) with( this ) {
     145                verify(__cfaabi_dbg_in_kernel());
     146                pthread_mutex_lock(&lock);
     147                if(counter != 0) {   // this must be a loop, not if!
     148                        pthread_cond_wait(&cond, &lock);
     149                }
     150                counter = 1;
     151                pthread_mutex_unlock(&lock);
     152        }
     153
     154        static inline void post(__bin_sem_t & this) with( this ) {
     155                verify(__cfaabi_dbg_in_kernel());
     156                pthread_mutex_lock(&lock);
     157                bool needs_signal = counter == 0;
     158                counter = 1;
     159                pthread_mutex_unlock(&lock);
     160                if (!needs_signal)
     161                        pthread_cond_signal(&cond);
     162                }
    114163#endif
Note: See TracChangeset for help on using the changeset viewer.