Ignore:
Timestamp:
Nov 29, 2007, 12:46:14 AM (17 years ago)
Author:
[email protected]
Message:

Merging updated system alloc and spinlock code from r38 of TCMalloc.

Reviewed by Geoff

This is needed as a precursor to the merge of TCMalloc proper.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/wtf/TCSpinLock.h

    r27709 r28135  
    1 // Copyright (c) 2005, Google Inc.
     1// Copyright (c) 2005, 2006, Google Inc.
    22// All rights reserved.
    33//
     
    5858// The following is a struct so that it can be initialized at compile time
    5959struct TCMalloc_SpinLock {
    60   volatile unsigned int private_lockword_;
    61 
    62   inline void Init() { private_lockword_ = 0; }
    63   inline void Finalize() { }
    64    
     60
    6561  inline void Lock() {
    6662    int r;
     
    6965    __asm__ __volatile__
    7066      ("xchgl %0, %1"
    71        : "=r"(r), "=m"(private_lockword_)
    72        : "0"(1), "m"(private_lockword_)
    73        : "memory");
    74 #else
    75     volatile unsigned int *lockword_ptr = &private_lockword_;
     67       : "=r"(r), "=m"(lockword_)
     68       : "0"(1), "m"(lockword_)
     69       : "memory");
     70#else
     71    volatile unsigned int *lockword_ptr = &lockword_;
    7672    __asm__ __volatile__
    7773        ("1: lwarx %0, 0, %1\n\t"
     
    8581#elif COMPILER(MSVC)
    8682    __asm {
    87         mov eax, this    ; store &private_lockword_ (which is this+0) in eax
     83        mov eax, this    ; store &lockword_ (which is this+0) in eax
    8884        mov ebx, 1       ; store 1 in ebx
    89         xchg [eax], ebx  ; exchange private_lockword_ and 1
    90         mov r, ebx       ; store old value of private_lockword_ in r
    91     }
    92 #endif
    93     if (r) TCMalloc_SlowLock(&private_lockword_);
     85        xchg [eax], ebx  ; exchange lockword_ and 1
     86        mov r, ebx       ; store old value of lockword_ in r
     87    }
     88#endif
     89    if (r) TCMalloc_SlowLock(&lockword_);
    9490  }
    9591
     
    9995    __asm__ __volatile__
    10096      ("movl $0, %0"
    101        : "=m"(private_lockword_)
    102        : "m" (private_lockword_)
     97       : "=m"(lockword_)
     98       : "m" (lockword_)
    10399       : "memory");
    104100#else
     
    107103       "eieio\n\t"
    108104       "stw %1, %0"
    109        : "=o" (private_lockword_)
     105       : "=o" (lockword_)
    110106       : "r" (0)
    111107       : "memory");
     
    113109#elif COMPILER(MSVC)
    114110      __asm {
    115           mov eax, this  ; store &private_lockword_ (which is this+0) in eax
    116           mov [eax], 0   ; set private_lockword_ to 0
     111          mov eax, this  ; store &lockword_ (which is this+0) in eax
     112          mov [eax], 0   ; set lockword_ to 0
    117113      }
    118114#endif
    119115  }
    120 
    121 #ifdef WTF_CHANGES 
    122   inline bool IsLocked() {
    123     return private_lockword_ != 0;
    124   }
    125 #endif
     116    // Report if we think the lock can be held by this thread.
     117    // When the lock is truly held by the invoking thread
     118    // we will always return true.
     119    // Indended to be used as CHECK(lock.IsHeld());
     120    inline bool IsHeld() const {
     121        return lockword_ != 0;
     122    }
     123
     124    volatile unsigned int lockword_;
    126125};
    127126
Note: See TracChangeset for help on using the changeset viewer.