Debian Codegraph @

pathrs-lite/internal/gocompat/gocompat_atomic_unsupported.go

raw
1 // SPDX-License-Identifier: BSD-3-Clause
2
3 //go:build linux && !go1.19
4
5 // Copyright (C) 2024-2025 SUSE LLC. All rights reserved.
6 // Use of this source code is governed by a BSD-style
7 // license that can be found in the LICENSE file.
8
9 package gocompat
10
11 import (
12 "sync/atomic"
13 )
14
15 // noCopy may be added to structs which must not be copied
16 // after the first use.
17 //
18 // See https://golang.org/issues/8005#issuecomment-190753527
19 // for details.
20 //
21 // Note that it must not be embedded, due to the Lock and Unlock methods.
22 type noCopy struct{}
23
24 // Lock is a no-op used by -copylocks checker from `go vet`.
25 func (*noCopy) Lock() {}
26
27 // b32 returns a uint32 0 or 1 representing b.
28 func b32(b bool) uint32 {
29 if b {
30 return 1
31 }
32 return 0
33 }
34
35 // A Bool is an atomic boolean value.
36 // The zero value is false.
37 //
38 // Bool must not be copied after first use.
39 type Bool struct {
40 _ noCopy
41 v uint32
42 }
43
44 // Load atomically loads and returns the value stored in x.
45 func (x *Bool) Load() bool { return atomic.LoadUint32(&x.v) != 0 }
46
47 // Store atomically stores val into x.
48 func (x *Bool) Store(val bool) { atomic.StoreUint32(&x.v, b32(val)) }