Changeset 7416d46a for src/libcfa/bits
- Timestamp:
- Jan 30, 2018, 3:54:32 PM (7 years ago)
- 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, resolv-new, with_gc
- Children:
- 633a642
- Parents:
- f792cb8 (diff), 42be3c3 (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. - Location:
- src/libcfa/bits
- Files:
-
- 1 added
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/libcfa/bits/locks.h
rf792cb8 r7416d46a 9 9 // Author : Thierry Delisle 10 10 // Created On : Tue Oct 31 15:14:38 2017 11 // Last Modified By : --12 // Last Modified On : --13 // Update Count : 011 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Fri Dec 8 16:02:22 2017 13 // Update Count : 1 14 14 // 15 15 … … 24 24 #elif defined( __i386 ) || defined( __x86_64 ) 25 25 #define Pause() __asm__ __volatile__ ( "pause" : : : ) 26 #elif defined( __ARM_ARCH ) 27 #define Pause() __asm__ __volatile__ ( "nop" : : : ) 26 28 #else 27 29 #error unsupported architecture 28 30 #endif 29 31 30 #if defined( __i386 ) || defined( __x86_64 ) 32 #if defined( __i386 ) || defined( __x86_64 ) || defined( __ARM_ARCH ) 31 33 // Intel recommendation 32 34 #define __ALIGN__ __attribute__(( aligned (128) )) … … 37 39 #endif 38 40 39 #if defined( __x86_64 )41 #if __SIZEOF_SIZE_T__ == 8 40 42 #define __lock_test_and_test_and_set( lock ) (lock) == 0 && __sync_lock_test_and_set_8( &(lock), 1 ) == 0 41 43 #define __lock_release( lock ) __sync_lock_release_8( &(lock) ); 42 #elif defined( __i386 )44 #elif __SIZEOF_SIZE_T__ == 4 43 45 #define __lock_test_and_test_and_set( lock ) (lock) == 0 && __sync_lock_test_and_set_4( &(lock), 1 ) == 0 44 46 #define __lock_release( lock ) __sync_lock_release_4( &(lock) ); … … 48 50 49 51 struct __spinlock_t { 50 __ALIGN__ volatile uintptr_t lock;52 __ALIGN__ volatile size_t lock; 51 53 #ifdef __CFA_DEBUG__ 52 54 const char * prev_name; … … 56 58 57 59 #ifdef __cforall 60 extern "C" { 61 extern void disable_interrupts(); 62 extern void enable_interrupts_noPoll(); 63 } 64 58 65 extern void yield( unsigned int ); 59 66 extern thread_local struct thread_desc * volatile this_thread; 67 extern thread_local struct processor * volatile this_processor; 60 68 61 69 static inline void ?{}( __spinlock_t & this ) { … … 66 74 static inline _Bool try_lock ( __spinlock_t & this __cfaabi_dbg_ctx_param2 ) { 67 75 _Bool result = __lock_test_and_test_and_set( this.lock ); 68 __cfaabi_dbg_debug_do( 69 if( result ) { 76 if( result ) { 77 disable_interrupts(); 78 __cfaabi_dbg_debug_do( 70 79 this.prev_name = caller; 71 80 this.prev_thrd = this_thread; 72 }73 )81 ) 82 } 74 83 return result; 75 84 } … … 97 106 #endif 98 107 } 108 disable_interrupts(); 99 109 __cfaabi_dbg_debug_do( 100 110 this.prev_name = caller; … … 103 113 } 104 114 105 // Lock the spinlock, spin if already acquired 106 static inline void lock_yield( __spinlock_t & this __cfaabi_dbg_ctx_param2 ) { 107 for ( unsigned int i = 1;; i += 1 ) { 108 if ( __lock_test_and_test_and_set( this.lock ) ) break; 109 yield( i ); 110 } 111 __cfaabi_dbg_debug_do( 112 this.prev_name = caller; 113 this.prev_thrd = this_thread; 114 ) 115 } 115 // // Lock the spinlock, yield if already acquired 116 // static inline void lock_yield( __spinlock_t & this __cfaabi_dbg_ctx_param2 ) { 117 // for ( unsigned int i = 1;; i += 1 ) { 118 // if ( __lock_test_and_test_and_set( this.lock ) ) break; 119 // yield( i ); 120 // } 121 // disable_interrupts(); 122 // __cfaabi_dbg_debug_do( 123 // this.prev_name = caller; 124 // this.prev_thrd = this_thread; 125 // ) 126 // } 116 127 117 128 static inline void unlock( __spinlock_t & this ) { 129 enable_interrupts_noPoll(); 118 130 __lock_release( this.lock ); 119 131 }
Note: See TracChangeset
for help on using the changeset viewer.