[idd] common: centralize nonzero sequences

This commit is contained in:
Geoffrey McRae
2026-08-13 21:44:07 +10:00
parent cd6bcc3a41
commit 5d12ee4bce
11 changed files with 97 additions and 62 deletions

View File

@@ -21,6 +21,7 @@
#include "transport/CControlHub.h"
#include "CDebug.h"
#include "Seq.h"
#include <algorithm>
#include <cstring>
@@ -105,12 +106,6 @@ DWORD WINAPI CControlHub::WorkerProc(void * opaque)
return 0;
}
uint64_t CControlHub::NextRevision(uint64_t revision)
{
++revision;
return revision ? revision : 1;
}
bool CControlHub::TokenMatches(
const Sink& sink, const ControlToken& token)
{
@@ -159,12 +154,12 @@ bool CControlHub::Add(
selected->deliveredShape = 0;
selected->deliveredTransform = 0;
memset(selected->retryAt, 0, sizeof(selected->retryAt));
selected->nextWork = 0;
selected->bindingSerial = NextRevision(selected->bindingSerial);
selected->replaySerial = NextRevision(selected->replaySerial);
selected->calling = false;
selected->active = false;
selected->failed = false;
selected->nextWork = 0;
selected->bindingSerial = Seq::Next(selected->bindingSerial);
selected->replaySerial = Seq::Next(selected->replaySerial);
selected->calling = false;
selected->active = false;
selected->failed = false;
selected->failurePending = false;
}
control.SetControlEvents(this, token);
@@ -174,10 +169,10 @@ bool CControlHub::Add(
if (selected->target == &control && selected->backend == backend &&
selected->epoch == epoch && selected->reserved && !selected->failed)
{
selected->replaySerial = NextRevision(selected->replaySerial);
selected->active = true;
selected->reserved = false;
attached = true;
selected->replaySerial = Seq::Next(selected->replaySerial);
selected->active = true;
selected->reserved = false;
attached = true;
}
}
if (!attached)
@@ -285,7 +280,7 @@ void CControlHub::OnControlReplay(const ControlToken& token)
sink.deliveredPosition = 0;
sink.deliveredShape = 0;
sink.deliveredTransform = 0;
sink.replaySerial = NextRevision(sink.replaySerial);
sink.replaySerial = Seq::Next(sink.replaySerial);
memset(sink.retryAt, 0, sizeof(sink.retryAt));
SetEvent(sink.wake);
return;
@@ -529,14 +524,14 @@ void CControlHub::SendCursor(const IDARG_OUT_QUERY_HWCURSOR& info,
m_state.cursor.X = info.X;
m_state.cursor.Y = info.Y;
m_state.sdrWhiteLevel = sdrWhiteLevel;
m_state.positionRevision = NextRevision(m_state.positionRevision);
m_state.positionRevision = Seq::Next(m_state.positionRevision);
if (shape)
{
m_state.cursor.IsCursorShapeUpdated = info.IsCursorShapeUpdated;
m_state.cursor.CursorShapeInfo = info.CursorShapeInfo;
m_state.cursorData = std::move(cursorData);
m_state.shapeRevision = NextRevision(m_state.shapeRevision);
m_state.cursorData = std::move(cursorData);
m_state.shapeRevision = Seq::Next(m_state.shapeRevision);
}
}
@@ -550,8 +545,8 @@ void CControlHub::SetColorTransform(
{
{
CSRWExclusiveLock lock(m_stateLock);
m_state.transform = std::move(transform);
m_state.transformRevision = NextRevision(m_state.transformRevision);
m_state.transform = std::move(transform);
m_state.transformRevision = Seq::Next(m_state.transformRevision);
}
WakeAll(WorkType::TRANSFORM);
}

View File

@@ -104,7 +104,6 @@ private:
bool m_valid = false;
static DWORD WINAPI WorkerProc(void * opaque);
static uint64_t NextRevision(uint64_t revision);
static bool TokenMatches(const Sink& sink, const ControlToken& token);
bool BeginWork(Sink& sink, Work& work, DWORD& wait);

View File

@@ -21,6 +21,7 @@
#include "transport/CInputHub.h"
#include "input/IInputSink.h"
#include "Seq.h"
static bool SameClient(const SourceKey& left, const SourceKey& right)
{
@@ -510,9 +511,7 @@ void CInputHub::InvalidateInteraction()
void CInputHub::AdvanceInteractionSerial()
{
++m_interactionSerial;
if (!m_interactionSerial)
++m_interactionSerial;
Seq::Inc(m_interactionSerial);
}
bool CInputHub::CheckState()

View File

@@ -20,6 +20,8 @@
#include "transport/CRecoveryHub.h"
#include "Seq.h"
#include <Windows.h>
namespace
@@ -99,16 +101,6 @@ bool CRecoveryHub::ActionMatchesLocked(
action.active == m_operation.action.active;
}
uint64_t CRecoveryHub::NextNonzero(uint64_t& value)
{
uint64_t result = value++;
if (!result)
result = value++;
if (!value)
++value;
return result;
}
uint32_t CRecoveryHub::NextSerial()
{
uint32_t result = m_nextSerial;
@@ -134,7 +126,7 @@ void CRecoveryHub::SetWaitingLocked(Request& request,
request.source = source;
request.session = session;
request.operation = operation;
request.sequence = NextNonzero(m_nextSequence);
request.sequence = Seq::Take(m_nextSequence);
request.serial = serial;
request.active = active;
request.state = SlotState::WAITING;
@@ -264,9 +256,9 @@ RecoveryAdmission CRecoveryHub::Submit(const SourceKey& source,
}
m_operation = Operation {};
m_operation.phase = OperationPhase::IN_FLIGHT;
m_operation.id = NextNonzero(m_nextOperation);
m_operation.action.route = NextNonzero(m_nextRoute);
m_operation.phase = OperationPhase::IN_FLIGHT;
m_operation.id = Seq::Take(m_nextOperation);
m_operation.action.route = Seq::Take(m_nextRoute);
m_operation.action.session = m_session;
m_operation.action.serial = NextSerial();
m_operation.action.active = active;

View File

@@ -106,7 +106,6 @@ private:
unsigned FindSourceLocked(const SourceKey& source) const;
unsigned FindFreeLocked() const;
bool ActionMatchesLocked(const RecoveryAction& action) const;
uint64_t NextNonzero(uint64_t& value);
uint32_t NextSerial();
void ClearRequestLocked(Request& request);
void SetWaitingLocked(Request& request, const SourceKey& source,

View File

@@ -21,6 +21,7 @@
#include "transport/CTransportManager.h"
#include "CDebug.h"
#include "Seq.h"
#include <Windows.h>
#include <new>
@@ -737,9 +738,7 @@ void CTransportManager::RetryEntry(Entry& entry, uint64_t now,
entry.inputAbsent = false;
entry.frameAbsent = false;
entry.serviceRetryAt = 0;
++entry.epoch;
if (!entry.epoch)
++entry.epoch;
Seq::Inc(entry.epoch);
}
if (OpenEntry(entry) != OpenResult::SUCCESS)

View File

@@ -23,6 +23,7 @@
#include "transport/lgmp/CLGMPHost.h"
#include "CDebug.h"
#include "CSRWLock.h"
#include "Seq.h"
#include "common/KVMFRInput.h"
#include "common/LGMPConfig.h"
@@ -127,17 +128,16 @@ void CLGMPInputTransport::UpdateTargetState(
const InputTargetState& state)
{
CSRWExclusiveLock lock(m_statusLock);
if (state.state == m_targetState.state &&
state.available == m_targetState.available &&
state.owned == m_targetState.owned &&
state.owner.client == m_targetState.owner.client &&
if (state.state == m_targetState.state &&
state.available == m_targetState.available &&
state.owned == m_targetState.owned &&
state.owner.client == m_targetState.owner.client &&
state.owner.generation == m_targetState.owner.generation)
return;
if (state.state != m_targetState.state)
{
if (++m_endpointGeneration == 0)
++m_endpointGeneration;
Seq::Inc(m_endpointGeneration);
}
m_targetState = state;
m_statusDirty = true;
@@ -183,9 +183,7 @@ bool CLGMPInputTransport::PublishStatus()
status.maxButtons = KVMFR_INPUT_MOUSE_BUTTON_COUNT;
memcpy(lgmpHostMemPtr(memory), &status, sizeof(status));
uint32_t serial = m_statusSerial + 1;
if (!serial)
++serial;
const uint32_t serial = Seq::Next(m_statusSerial);
const LGMP_STATUS result = lgmpHostQueuePost(m_queue, serial, memory);
if (result == LGMP_OK)
{
@@ -263,8 +261,7 @@ bool CLGMPInputTransport::Start(IInputTarget& target)
{
CSRWExclusiveLock statusLock(m_statusLock);
m_targetState = target.GetState({});
if (++m_endpointGeneration == 0)
++m_endpointGeneration;
Seq::Inc(m_endpointGeneration);
m_statusDirty = true;
}
m_statusFailed.store(false, std::memory_order_release);
@@ -505,9 +502,7 @@ bool CLGMPInputTransport::ProcessMessage(
return true;
}
uint32_t expectedSequence = m_ownerSequence + 1;
if (!expectedSequence)
expectedSequence = 1;
const uint32_t expectedSequence = Seq::Next(m_ownerSequence);
if (message.sequence != expectedSequence)
{
++m_statistics.sequenceErrors;