atomicops.h revision eb525c5499e34cc9c4b825d6d9e75bb07cc06ace
1/* Copyright 2013 The Chromium Authors. All rights reserved. 2 * Use of this source code is governed by a BSD-style license that can be 3 * found in the LICENSE file. 4 */ 5 6#ifndef LIBRARIES_SDK_UTIL_ATOMICOPS_H_ 7#define LIBRARIES_SDK_UTIL_ATOMICOPS_H_ 8 9#ifndef WIN32 10 11#include <stdint.h> 12typedef int32_t Atomic32; 13 14#ifndef __llvm__ 15static inline void MemoryBarrier() { 16 __sync_synchronize(); 17} 18#endif 19 20inline Atomic32 AtomicAddFetch(volatile Atomic32* ptr, Atomic32 value) { 21 return __sync_add_and_fetch(ptr, value); 22} 23 24#else 25 26#include <windows.h> 27 28/* Undefine many Windows.h macros that we almost certainly do not want. */ 29#undef min 30#undef max 31#undef PostMessage 32#undef interface 33 34typedef long Atomic32; 35 36/* Windows.h already defines a MemoryBarrier macro. */ 37 38inline Atomic32 AtomicAddFetch(volatile Atomic32* ptr, Atomic32 value) { 39 return InterlockedExchangeAdd(ptr, value); 40} 41#endif 42 43 44#endif /* LIBRARIES_SDK_UTIL_ATOMICOPS_H_ */ 45