Changeset eba74ba for src/libcfa/bits


Ignore:
Timestamp:
May 25, 2018, 2:51:06 PM (7 years ago)
Author:
Aaron Moss <a3moss@…>
Branches:
new-env, with_gc
Children:
cdc4d43
Parents:
3ef35bd (diff), 58e822a (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 remote-tracking branch 'origin/master' into with_gc

Location:
src/libcfa/bits
Files:
2 edited

Legend:

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

    r3ef35bd reba74ba  
    220220        }
    221221
    222         #define _next .0
    223         #define _prev .1
     222        #define next 0
     223        #define prev 1
    224224        forall(dtype T | sized(T))
    225225        static inline void push_front( __dllist(T) & this, T & node ) with( this ) {
     226                verify(__get);
    226227                if ( head ) {
    227                         __get( node )_next = head;
    228                         __get( node )_prev = __get( *head )_prev;
     228                        __get( node ).next = head;
     229                        __get( node ).prev = __get( *head ).prev;
    229230                        // inserted node must be consistent before it is seen
    230231                        // prevent code movement across barrier
    231232                        asm( "" : : : "memory" );
    232                         __get( *head )_prev = &node;
    233                         T & prev = *__get( node )_prev;
    234                         __get( prev )_next = &node;
     233                        __get( *head ).prev = &node;
     234                        T & _prev = *__get( node ).prev;
     235                        __get( _prev ).next = &node;
    235236                }
    236237                else {
    237                         __get( node )_next = &node;
    238                         __get( node )_prev = &node;
     238                        __get( node ).next = &node;
     239                        __get( node ).prev = &node;
    239240                }
    240241
     
    246247        forall(dtype T | sized(T))
    247248        static inline void remove( __dllist(T) & this, T & node ) with( this ) {
     249                verify(__get);
    248250                if ( &node == head ) {
    249                         if ( __get( *head )_next == head ) {
     251                        if ( __get( *head ).next == head ) {
    250252                                head = NULL;
    251253                        }
    252254                        else {
    253                                 head = __get( *head )_next;
     255                                head = __get( *head ).next;
    254256                        }
    255257                }
    256                 __get( *__get( node )_next )_prev = __get( node )_prev;
    257                 __get( *__get( node )_prev )_next = __get( node )_next;
    258                 __get( node )_next = NULL;
    259                 __get( node )_prev = NULL;
    260         }
    261         #undef _next
    262         #undef _prev
     258                __get( *__get( node ).next ).prev = __get( node ).prev;
     259                __get( *__get( node ).prev ).next = __get( node ).next;
     260                __get( node ).next = NULL;
     261                __get( node ).prev = NULL;
     262        }
     263        #undef next
     264        #undef prev
    263265#endif
    264266
  • src/libcfa/bits/locks.h

    r3ef35bd reba74ba  
    3939#endif
    4040
    41 #if __SIZEOF_SIZE_T__ == 8
    42         #define __lock_test_and_test_and_set( lock ) (lock) == 0 && __sync_lock_test_and_set_8( &(lock), 1 ) == 0
    43         #define __lock_release( lock ) __sync_lock_release_8( &(lock) );
    44 #elif __SIZEOF_SIZE_T__ == 4
    45         #define __lock_test_and_test_and_set( lock ) (lock) == 0 && __sync_lock_test_and_set_4( &(lock), 1 ) == 0
    46         #define __lock_release( lock ) __sync_lock_release_4( &(lock) );
    47 #else
    48         #error unsupported architecture
    49 #endif
    50 
    5141struct __spinlock_t {
    52         __ALIGN__ volatile size_t lock;
     42        // Wrap in struct to prevent false sharing with debug info
     43        struct {
     44                // Align lock on 128-bit boundary
     45                __ALIGN__ volatile _Bool lock;
     46        };
    5347        #ifdef __CFA_DEBUG__
     48                // previous function to acquire the lock
    5449                const char * prev_name;
     50                // previous thread to acquire the lock
    5551                void* prev_thrd;
    5652        #endif
     
    7874        // Lock the spinlock, return false if already acquired
    7975        static inline _Bool try_lock  ( __spinlock_t & this __cfaabi_dbg_ctx_param2 ) {
    80                 _Bool result = __lock_test_and_test_and_set( this.lock );
     76                _Bool result = (this.lock == 0) && (__atomic_test_and_set( &this.lock, __ATOMIC_ACQUIRE ) == 0);
    8177                if( result ) {
    8278                        disable_interrupts();
     
    9490
    9591                for ( unsigned int i = 1;; i += 1 ) {
    96                         if ( __lock_test_and_test_and_set( this.lock ) ) break;
     92                        if ( (this.lock == 0) && (__atomic_test_and_set( &this.lock, __ATOMIC_ACQUIRE ) == 0) ) break;
    9793                        #ifndef NOEXPBACK
    9894                                // exponential spin
     
    112108        }
    113109
    114         // // Lock the spinlock, yield if already acquired
    115         // static inline void lock_yield( __spinlock_t & this __cfaabi_dbg_ctx_param2 ) {
    116         //      for ( unsigned int i = 1;; i += 1 ) {
    117         //              if ( __lock_test_and_test_and_set( this.lock ) ) break;
    118         //              yield( i );
    119         //      }
    120         //      disable_interrupts();
    121         //      __cfaabi_dbg_debug_do(
    122         //              this.prev_name = caller;
    123         //              this.prev_thrd = this_thread;
    124         //      )
    125         // }
    126 
    127110        static inline void unlock( __spinlock_t & this ) {
    128111                enable_interrupts_noPoll();
    129                 __lock_release( this.lock );
     112                __atomic_clear( &this.lock, __ATOMIC_RELEASE );
    130113        }
    131114#endif
Note: See TracChangeset for help on using the changeset viewer.