From 64f14604093ba4f5c84ec87ede28b3281d626c61 Mon Sep 17 00:00:00 2001 From: Wojciech Malota-Wojcik Date: Tue, 3 Dec 2024 09:02:09 +0100 Subject: [PATCH] Update state by one bit --- types/types.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/types/types.go b/types/types.go index ec72818..6b19011 100644 --- a/types/types.go +++ b/types/types.go @@ -20,15 +20,19 @@ const ( // State enumerates possible slot states. type State byte +// State values are intentionally chosen in a way where following states differ by one bit only. +// It is designed this way to guarantee that goroutines read (maybe outdated but) valid state values. +// This hack is probably not needed because x86 CPUs guarantee write consistency on DWORD level, +// but this business is crazy and nothing is going to surprise me. const ( // StateFree means slot is free. - StateFree State = iota + StateFree State = 0 // StateData means slot contains data. - StateData + StateData State = 1 // StatePointer means slot contains pointer. - StatePointer + StatePointer State = 3 ) // Flags defines pointer flags.