1 // Protocol Buffers - Google's data interchange format
2 // Copyright 2012 Google Inc. All rights reserved.
3 // https://developers.google.com/protocol-buffers/
5 // Redistribution and use in source and binary forms, with or without
6 // modification, are permitted provided that the following conditions are
9 // * Redistributions of source code must retain the above copyright
10 // notice, this list of conditions and the following disclaimer.
11 // * Redistributions in binary form must reproduce the above
12 // copyright notice, this list of conditions and the following disclaimer
13 // in the documentation and/or other materials provided with the
15 // * Neither the name of Google Inc. nor the names of its
16 // contributors may be used to endorse or promote products derived from
17 // this software without specific prior written permission.
19 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 // This file is an internal atomic implementation, use atomicops.h instead.
33 #ifndef GOOGLE_PROTOBUF_ATOMICOPS_INTERNALS_X86_MSVC_H_
34 #define GOOGLE_PROTOBUF_ATOMICOPS_INTERNALS_X86_MSVC_H_
40 inline Atomic32 NoBarrier_AtomicIncrement(volatile Atomic32* ptr,
42 return Barrier_AtomicIncrement(ptr, increment);
45 #if !(defined(_MSC_VER) && _MSC_VER >= 1400)
46 #error "We require at least vs2005 for MemoryBarrier"
49 inline Atomic32 Acquire_CompareAndSwap(volatile Atomic32* ptr,
52 return NoBarrier_CompareAndSwap(ptr, old_value, new_value);
55 inline Atomic32 Release_CompareAndSwap(volatile Atomic32* ptr,
58 return NoBarrier_CompareAndSwap(ptr, old_value, new_value);
61 inline void NoBarrier_Store(volatile Atomic32* ptr, Atomic32 value) {
65 inline void Acquire_Store(volatile Atomic32* ptr, Atomic32 value) {
66 NoBarrier_AtomicExchange(ptr, value);
67 // acts as a barrier in this implementation
70 inline void Release_Store(volatile Atomic32* ptr, Atomic32 value) {
71 *ptr = value; // works w/o barrier for current Intel chips as of June 2005
72 // See comments in Atomic64 version of Release_Store() below.
75 inline Atomic32 NoBarrier_Load(volatile const Atomic32* ptr) {
79 inline Atomic32 Acquire_Load(volatile const Atomic32* ptr) {
80 Atomic32 value = *ptr;
84 inline Atomic32 Release_Load(volatile const Atomic32* ptr) {
91 // 64-bit low-level operations on 64-bit platform.
93 inline Atomic64 NoBarrier_AtomicIncrement(volatile Atomic64* ptr,
95 return Barrier_AtomicIncrement(ptr, increment);
98 inline void NoBarrier_Store(volatile Atomic64* ptr, Atomic64 value) {
102 inline void Acquire_Store(volatile Atomic64* ptr, Atomic64 value) {
103 NoBarrier_AtomicExchange(ptr, value);
104 // acts as a barrier in this implementation
107 inline void Release_Store(volatile Atomic64* ptr, Atomic64 value) {
108 *ptr = value; // works w/o barrier for current Intel chips as of June 2005
110 // When new chips come out, check:
111 // IA-32 Intel Architecture Software Developer's Manual, Volume 3:
112 // System Programming Guide, Chatper 7: Multiple-processor management,
113 // Section 7.2, Memory Ordering.
115 // http://developer.intel.com/design/pentium4/manuals/index_new.htm
118 inline Atomic64 NoBarrier_Load(volatile const Atomic64* ptr) {
122 inline Atomic64 Acquire_Load(volatile const Atomic64* ptr) {
123 Atomic64 value = *ptr;
127 inline Atomic64 Release_Load(volatile const Atomic64* ptr) {
132 inline Atomic64 Acquire_CompareAndSwap(volatile Atomic64* ptr,
134 Atomic64 new_value) {
135 return NoBarrier_CompareAndSwap(ptr, old_value, new_value);
138 inline Atomic64 Release_CompareAndSwap(volatile Atomic64* ptr,
140 Atomic64 new_value) {
141 return NoBarrier_CompareAndSwap(ptr, old_value, new_value);
144 #endif // defined(_WIN64)
146 } // namespace internal
147 } // namespace protobuf
148 } // namespace google
150 #endif // GOOGLE_PROTOBUF_ATOMICOPS_INTERNALS_X86_MSVC_H_