Impala
Impalaistheopensource,nativeanalyticdatabaseforApacheHadoop.
|
Lightweight spinlock. More...
#include <spinlock.h>
Public Member Functions | |
SpinLock () | |
void | lock () |
Acquires the lock, spins until the lock becomes available. More... | |
void | unlock () |
bool | try_lock () |
Tries to acquire the lock. More... | |
void | DCheckLocked () |
Private Member Functions | |
void | SlowAcquire () |
Private Attributes | |
bool | locked_ |
TODO: pad this to be a cache line? More... | |
Static Private Attributes | |
static const int | NUM_SPIN_CYCLES = 70 |
Lightweight spinlock.
Definition at line 24 of file spinlock.h.
|
inline |
Definition at line 26 of file spinlock.h.
|
inline |
|
inline |
Acquires the lock, spins until the lock becomes available.
Definition at line 29 of file spinlock.h.
References SlowAcquire(), and try_lock().
Referenced by impala::StreamingSampler< int64_t, 64 >::GetSamples().
|
private |
Out-of-line definition of the actual spin loop. The primary goal is to have the actual lock method as short as possible to avoid polluting the i-cache with unnecessary instructions in the non-contested case.
Definition at line 18 of file spinlock.cc.
References impala::AtomicUtil::CpuWait(), NUM_SPIN_CYCLES, and try_lock().
Referenced by lock().
|
inline |
Tries to acquire the lock.
Definition at line 41 of file spinlock.h.
References locked_.
Referenced by lock(), and SlowAcquire().
|
inline |
Definition at line 33 of file spinlock.h.
References locked_.
Referenced by impala::RuntimeProfile::PrettyPrint(), and impala::RuntimeProfile::TimeSeriesCounter::ToThrift().
|
private |
TODO: pad this to be a cache line?
Definition at line 67 of file spinlock.h.
Referenced by DCheckLocked(), try_lock(), and unlock().
|
staticprivate |
In typical spin lock implements, we want to spin (and keep the core fully busy), for some number of cycles before yielding. Consider these three cases: 1) lock is un-contended - spinning doesn't kick in and has no effect. 2) lock is taken by another thread and that thread finishes quickly. 3) lock is taken by another thread and that thread is slow (e.g. scheduled away).
In case 3), we'd want to yield so another thread can do work. This thread won't be able to do anything useful until the thread with the lock runs again. In case 2), we don't want to yield (and give up our scheduling time slice) since we will get to run soon after. To try to get the best of everything, we will busy spin for a while before yielding to another thread. TODO: how do we set this.
Definition at line 65 of file spinlock.h.
Referenced by SlowAcquire().