okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
a8a51b280
main
1#pragma once 2#include <chrono> 3#include <cstdlib> 4// Only the pipeline owner thread calls these chain methods. The state belongs 5// to its current MtpDrafter and is reset before every chain and request. No 6// class definition or layout differs from the normal engine's archives. 7namespace strata::private_demand { 8struct State { 9const void * owner = nullptr ; 10bool enabled = false,final = false; 11int submitted = 0 ,target = 0 ,limit = 0 ; 12long long chains = 0 ,requested = 0 ,actual = 0 ,continuations = 0 ,dead = 0 ; 13bool metrics = false; 14long long last_ready_ns = 0 ,reaction_ns = 0 ,submit_ns = 0 ,max_reaction_ns = 0 ; 15int ordinal = 0 ,T = 0 ,a = 0 ,n_force = 0 ; 16long long p = 0 ; 17int tokens [8 ]= {},force [8 ]= {}; 18}; 19inline long long now_ns () { 20return std::chrono::duration_cast < std::chrono::nanoseconds > ( 21 std::chrono::steady_clock::now ().time_since_epoch ()).count (); 22} 23inline State & state () {static thread_localState s ;return s ; } 24inline State * get (const void * p ) { 25auto & s = state ();return s .enabled && s .owner == p ?& s :nullptr ; 26} 27inline void begin (const void * p ,bool on ) { 28auto & s = state ();const int ordinal = s .ordinal + int (on );s = State {}; 29s .owner = p ;s .enabled = on ;s .ordinal = ordinal ; 30s .metrics = std::getenv ("STRATA_PRIVATE_MTP_DEMAND_LOG" )|| std::getenv ("STRATA_PRIVATE_MTP_DEMAND_MICRO" ); 31} 32inline bool can_enqueue_s1 (const void * p ) { 33auto * s = get (p );return !s || s -> submitted == 0 || s -> final ; 34} 35inline void drain (const void * p ) { 36if (auto * s = get (p )) {s -> target = s -> limit ;s -> final = true; } 37} 38}// namespace strata::private_demand