inet.af/netstack@v0.0.0-20220214151720-7585b01ddccf/atomicbitops/aligned_64bit.go (about) 1 // Copyright 2021 The gVisor Authors. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 //go:build !arm && !mips && !mipsle && !386 16 // +build !arm,!mips,!mipsle,!386 17 18 package atomicbitops 19 20 import "sync/atomic" 21 22 // AlignedAtomicInt64 is an atomic int64 that is guaranteed to be 64-bit 23 // aligned, even on 32-bit systems. On most architectures, it's just a regular 24 // int64. 25 // 26 // See aligned_unsafe.go in this directory for justification. 27 // 28 // +stateify savable 29 type AlignedAtomicInt64 struct { 30 value int64 31 } 32 33 // Load is analagous to atomic.LoadInt64. 34 func (aa *AlignedAtomicInt64) Load() int64 { 35 return atomic.LoadInt64(&aa.value) 36 } 37 38 // Store is analagous to atomic.StoreInt64. 39 func (aa *AlignedAtomicInt64) Store(v int64) { 40 atomic.StoreInt64(&aa.value, v) 41 } 42 43 // Add is analagous to atomic.AddInt64. 44 func (aa *AlignedAtomicInt64) Add(v int64) int64 { 45 return atomic.AddInt64(&aa.value, v) 46 } 47 48 // AlignedAtomicUint64 is an atomic uint64 that is guaranteed to be 64-bit 49 // aligned, even on 32-bit systems. On most architectures, it's just a regular 50 // uint64. 51 // 52 // See aligned_unsafe.go in this directory for justification. 53 // 54 // +stateify savable 55 type AlignedAtomicUint64 struct { 56 value uint64 57 } 58 59 // Load is analagous to atomic.LoadUint64. 60 func (aa *AlignedAtomicUint64) Load() uint64 { 61 return atomic.LoadUint64(&aa.value) 62 } 63 64 // Store is analagous to atomic.StoreUint64. 65 func (aa *AlignedAtomicUint64) Store(v uint64) { 66 atomic.StoreUint64(&aa.value, v) 67 } 68 69 // Add is analagous to atomic.AddUint64. 70 func (aa *AlignedAtomicUint64) Add(v uint64) uint64 { 71 return atomic.AddUint64(&aa.value, v) 72 }