Changes in src/libcfa/bits/locks.h [13073be:9181f1d]
- File:
-
- 1 edited
-
src/libcfa/bits/locks.h (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/libcfa/bits/locks.h
r13073be r9181f1d 39 39 #endif 40 40 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 41 51 struct __spinlock_t { 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 }; 52 __ALIGN__ volatile size_t lock; 47 53 #ifdef __CFA_DEBUG__ 48 // previous function to acquire the lock49 54 const char * prev_name; 50 // previous thread to acquire the lock51 55 void* prev_thrd; 52 56 #endif … … 74 78 // Lock the spinlock, return false if already acquired 75 79 static inline _Bool try_lock ( __spinlock_t & this __cfaabi_dbg_ctx_param2 ) { 76 _Bool result = (this.lock == 0) && (__atomic_test_and_set( &this.lock, __ATOMIC_ACQUIRE ) == 0);80 _Bool result = __lock_test_and_test_and_set( this.lock ); 77 81 if( result ) { 78 82 disable_interrupts(); … … 90 94 91 95 for ( unsigned int i = 1;; i += 1 ) { 92 if ( (this.lock == 0) && (__atomic_test_and_set( &this.lock, __ATOMIC_ACQUIRE ) == 0) ) break;96 if ( __lock_test_and_test_and_set( this.lock ) ) break; 93 97 #ifndef NOEXPBACK 94 98 // exponential spin … … 108 112 } 109 113 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 110 127 static inline void unlock( __spinlock_t & this ) { 111 128 enable_interrupts_noPoll(); 112 __ atomic_clear( &this.lock, __ATOMIC_RELEASE);129 __lock_release( this.lock ); 113 130 } 114 131 #endif
Note:
See TracChangeset
for help on using the changeset viewer.