cheatah
Source

stdlib/memory/policy.hpp

1// Copyright (c) 2026 BigBrain LLC. MIT-licensed (see LICENSE).
2// Original work; see ACKNOWLEDGMENTS.md for the open-source ideas we build upon.
3#pragma once
5/**
6 * @file policy.hpp
7 * @brief `memory` scheduling policy + the immediate-write priority constant.
8 */
10#include <cstdint>
12namespace cheatah::memory {
14/// How the owner schedules pending writes against reads. Chosen at construction (a stored value).
15/// NOTE: the current coordinator is writer-preferring under BOTH values — a renewing reader waits
16/// until the write queue is empty (today both behave as `writes_first`); `interleave` records the
17/// declared fairness intent.
18enum class policy : std::uint8_t {
19 interleave, ///< (default) readers renew *between* writes; writers + waiting readers are fair.
20 writes_first, ///< drain the ENTIRE write queue before renewing any reader (owner's declared choice).
21};
22/// Shorthand for `policy::interleave` — readers renew between writes (the default, fair) policy.
23inline constexpr policy interleave = policy::interleave;
24/// Shorthand for `policy::writes_first` — drain the whole write queue before renewing any reader.
25inline constexpr policy writes_first = policy::writes_first;
27/// The readable spelling of an immediate-write priority. Any negative priority is immediate; this is
28/// simply its name: `x.rwrite<memory::immediate>()` reads better than `x.rwrite<-1>()`.
29inline constexpr long long immediate = -1;
31} // namespace cheatah::memory