Changeset 3381ed7 for libcfa/src/bits


Ignore:
Timestamp:
Feb 13, 2020, 4:18:07 PM (5 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
50b8885
Parents:
9f575ea
Message:

Added park/unpark primitives thread and removed BlockInternal?.
Converted monitors to use park unpark.
Intrusive Queue now mark next field when thread is inside queue.
Added several asserts to kernel and monitor.
Added a few tests for park and unpark.

Location:
libcfa/src/bits
Files:
2 edited

Legend:

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

    r9f575ea r3381ed7  
    146146        static inline forall( dtype T | is_node(T) ) {
    147147                void ?{}( __queue(T) & this ) with( this ) {
    148                         head{ 0p };
     148                        head{ 1p };
    149149                        tail{ &head };
     150                        verify(*tail == 1p);
    150151                }
    151152
    152153                void append( __queue(T) & this, T * val ) with( this ) {
    153154                        verify(tail != 0p);
     155                        verify(*tail == 1p);
    154156                        *tail = val;
    155157                        tail = &get_next( *val );
     158                        *tail = 1p;
    156159                }
    157160
    158161                T * pop_head( __queue(T) & this ) {
     162                        verify(*this.tail == 1p);
    159163                        T * head = this.head;
    160                         if( head ) {
     164                        if( head != 1p ) {
    161165                                this.head = get_next( *head );
    162                                 if( !get_next( *head ) ) {
     166                                if( get_next( *head ) == 1p ) {
    163167                                        this.tail = &this.head;
    164168                                }
    165169                                get_next( *head ) = 0p;
    166                         }
    167                         return head;
     170                                verify(*this.tail == 1p);
     171                                return head;
     172                        }
     173                        verify(*this.tail == 1p);
     174                        return 0p;
    168175                }
    169176
     
    180187                        get_next( *val ) = 0p;
    181188
    182                         verify( (head == 0p) == (&head == tail) );
    183                         verify( *tail == 0p );
     189                        verify( (head == 1p) == (&head == tail) );
     190                        verify( *tail == 1p );
    184191                        return val;
    185192                }
  • libcfa/src/bits/locks.hfa

    r9f575ea r3381ed7  
    6060        }
    6161
    62         extern void yield( unsigned int );
    63 
    6462        static inline void ?{}( __spinlock_t & this ) {
    6563                this.lock = 0;
     
    6866        // Lock the spinlock, return false if already acquired
    6967        static inline bool try_lock  ( __spinlock_t & this __cfaabi_dbg_ctx_param2 ) {
     68                disable_interrupts();
    7069                bool result = (this.lock == 0) && (__atomic_test_and_set( &this.lock, __ATOMIC_ACQUIRE ) == 0);
    7170                if( result ) {
    72                         disable_interrupts();
    7371                        __cfaabi_dbg_record( this, caller );
     72                } else {
     73                        enable_interrupts_noPoll();
    7474                }
    7575                return result;
     
    8383                #endif
    8484
     85                disable_interrupts();
    8586                for ( unsigned int i = 1;; i += 1 ) {
    8687                        if ( (this.lock == 0) && (__atomic_test_and_set( &this.lock, __ATOMIC_ACQUIRE ) == 0) ) break;
     
    9899                        #endif
    99100                }
    100                 disable_interrupts();
    101101                __cfaabi_dbg_record( this, caller );
    102102        }
    103103
    104104        static inline void unlock( __spinlock_t & this ) {
     105                __atomic_clear( &this.lock, __ATOMIC_RELEASE );
    105106                enable_interrupts_noPoll();
    106                 __atomic_clear( &this.lock, __ATOMIC_RELEASE );
    107107        }
    108108
Note: See TracChangeset for help on using the changeset viewer.