Path: blob/master/Utilities/cmlibuv/src/win/atomicops-inl.h
3153 views
/* Copyright Joyent, Inc. and other Node contributors. All rights reserved.1*2* Permission is hereby granted, free of charge, to any person obtaining a copy3* of this software and associated documentation files (the "Software"), to4* deal in the Software without restriction, including without limitation the5* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or6* sell copies of the Software, and to permit persons to whom the Software is7* furnished to do so, subject to the following conditions:8*9* The above copyright notice and this permission notice shall be included in10* all copies or substantial portions of the Software.11*12* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR13* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,14* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE15* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER16* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING17* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS18* IN THE SOFTWARE.19*/2021#ifndef UV_WIN_ATOMICOPS_INL_H_22#define UV_WIN_ATOMICOPS_INL_H_2324#include "uv.h"25#include "internal.h"262728/* Atomic set operation on char */29#ifdef _MSC_VER /* MSVC */3031/* _InterlockedOr8 is supported by MSVC on x32 and x64. It is slightly less32* efficient than InterlockedExchange, but InterlockedExchange8 does not exist,33* and interlocked operations on larger targets might require the target to be34* aligned. */35#pragma intrinsic(_InterlockedOr8)3637static char INLINE uv__atomic_exchange_set(char volatile* target) {38return _InterlockedOr8(target, 1);39}4041#else /* GCC, Clang in mingw mode */4243static inline char uv__atomic_exchange_set(char volatile* target) {44#if defined(__i386__) || defined(__x86_64__)45/* Mingw-32 version, hopefully this works for 64-bit gcc as well. */46const char one = 1;47char old_value;48__asm__ __volatile__ ("lock xchgb %0, %1\n\t"49: "=r"(old_value), "=m"(*target)50: "0"(one), "m"(*target)51: "memory");52return old_value;53#else54return __sync_fetch_and_or(target, 1);55#endif56}5758#endif5960#endif /* UV_WIN_ATOMICOPS_INL_H_ */616263