aboutsummaryrefslogtreecommitdiff
path: root/src/hash
diff options
context:
space:
mode:
authorcuiweixie <cuiweixie@gmail.com>2022-08-27 11:11:08 +0800
committerGopher Robot <gobot@golang.org>2022-09-02 06:06:53 +0000
commit134cd34c07862aa8618e25d1d1279b4fd127c512 (patch)
treed49ea3c836feafedb8df4eb4f39ce8eb46eb2775 /src/hash
parent8e35910640bd190103d99d994d54b738e619c858 (diff)
downloadgo-134cd34c07862aa8618e25d1d1279b4fd127c512.tar.gz
go-134cd34c07862aa8618e25d1d1279b4fd127c512.zip
hash: convert haveCastagnoli to atomic type
Change-Id: I313fff5684d89ee737572d11b1b697c5575866a8 Reviewed-on: https://go-review.googlesource.com/c/go/+/426083 Reviewed-by: Keith Randall <khr@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Michael Pratt <mpratt@google.com> Run-TryBot: Keith Randall <khr@golang.org> Auto-Submit: Keith Randall <khr@golang.org> Reviewed-by: Keith Randall <khr@google.com>
Diffstat (limited to 'src/hash')
-rw-r--r--src/hash/crc32/crc32.go8
1 files changed, 4 insertions, 4 deletions
diff --git a/src/hash/crc32/crc32.go b/src/hash/crc32/crc32.go
index 1a24d980cc..4fcb168e6e 100644
--- a/src/hash/crc32/crc32.go
+++ b/src/hash/crc32/crc32.go
@@ -78,7 +78,7 @@ var castagnoliTable *Table
var castagnoliTable8 *slicing8Table
var updateCastagnoli func(crc uint32, p []byte) uint32
var castagnoliOnce sync.Once
-var haveCastagnoli uint32
+var haveCastagnoli atomic.Bool
func castagnoliInit() {
castagnoliTable = simpleMakeTable(Castagnoli)
@@ -94,7 +94,7 @@ func castagnoliInit() {
}
}
- atomic.StoreUint32(&haveCastagnoli, 1)
+ haveCastagnoli.Store(true)
}
// IEEETable is the table for the IEEE polynomial.
@@ -208,7 +208,7 @@ func readUint32(b []byte) uint32 {
// Update returns the result of adding the bytes in p to the crc.
func Update(crc uint32, tab *Table, p []byte) uint32 {
switch {
- case atomic.LoadUint32(&haveCastagnoli) != 0 && tab == castagnoliTable:
+ case haveCastagnoli.Load() && tab == castagnoliTable:
return updateCastagnoli(crc, p)
case tab == IEEETable:
// Unfortunately, because IEEETable is exported, IEEE may be used without a
@@ -222,7 +222,7 @@ func Update(crc uint32, tab *Table, p []byte) uint32 {
func (d *digest) Write(p []byte) (n int, err error) {
switch {
- case atomic.LoadUint32(&haveCastagnoli) != 0 && d.tab == castagnoliTable:
+ case haveCastagnoli.Load() && d.tab == castagnoliTable:
d.crc = updateCastagnoli(d.crc, p)
case d.tab == IEEETable:
// We only create digest objects through New() which takes care of