Files
kinect-bot 0af22f1783
ci / Linux C++ core (cmake + ctest) (push) Canceled after 0s
ci / Python tracker (pytest) (push) Canceled after 0s
feat(calibration,contract,tracker): T-pose calibration + seqlock fix + articulated-depth wiring (wave 8a; todos 11,20,21 done)
2026-11-25 05:47:19 -05:00

36 lines
1.1 KiB
C++

#include "contract/contract.h"
namespace nui::contract {
int contract_version() { return static_cast<int>(kContractVersion); }
void publish_frame(FrameContract& contract, const FrameData& data) {
const uint64_t next_sequence = contract.published_sequence + 1;
FrameSlot& slot = contract.slots[next_sequence % kFrameSlotCount];
// Seqlock parity: odd while writing, even once `data` is fully written.
++slot.sequence;
slot.data = data;
++slot.sequence;
contract.published_sequence = next_sequence;
}
void read_latest_frame(const FrameContract& contract, FrameData& out) {
for (;;) {
const uint64_t published = contract.published_sequence;
const FrameSlot& slot = contract.slots[published % kFrameSlotCount];
const uint64_t seq_before = slot.sequence;
if (seq_before & 1) {
continue; // mid-write
}
FrameData snapshot = slot.data;
const uint64_t seq_after = slot.sequence;
if (seq_after == seq_before &&
contract.published_sequence == published) {
out = snapshot;
return;
}
}
}
} // namespace nui::contract