Ignore:
File:
1 edited

Legend:

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

    r3aeee3c r73abe95  
    1010// Created On       : Tue Oct 31 15:14:38 2017
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sat Aug 11 15:42:24 2018
    13 // Update Count     : 10
     12// Last Modified On : Fri Mar 30 18:18:13 2018
     13// Update Count     : 9
    1414//
    1515
     
    3737#endif
    3838
     39#if defined( __i386 ) || defined( __x86_64 ) || defined( __ARM_ARCH )
     40        // Intel recommendation
     41        #define __ALIGN__ __attribute__(( aligned (128) ))
     42#elif defined( __sparc )
     43        #define __ALIGN__ CALIGN
     44#else
     45        #error unsupported architecture
     46#endif
     47
    3948struct __spinlock_t {
    4049        // Wrap in struct to prevent false sharing with debug info
    41         volatile bool lock;
     50        struct {
     51                // Align lock on 128-bit boundary
     52                __ALIGN__ volatile _Bool lock;
     53        };
    4254        #ifdef __CFA_DEBUG__
    4355                // previous function to acquire the lock
     
    4658                void* prev_thrd;
    4759        #endif
    48 };
     60} __ALIGN__;
    4961
    5062#ifdef __cforall
     
    5264                extern void disable_interrupts();
    5365                extern void enable_interrupts_noPoll();
    54 
    55                 #ifdef __CFA_DEBUG__
    56                         void __cfaabi_dbg_record(__spinlock_t & this, const char * prev_name);
    57                 #else
    58                         #define __cfaabi_dbg_record(x, y)
    59                 #endif
    6066        }
    6167
     
    6672        }
    6773
     74
     75        #ifdef __CFA_DEBUG__
     76                void __cfaabi_dbg_record(__spinlock_t & this, const char * prev_name);
     77        #else
     78                #define __cfaabi_dbg_record(x, y)
     79        #endif
     80
    6881        // Lock the spinlock, return false if already acquired
    69         static inline bool try_lock  ( __spinlock_t & this __cfaabi_dbg_ctx_param2 ) {
    70                 bool result = (this.lock == 0) && (__atomic_test_and_set( &this.lock, __ATOMIC_ACQUIRE ) == 0);
     82        static inline _Bool try_lock  ( __spinlock_t & this __cfaabi_dbg_ctx_param2 ) {
     83                _Bool result = (this.lock == 0) && (__atomic_test_and_set( &this.lock, __ATOMIC_ACQUIRE ) == 0);
    7184                if( result ) {
    7285                        disable_interrupts();
Note: See TracChangeset for help on using the changeset viewer.