Skip to content

Commit fc75401

Browse files
committed
spin for a short time to improve latency
1 parent a9c0a2b commit fc75401

File tree

2 files changed

+23
-5
lines changed

2 files changed

+23
-5
lines changed

game/shared/tf/tf_player_shared.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5573,7 +5573,10 @@ void CTFPlayerShared::OnAddHalloweenKartCage( void )
55735573
if ( !m_pOuter->m_hHalloweenKartCage )
55745574
{
55755575
m_pOuter->m_hHalloweenKartCage = C_PlayerAttachedModel::Create( "models/props_halloween/bumpercar_cage.mdl", m_pOuter, 0, vec3_origin, PAM_PERMANENT, 0 );
5576-
m_pOuter->m_hHalloweenKartCage->FollowEntity( m_pOuter, true );
5576+
if (m_pOuter->m_hHalloweenKartCage)
5577+
{
5578+
m_pOuter->m_hHalloweenKartCage->FollowEntity(m_pOuter, true);
5579+
}
55775580
}
55785581
#else
55795582
AddCond( TF_COND_FREEZE_INPUT );

tier0/threadtools.cpp

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1593,14 +1593,13 @@ int ThreadWaitForEvents(int nEvents, CThreadEvent* const* pEvents, bool bWaitAll
15931593
}
15941594
else
15951595
{
1596-
// We use the raw boolean because we have a lock on all events.
15971596
auto lPredSignaledAny = [nEvents, &pEvents, &iEventIndex]
15981597
{
15991598
for (int i = 0; i < nEvents; i++)
16001599
{
16011600
if (pEvents[i]->m_bSignaled)
16021601
{
1603-
iEventIndex = i;
1602+
iEventIndex = i;
16041603
return true;
16051604
}
16061605
}
@@ -1622,11 +1621,27 @@ int ThreadWaitForEvents(int nEvents, CThreadEvent* const* pEvents, bool bWaitAll
16221621
return false;
16231622
};
16241623

1625-
if (lPredSignaledAny() || lPredSignaledAnyCheck())
1624+
// Most optimistic case: we have signal state synced already.
1625+
for (int i = 0; i < 20; i++)
1626+
{
1627+
if (lPredSignaledAny())
1628+
{
1629+
if (pEvents[iEventIndex]->m_bAutoReset)
1630+
{
1631+
pEvents[iEventIndex]->Reset();
1632+
}
1633+
bRet = true;
1634+
break;
1635+
}
1636+
ThreadPause();
1637+
}
1638+
// Second optimistic case: we can do an initial check to minimize contention
1639+
if (!bRet && lPredSignaledAnyCheck())
16261640
{
1641+
// Check handles auto reset
16271642
bRet = true;
16281643
}
1629-
else
1644+
else if (!bRet)
16301645
{
16311646
// Lock all at the same time, to prevent race conditions.
16321647
// Before, this was implemented by locking and checking for each one after the other, which caused a race condition.

0 commit comments

Comments
 (0)