import { registerSync } from './reconstruct.ts'; export class BoolAtomic { static readonly byteSize = 1; static readonly byteAlignment = 1; private readonly view: Uint8Array; constructor(buffer?: SharedArrayBuffer, byteOffset?: number) { const buf = buffer ?? new SharedArrayBuffer(1); const offset = byteOffset ?? 0; this.view = new Uint8Array(buf, offset, 1); } load(): boolean { return Atomics.load(this.view, 0) !== 0; } store(value: boolean): void { Atomics.store(this.view, 0, value ? 1 : 0); } and(value: boolean): boolean { return Atomics.and(this.view, 0, value ? 1 : 0) !== 0; } or(value: boolean): boolean { return Atomics.or(this.view, 0, value ? 1 : 0) !== 0; } xor(value: boolean): boolean { return Atomics.xor(this.view, 0, value ? 1 : 0) !== 0; } exchange(value: boolean): boolean { return Atomics.exchange(this.view, 0, value ? 1 : 0) !== 0; } compareExchange(expected: boolean, replacement: boolean): boolean { return Atomics.compareExchange(this.view, 0, expected ? 1 : 0, replacement ? 1 : 0) !== 0; } [Symbol.for('moroutine.shared')](): { tag: string; buffer: SharedArrayBuffer; byteOffset: number } { return { tag: 'BoolAtomic', buffer: this.view.buffer as SharedArrayBuffer, byteOffset: this.view.byteOffset }; } } registerSync('BoolAtomic', BoolAtomic);