Blame src/win/atomicops-inl.h

Packit b5b901
/* Copyright Joyent, Inc. and other Node contributors. All rights reserved.
Packit b5b901
 *
Packit b5b901
 * Permission is hereby granted, free of charge, to any person obtaining a copy
Packit b5b901
 * of this software and associated documentation files (the "Software"), to
Packit b5b901
 * deal in the Software without restriction, including without limitation the
Packit b5b901
 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
Packit b5b901
 * sell copies of the Software, and to permit persons to whom the Software is
Packit b5b901
 * furnished to do so, subject to the following conditions:
Packit b5b901
 *
Packit b5b901
 * The above copyright notice and this permission notice shall be included in
Packit b5b901
 * all copies or substantial portions of the Software.
Packit b5b901
 *
Packit b5b901
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
Packit b5b901
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
Packit b5b901
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
Packit b5b901
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
Packit b5b901
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
Packit b5b901
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
Packit b5b901
 * IN THE SOFTWARE.
Packit b5b901
 */
Packit b5b901
Packit b5b901
#ifndef UV_WIN_ATOMICOPS_INL_H_
Packit b5b901
#define UV_WIN_ATOMICOPS_INL_H_
Packit b5b901
Packit b5b901
#include "uv.h"
Packit b5b901
#include "internal.h"
Packit b5b901
Packit b5b901
Packit b5b901
/* Atomic set operation on char */
Packit b5b901
#ifdef _MSC_VER /* MSVC */
Packit b5b901
Packit b5b901
/* _InterlockedOr8 is supported by MSVC on x32 and x64. It is slightly less
Packit b5b901
 * efficient than InterlockedExchange, but InterlockedExchange8 does not exist,
Packit b5b901
 * and interlocked operations on larger targets might require the target to be
Packit b5b901
 * aligned. */
Packit b5b901
#pragma intrinsic(_InterlockedOr8)
Packit b5b901
Packit b5b901
static char INLINE uv__atomic_exchange_set(char volatile* target) {
Packit b5b901
  return _InterlockedOr8(target, 1);
Packit b5b901
}
Packit b5b901
Packit b5b901
#else /* GCC */
Packit b5b901
Packit b5b901
/* Mingw-32 version, hopefully this works for 64-bit gcc as well. */
Packit b5b901
static inline char uv__atomic_exchange_set(char volatile* target) {
Packit b5b901
  const char one = 1;
Packit b5b901
  char old_value;
Packit b5b901
  __asm__ __volatile__ ("lock xchgb %0, %1\n\t"
Packit b5b901
                        : "=r"(old_value), "=m"(*target)
Packit b5b901
                        : "0"(one), "m"(*target)
Packit b5b901
                        : "memory");
Packit b5b901
  return old_value;
Packit b5b901
}
Packit b5b901
Packit b5b901
#endif
Packit b5b901
Packit b5b901
#endif /* UV_WIN_ATOMICOPS_INL_H_ */