Changeset 7416d46a for src/libcfa/bits


Ignore:
Timestamp:
Jan 30, 2018, 3:54:32 PM (7 years ago)
Author:
Thierry Delisle <tdelisle@…>
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.
Message:

Merge branch 'master' of plg.uwaterloo.ca:software/cfa/cfa-cc

Location:
src/libcfa/bits
Files:
1 added
1 edited

Legend:

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

    rf792cb8 r7416d46a  
    99// Author           : Thierry Delisle
    1010// Created On       : Tue Oct 31 15:14:38 2017
    11 // Last Modified By : --
    12 // Last Modified On : --
    13 // Update Count     : 0
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Fri Dec  8 16:02:22 2017
     13// Update Count     : 1
    1414//
    1515
     
    2424#elif defined( __i386 ) || defined( __x86_64 )
    2525        #define Pause() __asm__ __volatile__ ( "pause" : : : )
     26#elif defined( __ARM_ARCH )
     27        #define Pause() __asm__ __volatile__ ( "nop" : : : )
    2628#else
    2729        #error unsupported architecture
    2830#endif
    2931
    30 #if defined( __i386 ) || defined( __x86_64 )
     32#if defined( __i386 ) || defined( __x86_64 ) || defined( __ARM_ARCH )
    3133        // Intel recommendation
    3234        #define __ALIGN__ __attribute__(( aligned (128) ))
     
    3739#endif
    3840
    39 #if defined( __x86_64 )
     41#if __SIZEOF_SIZE_T__ == 8
    4042        #define __lock_test_and_test_and_set( lock ) (lock) == 0 && __sync_lock_test_and_set_8( &(lock), 1 ) == 0
    4143        #define __lock_release( lock ) __sync_lock_release_8( &(lock) );
    42 #elif defined( __i386 )
     44#elif __SIZEOF_SIZE_T__ == 4
    4345        #define __lock_test_and_test_and_set( lock ) (lock) == 0 && __sync_lock_test_and_set_4( &(lock), 1 ) == 0
    4446        #define __lock_release( lock ) __sync_lock_release_4( &(lock) );
     
    4850
    4951struct __spinlock_t {
    50         __ALIGN__ volatile uintptr_t lock;
     52        __ALIGN__ volatile size_t lock;
    5153        #ifdef __CFA_DEBUG__
    5254                const char * prev_name;
     
    5658
    5759#ifdef __cforall
     60        extern "C" {
     61                extern void disable_interrupts();
     62                extern void enable_interrupts_noPoll();
     63        }
     64
    5865        extern void yield( unsigned int );
    5966        extern thread_local struct thread_desc *    volatile this_thread;
     67        extern thread_local struct processor *      volatile this_processor;
    6068
    6169        static inline void ?{}( __spinlock_t & this ) {
     
    6674        static inline _Bool try_lock  ( __spinlock_t & this __cfaabi_dbg_ctx_param2 ) {
    6775                _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(
    7079                                this.prev_name = caller;
    7180                                this.prev_thrd = this_thread;
    72                         }
    73                 )
     81                        )
     82                }
    7483                return result;
    7584        }
     
    97106                        #endif
    98107                }
     108                disable_interrupts();
    99109                __cfaabi_dbg_debug_do(
    100110                        this.prev_name = caller;
     
    103113        }
    104114
    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        // }
    116127
    117128        static inline void unlock( __spinlock_t & this ) {
     129                enable_interrupts_noPoll();
    118130                __lock_release( this.lock );
    119131        }
Note: See TracChangeset for help on using the changeset viewer.