Skip to content

Commit

Permalink
Make SpinLock class smaller (#99618)
Browse files Browse the repository at this point in the history
- During other work, I noticed that the SpinLock class's `m_Initialized` field was only useful for DEBUG builds, and for ensuring that m_lock was set to 0 sometime after construction of the SpinLock
- Set `m_lock` to 0 in the constructor instead
- Move all handling of `m_initialized` to withing a DEBUG block
  • Loading branch information
davidwrighton authored Mar 13, 2024
1 parent e4fceb3 commit fde0fd3
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
12 changes: 6 additions & 6 deletions src/coreclr/vm/spinlock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,11 @@ SpinLock::SpinLock()
STATIC_CONTRACT_NOTHROW;
STATIC_CONTRACT_GC_NOTRIGGER;

m_lock = 0;

#ifdef _DEBUG
m_Initialized = UnInitialized;
#endif
}

void SpinLock::Init(LOCK_TYPE type, bool RequireCoopGC)
Expand All @@ -45,6 +49,7 @@ void SpinLock::Init(LOCK_TYPE type, bool RequireCoopGC)
}
CONTRACTL_END;

#ifdef _DEBUG
if (m_Initialized == Initialized)
{
_ASSERTE (type == m_LockType);
Expand Down Expand Up @@ -72,17 +77,12 @@ void SpinLock::Init(LOCK_TYPE type, bool RequireCoopGC)
}
}

{
m_lock = 0;
}

#ifdef _DEBUG
m_LockType = type;
m_requireCoopGCMode = RequireCoopGC;
#endif

_ASSERTE (m_Initialized == BeingInitialized);
m_Initialized = Initialized;
#endif
}

#ifdef _DEBUG
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/vm/spinlock.h
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ class SpinLock
LONG m_lock; // LONG used in interlocked exchange
};

#ifdef _DEBUG
enum SpinLockState
{
UnInitialized,
Expand All @@ -163,7 +164,6 @@ class SpinLock
Volatile<SpinLockState> m_Initialized; // To verify initialized
// And initialize once

#ifdef _DEBUG
LOCK_TYPE m_LockType; // lock type to track statistics

// Check for dead lock situation.
Expand Down

0 comments on commit fde0fd3

Please sign in to comment.