Changeset eba74ba for src/libcfa/bits/locks.h
- Timestamp:
- May 25, 2018, 2:51:06 PM (6 years ago)
- 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. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/libcfa/bits/locks.h
r3ef35bd reba74ba 39 39 #endif 40 40 41 #if __SIZEOF_SIZE_T__ == 842 #define __lock_test_and_test_and_set( lock ) (lock) == 0 && __sync_lock_test_and_set_8( &(lock), 1 ) == 043 #define __lock_release( lock ) __sync_lock_release_8( &(lock) );44 #elif __SIZEOF_SIZE_T__ == 445 #define __lock_test_and_test_and_set( lock ) (lock) == 0 && __sync_lock_test_and_set_4( &(lock), 1 ) == 046 #define __lock_release( lock ) __sync_lock_release_4( &(lock) );47 #else48 #error unsupported architecture49 #endif50 51 41 struct __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 }; 53 47 #ifdef __CFA_DEBUG__ 48 // previous function to acquire the lock 54 49 const char * prev_name; 50 // previous thread to acquire the lock 55 51 void* prev_thrd; 56 52 #endif … … 78 74 // Lock the spinlock, return false if already acquired 79 75 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); 81 77 if( result ) { 82 78 disable_interrupts(); … … 94 90 95 91 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; 97 93 #ifndef NOEXPBACK 98 94 // exponential spin … … 112 108 } 113 109 114 // // Lock the spinlock, yield if already acquired115 // 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 127 110 static inline void unlock( __spinlock_t & this ) { 128 111 enable_interrupts_noPoll(); 129 __ lock_release( this.lock);112 __atomic_clear( &this.lock, __ATOMIC_RELEASE ); 130 113 } 131 114 #endif
Note: See TracChangeset
for help on using the changeset viewer.