github.com/SagerNet/gvisor@v0.0.0-20210707092255-7731c139d75c/pkg/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 // +build !arm,!mips,!386 16 17 package atomicbitops 18 19 import "sync/atomic" 20 21 // AlignedAtomicInt64 is an atomic int64 that is guaranteed to be 64-bit 22 // aligned, even on 32-bit systems. On most architectures, it's just a regular 23 // int64. 24 // 25 // See aligned_unsafe.go in this directory for justification. 26 // 27 // +stateify savable 28 type AlignedAtomicInt64 struct { 29 value int64 30 } 31 32 // Load is analagous to atomic.LoadInt64. 33 func (aa *AlignedAtomicInt64) Load() int64 { 34 return atomic.LoadInt64(&aa.value) 35 } 36 37 // Store is analagous to atomic.StoreInt64. 38 func (aa *AlignedAtomicInt64) Store(v int64) { 39 atomic.StoreInt64(&aa.value, v) 40 } 41 42 // Add is analagous to atomic.AddInt64. 43 func (aa *AlignedAtomicInt64) Add(v int64) int64 { 44 return atomic.AddInt64(&aa.value, v) 45 } 46 47 // AlignedAtomicUint64 is an atomic uint64 that is guaranteed to be 64-bit 48 // aligned, even on 32-bit systems. On most architectures, it's just a regular 49 // uint64. 50 // 51 // See aligned_unsafe.go in this directory for justification. 52 // 53 // +stateify savable 54 type AlignedAtomicUint64 struct { 55 value uint64 56 } 57 58 // Load is analagous to atomic.LoadUint64. 59 func (aa *AlignedAtomicUint64) Load() uint64 { 60 return atomic.LoadUint64(&aa.value) 61 } 62 63 // Store is analagous to atomic.StoreUint64. 64 func (aa *AlignedAtomicUint64) Store(v uint64) { 65 atomic.StoreUint64(&aa.value, v) 66 } 67 68 // Add is analagous to atomic.AddUint64. 69 func (aa *AlignedAtomicUint64) Add(v uint64) uint64 { 70 return atomic.AddUint64(&aa.value, v) 71 }