gvisor.dev/gvisor@v0.0.0-20240520182842-f9d4d51c7e0f/vdso/seqlock.h (about) 1 // Copyright 2018 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 // Low level raw interfaces to the sequence counter used by the VDSO. 16 #ifndef VDSO_SEQLOCK_H_ 17 #define VDSO_SEQLOCK_H_ 18 19 #include <stdint.h> 20 21 #include "vdso/barrier.h" 22 #include "vdso/compiler.h" 23 24 namespace vdso { 25 26 inline int32_t read_seqcount_begin(const uint64_t* s) { 27 uint64_t seq = *s; 28 read_barrier(); 29 return seq & ~1; 30 } 31 32 inline int read_seqcount_retry(const uint64_t* s, uint64_t seq) { 33 read_barrier(); 34 return unlikely(*s != seq); 35 } 36 37 } // namespace vdso 38 39 #endif // VDSO_SEQLOCK_H_