feat(contract,spikes): frozen IPC data contract + Linux/Windows spikes (wave 2)
This commit is contained in:
1 parent
b38c7bcd82
commit
e6d4e510d3
11 files changed
+1523
-14
No files matched your search
@@ -2,9 +2,33 @@
|
||||
|
||||
namespace nui::contract {
|
||||
|
||||
int contract_version() {
|
||||
// v0: scaffold placeholder; frozen layout defined in todo 2.
|
||||
return 0;
|
||||
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 = next_sequence * 2 - 1;
|
||||
slot.data = data;
|
||||
slot.sequence = next_sequence * 2;
|
||||
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 != published * 2) {
|
||||
continue; // mid-write (odd) or stale slot; retry against the current publish
|
||||
}
|
||||
FrameData snapshot = slot.data;
|
||||
const uint64_t seq_after = slot.sequence;
|
||||
if (seq_after == seq_before) {
|
||||
out = snapshot;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace nui::contract
|
||||
Reference in new issue
Block a user