Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/sujqvwi/AnonR/anonr.TX.../opt/alt/ruby31/include/ruby
File: atomic.h
#ifndef RUBY_ATOMIC_H /*-*-C++-*-vi:se ft=cpp:*/
[0] Fix | Delete
#define RUBY_ATOMIC_H
[1] Fix | Delete
/**
[2] Fix | Delete
* @file
[3] Fix | Delete
* @author Ruby developers <ruby-core@ruby-lang.org>
[4] Fix | Delete
* @copyright This file is a part of the programming language Ruby.
[5] Fix | Delete
* Permission is hereby granted, to either redistribute and/or
[6] Fix | Delete
* modify this file, provided that the conditions mentioned in the
[7] Fix | Delete
* file COPYING are met. Consult the file for details.
[8] Fix | Delete
* @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are
[9] Fix | Delete
* implementation details. Don't take them as canon. They could
[10] Fix | Delete
* rapidly appear then vanish. The name (path) of this header file
[11] Fix | Delete
* is also an implementation detail. Do not expect it to persist
[12] Fix | Delete
* at the place it is now. Developers are free to move it anywhere
[13] Fix | Delete
* anytime at will.
[14] Fix | Delete
* @note To ruby-core: remember that this header can be possibly
[15] Fix | Delete
* recursively included from extension libraries written in C++.
[16] Fix | Delete
* Do not expect for instance `__VA_ARGS__` is always available.
[17] Fix | Delete
* We assume C99 for ruby itself but we don't assume languages of
[18] Fix | Delete
* extension libraries. They could be written in C++98.
[19] Fix | Delete
* @brief Atomic operations
[20] Fix | Delete
*
[21] Fix | Delete
* Basically, if we could assume either C11 or C++11, these macros are just
[22] Fix | Delete
* redundant. Sadly we cannot. We have to do them ourselves.
[23] Fix | Delete
*/
[24] Fix | Delete
[25] Fix | Delete
#include "ruby/internal/config.h"
[26] Fix | Delete
[27] Fix | Delete
#ifdef STDC_HEADERS
[28] Fix | Delete
# include <stddef.h> /* size_t */
[29] Fix | Delete
#endif
[30] Fix | Delete
[31] Fix | Delete
#ifdef HAVE_SYS_TYPES_H
[32] Fix | Delete
# include <sys/types.h> /* ssize_t */
[33] Fix | Delete
#endif
[34] Fix | Delete
[35] Fix | Delete
#if RBIMPL_COMPILER_SINCE(MSVC, 13, 0, 0)
[36] Fix | Delete
# pragma intrinsic(_InterlockedOr)
[37] Fix | Delete
#elif defined(__sun) && defined(HAVE_ATOMIC_H)
[38] Fix | Delete
# include <atomic.h>
[39] Fix | Delete
#endif
[40] Fix | Delete
[41] Fix | Delete
#include "ruby/assert.h"
[42] Fix | Delete
#include "ruby/backward/2/limits.h"
[43] Fix | Delete
#include "ruby/internal/attr/artificial.h"
[44] Fix | Delete
#include "ruby/internal/attr/noalias.h"
[45] Fix | Delete
#include "ruby/internal/attr/nonnull.h"
[46] Fix | Delete
#include "ruby/internal/compiler_since.h"
[47] Fix | Delete
#include "ruby/internal/cast.h"
[48] Fix | Delete
#include "ruby/internal/value.h"
[49] Fix | Delete
#include "ruby/internal/static_assert.h"
[50] Fix | Delete
#include "ruby/internal/stdbool.h"
[51] Fix | Delete
[52] Fix | Delete
/*
[53] Fix | Delete
* Asserts that your environment supports more than one atomic types. These
[54] Fix | Delete
* days systems tend to have such property (C11 was a standard of decades ago,
[55] Fix | Delete
* right?) but we still support older ones.
[56] Fix | Delete
*/
[57] Fix | Delete
#if defined(__DOXYGEN__) || defined(HAVE_GCC_ATOMIC_BUILTINS) || defined(HAVE_GCC_SYNC_BUILTINS)
[58] Fix | Delete
# define RUBY_ATOMIC_GENERIC_MACRO 1
[59] Fix | Delete
#endif
[60] Fix | Delete
[61] Fix | Delete
/**
[62] Fix | Delete
* Type that is eligible for atomic operations. Depending on your host
[63] Fix | Delete
* platform you might have more than one such type, but we choose one of them
[64] Fix | Delete
* anyways.
[65] Fix | Delete
*/
[66] Fix | Delete
#if defined(__DOXYGEN__)
[67] Fix | Delete
using rb_atomic_t = std::atomic<unsigned>;
[68] Fix | Delete
#elif defined(HAVE_GCC_ATOMIC_BUILTINS)
[69] Fix | Delete
typedef unsigned int rb_atomic_t;
[70] Fix | Delete
#elif defined(HAVE_GCC_SYNC_BUILTINS)
[71] Fix | Delete
typedef unsigned int rb_atomic_t;
[72] Fix | Delete
#elif defined(_WIN32)
[73] Fix | Delete
typedef LONG rb_atomic_t;
[74] Fix | Delete
#elif defined(__sun) && defined(HAVE_ATOMIC_H)
[75] Fix | Delete
typedef unsigned int rb_atomic_t;
[76] Fix | Delete
#else
[77] Fix | Delete
# error No atomic operation found
[78] Fix | Delete
#endif
[79] Fix | Delete
[80] Fix | Delete
/**
[81] Fix | Delete
* Atomically replaces the value pointed by `var` with the result of addition
[82] Fix | Delete
* of `val` to the old value of `var`.
[83] Fix | Delete
*
[84] Fix | Delete
* @param var A variable of ::rb_atomic_t.
[85] Fix | Delete
* @param val Value to add.
[86] Fix | Delete
* @return What was stored in `var` before the addition.
[87] Fix | Delete
* @post `var` holds `var + val`.
[88] Fix | Delete
*/
[89] Fix | Delete
#define RUBY_ATOMIC_FETCH_ADD(var, val) rbimpl_atomic_fetch_add(&(var), (val))
[90] Fix | Delete
[91] Fix | Delete
/**
[92] Fix | Delete
* Atomically replaces the value pointed by `var` with the result of
[93] Fix | Delete
* subtraction of `val` to the old value of `var`.
[94] Fix | Delete
*
[95] Fix | Delete
* @param var A variable of ::rb_atomic_t.
[96] Fix | Delete
* @param val Value to subtract.
[97] Fix | Delete
* @return What was stored in `var` before the subtraction.
[98] Fix | Delete
* @post `var` holds `var - val`.
[99] Fix | Delete
*/
[100] Fix | Delete
#define RUBY_ATOMIC_FETCH_SUB(var, val) rbimpl_atomic_fetch_sub(&(var), (val))
[101] Fix | Delete
[102] Fix | Delete
/**
[103] Fix | Delete
* Atomically replaces the value pointed by `var` with the result of
[104] Fix | Delete
* bitwise OR between `val` and the old value of `var`.
[105] Fix | Delete
*
[106] Fix | Delete
* @param var A variable of ::rb_atomic_t.
[107] Fix | Delete
* @param val Value to mix.
[108] Fix | Delete
* @return void
[109] Fix | Delete
* @post `var` holds `var | val`.
[110] Fix | Delete
* @note For portability, this macro can return void.
[111] Fix | Delete
*/
[112] Fix | Delete
#define RUBY_ATOMIC_OR(var, val) rbimpl_atomic_or(&(var), (val))
[113] Fix | Delete
[114] Fix | Delete
/**
[115] Fix | Delete
* Atomically replaces the value pointed by `var` with `val`. This is just an
[116] Fix | Delete
* assignment, but you can additionally know the previous value.
[117] Fix | Delete
*
[118] Fix | Delete
* @param var A variable of ::rb_atomic_t.
[119] Fix | Delete
* @param val Value to set.
[120] Fix | Delete
* @return What was stored in `var` before the assignment.
[121] Fix | Delete
* @post `var` holds `val`.
[122] Fix | Delete
*/
[123] Fix | Delete
#define RUBY_ATOMIC_EXCHANGE(var, val) rbimpl_atomic_exchange(&(var), (val))
[124] Fix | Delete
[125] Fix | Delete
/**
[126] Fix | Delete
* Atomic compare-and-swap. This stores `val` to `var` if and only if the
[127] Fix | Delete
* assignment changes the value of `var` from `oldval` to `newval`. You can
[128] Fix | Delete
* detect whether the assignment happened or not using the return value.
[129] Fix | Delete
*
[130] Fix | Delete
* @param var A variable of ::rb_atomic_t.
[131] Fix | Delete
* @param oldval Expected value of `var` before the assignment.
[132] Fix | Delete
* @param newval What you want to store at `var`.
[133] Fix | Delete
* @retval oldval Successful assignment (`var` is now `newval`).
[134] Fix | Delete
* @retval otherwise Something else is at `var`; not updated.
[135] Fix | Delete
*/
[136] Fix | Delete
#define RUBY_ATOMIC_CAS(var, oldval, newval) \
[137] Fix | Delete
rbimpl_atomic_cas(&(var), (oldval), (newval))
[138] Fix | Delete
[139] Fix | Delete
/**
[140] Fix | Delete
* Identical to #RUBY_ATOMIC_EXCHANGE, except for the return type.
[141] Fix | Delete
*
[142] Fix | Delete
* @param var A variable of ::rb_atomic_t.
[143] Fix | Delete
* @param val Value to set.
[144] Fix | Delete
* @return void
[145] Fix | Delete
* @post `var` holds `val`.
[146] Fix | Delete
*/
[147] Fix | Delete
#define RUBY_ATOMIC_SET(var, val) rbimpl_atomic_set(&(var), (val))
[148] Fix | Delete
[149] Fix | Delete
/**
[150] Fix | Delete
* Identical to #RUBY_ATOMIC_FETCH_ADD, except for the return type.
[151] Fix | Delete
*
[152] Fix | Delete
* @param var A variable of ::rb_atomic_t.
[153] Fix | Delete
* @param val Value to add.
[154] Fix | Delete
* @return void
[155] Fix | Delete
* @post `var` holds `var + val`.
[156] Fix | Delete
*/
[157] Fix | Delete
#define RUBY_ATOMIC_ADD(var, val) rbimpl_atomic_add(&(var), (val))
[158] Fix | Delete
[159] Fix | Delete
/**
[160] Fix | Delete
* Identical to #RUBY_ATOMIC_FETCH_SUB, except for the return type.
[161] Fix | Delete
*
[162] Fix | Delete
* @param var A variable of ::rb_atomic_t.
[163] Fix | Delete
* @param val Value to subtract.
[164] Fix | Delete
* @return void
[165] Fix | Delete
* @post `var` holds `var - val`.
[166] Fix | Delete
*/
[167] Fix | Delete
#define RUBY_ATOMIC_SUB(var, val) rbimpl_atomic_sub(&(var), (val))
[168] Fix | Delete
[169] Fix | Delete
/**
[170] Fix | Delete
* Atomically increments the value pointed by `var`.
[171] Fix | Delete
*
[172] Fix | Delete
* @param var A variable of ::rb_atomic_t.
[173] Fix | Delete
* @return void
[174] Fix | Delete
* @post `var` holds `var + 1`.
[175] Fix | Delete
*/
[176] Fix | Delete
#define RUBY_ATOMIC_INC(var) rbimpl_atomic_inc(&(var))
[177] Fix | Delete
[178] Fix | Delete
/**
[179] Fix | Delete
* Atomically decrements the value pointed by `var`.
[180] Fix | Delete
*
[181] Fix | Delete
* @param var A variable of ::rb_atomic_t.
[182] Fix | Delete
* @return void
[183] Fix | Delete
* @post `var` holds `var - 1`.
[184] Fix | Delete
*/
[185] Fix | Delete
#define RUBY_ATOMIC_DEC(var) rbimpl_atomic_dec(&(var))
[186] Fix | Delete
[187] Fix | Delete
/**
[188] Fix | Delete
* Identical to #RUBY_ATOMIC_INC, except it expects its argument is `size_t`.
[189] Fix | Delete
* There are cases where ::rb_atomic_t is 32bit while `size_t` is 64bit. This
[190] Fix | Delete
* should be used for size related operations to support such platforms.
[191] Fix | Delete
*
[192] Fix | Delete
* @param var A variable of `size_t`.
[193] Fix | Delete
* @return void
[194] Fix | Delete
* @post `var` holds `var + 1`.
[195] Fix | Delete
*/
[196] Fix | Delete
#define RUBY_ATOMIC_SIZE_INC(var) rbimpl_atomic_size_inc(&(var))
[197] Fix | Delete
[198] Fix | Delete
/**
[199] Fix | Delete
* Identical to #RUBY_ATOMIC_DEC, except it expects its argument is `size_t`.
[200] Fix | Delete
* There are cases where ::rb_atomic_t is 32bit while `size_t` is 64bit. This
[201] Fix | Delete
* should be used for size related operations to support such platforms.
[202] Fix | Delete
*
[203] Fix | Delete
* @param var A variable of `size_t`.
[204] Fix | Delete
* @return void
[205] Fix | Delete
* @post `var` holds `var - 1`.
[206] Fix | Delete
*/
[207] Fix | Delete
#define RUBY_ATOMIC_SIZE_DEC(var) rbimpl_atomic_size_dec(&(var))
[208] Fix | Delete
[209] Fix | Delete
/**
[210] Fix | Delete
* Identical to #RUBY_ATOMIC_EXCHANGE, except it expects its arguments are
[211] Fix | Delete
* `size_t`. There are cases where ::rb_atomic_t is 32bit while `size_t` is
[212] Fix | Delete
* 64bit. This should be used for size related operations to support such
[213] Fix | Delete
* platforms.
[214] Fix | Delete
*
[215] Fix | Delete
* @param var A variable of `size_t`.
[216] Fix | Delete
* @param val Value to set.
[217] Fix | Delete
* @return What was stored in `var` before the assignment.
[218] Fix | Delete
* @post `var` holds `val`.
[219] Fix | Delete
*/
[220] Fix | Delete
#define RUBY_ATOMIC_SIZE_EXCHANGE(var, val) \
[221] Fix | Delete
rbimpl_atomic_size_exchange(&(var), (val))
[222] Fix | Delete
[223] Fix | Delete
/**
[224] Fix | Delete
* Identical to #RUBY_ATOMIC_CAS, except it expects its arguments are `size_t`.
[225] Fix | Delete
* There are cases where ::rb_atomic_t is 32bit while `size_t` is 64bit. This
[226] Fix | Delete
* should be used for size related operations to support such platforms.
[227] Fix | Delete
*
[228] Fix | Delete
* @param var A variable of `size_t`.
[229] Fix | Delete
* @param oldval Expected value of `var` before the assignment.
[230] Fix | Delete
* @param newval What you want to store at `var`.
[231] Fix | Delete
* @retval oldval Successful assignment (`var` is now `newval`).
[232] Fix | Delete
* @retval otherwise Something else is at `var`; not updated.
[233] Fix | Delete
*/
[234] Fix | Delete
#define RUBY_ATOMIC_SIZE_CAS(var, oldval, newval) \
[235] Fix | Delete
rbimpl_atomic_size_cas(&(var), (oldval), (newval))
[236] Fix | Delete
[237] Fix | Delete
/**
[238] Fix | Delete
* Identical to #RUBY_ATOMIC_ADD, except it expects its arguments are `size_t`.
[239] Fix | Delete
* There are cases where ::rb_atomic_t is 32bit while `size_t` is 64bit. This
[240] Fix | Delete
* should be used for size related operations to support such platforms.
[241] Fix | Delete
*
[242] Fix | Delete
* @param var A variable of `size_t`.
[243] Fix | Delete
* @param val Value to add.
[244] Fix | Delete
* @return void
[245] Fix | Delete
* @post `var` holds `var + val`.
[246] Fix | Delete
*/
[247] Fix | Delete
#define RUBY_ATOMIC_SIZE_ADD(var, val) rbimpl_atomic_size_add(&(var), (val))
[248] Fix | Delete
[249] Fix | Delete
/**
[250] Fix | Delete
* Identical to #RUBY_ATOMIC_SUB, except it expects its arguments are `size_t`.
[251] Fix | Delete
* There are cases where ::rb_atomic_t is 32bit while `size_t` is 64bit. This
[252] Fix | Delete
* should be used for size related operations to support such platforms.
[253] Fix | Delete
*
[254] Fix | Delete
* @param var A variable of `size_t`.
[255] Fix | Delete
* @param val Value to subtract.
[256] Fix | Delete
* @return void
[257] Fix | Delete
* @post `var` holds `var - val`.
[258] Fix | Delete
*/
[259] Fix | Delete
#define RUBY_ATOMIC_SIZE_SUB(var, val) rbimpl_atomic_size_sub(&(var), (val))
[260] Fix | Delete
[261] Fix | Delete
/**
[262] Fix | Delete
* Identical to #RUBY_ATOMIC_EXCHANGE, except it expects its arguments are
[263] Fix | Delete
* `void*`. There are cases where ::rb_atomic_t is 32bit while `void*` is
[264] Fix | Delete
* 64bit. This should be used for pointer related operations to support such
[265] Fix | Delete
* platforms.
[266] Fix | Delete
*
[267] Fix | Delete
* @param var A variable of `void *`.
[268] Fix | Delete
* @param val Value to set.
[269] Fix | Delete
* @return What was stored in `var` before the assignment.
[270] Fix | Delete
* @post `var` holds `val`.
[271] Fix | Delete
*
[272] Fix | Delete
* @internal
[273] Fix | Delete
*
[274] Fix | Delete
* :FIXME: this `(void*)` cast is evil! However `void*` is incompatible with
[275] Fix | Delete
* some pointers, most notably function pointers.
[276] Fix | Delete
*/
[277] Fix | Delete
#define RUBY_ATOMIC_PTR_EXCHANGE(var, val) \
[278] Fix | Delete
RBIMPL_CAST(rbimpl_atomic_ptr_exchange((void **)&(var), (void *)val))
[279] Fix | Delete
[280] Fix | Delete
/**
[281] Fix | Delete
* Identical to #RUBY_ATOMIC_CAS, except it expects its arguments are `void*`.
[282] Fix | Delete
* There are cases where ::rb_atomic_t is 32bit while `void*` is 64bit. This
[283] Fix | Delete
* should be used for size related operations to support such platforms.
[284] Fix | Delete
*
[285] Fix | Delete
* @param var A variable of `void*`.
[286] Fix | Delete
* @param oldval Expected value of `var` before the assignment.
[287] Fix | Delete
* @param newval What you want to store at `var`.
[288] Fix | Delete
* @retval oldval Successful assignment (`var` is now `newval`).
[289] Fix | Delete
* @retval otherwise Something else is at `var`; not updated.
[290] Fix | Delete
*/
[291] Fix | Delete
#define RUBY_ATOMIC_PTR_CAS(var, oldval, newval) \
[292] Fix | Delete
RBIMPL_CAST(rbimpl_atomic_ptr_cas((void **)&(var), (oldval), (newval)))
[293] Fix | Delete
[294] Fix | Delete
/**
[295] Fix | Delete
* Identical to #RUBY_ATOMIC_EXCHANGE, except it expects its arguments are
[296] Fix | Delete
* ::VALUE. There are cases where ::rb_atomic_t is 32bit while ::VALUE is
[297] Fix | Delete
* 64bit. This should be used for pointer related operations to support such
[298] Fix | Delete
* platforms.
[299] Fix | Delete
*
[300] Fix | Delete
* @param var A variable of ::VALUE.
[301] Fix | Delete
* @param val Value to set.
[302] Fix | Delete
* @return What was stored in `var` before the assignment.
[303] Fix | Delete
* @post `var` holds `val`.
[304] Fix | Delete
*/
[305] Fix | Delete
#define RUBY_ATOMIC_VALUE_EXCHANGE(var, val) \
[306] Fix | Delete
rbimpl_atomic_value_exchange(&(var), (val))
[307] Fix | Delete
[308] Fix | Delete
/**
[309] Fix | Delete
* Identical to #RUBY_ATOMIC_CAS, except it expects its arguments are ::VALUE.
[310] Fix | Delete
* There are cases where ::rb_atomic_t is 32bit while ::VALUE is 64bit. This
[311] Fix | Delete
* should be used for size related operations to support such platforms.
[312] Fix | Delete
*
[313] Fix | Delete
* @param var A variable of `void*`.
[314] Fix | Delete
* @param oldval Expected value of `var` before the assignment.
[315] Fix | Delete
* @param newval What you want to store at `var`.
[316] Fix | Delete
* @retval oldval Successful assignment (`var` is now `newval`).
[317] Fix | Delete
* @retval otherwise Something else is at `var`; not updated.
[318] Fix | Delete
*/
[319] Fix | Delete
#define RUBY_ATOMIC_VALUE_CAS(var, oldval, newval) \
[320] Fix | Delete
rbimpl_atomic_value_cas(&(var), (oldval), (newval))
[321] Fix | Delete
[322] Fix | Delete
/** @cond INTERNAL_MACRO */
[323] Fix | Delete
RBIMPL_ATTR_ARTIFICIAL()
[324] Fix | Delete
RBIMPL_ATTR_NOALIAS()
[325] Fix | Delete
RBIMPL_ATTR_NONNULL((1))
[326] Fix | Delete
static inline rb_atomic_t
[327] Fix | Delete
rbimpl_atomic_fetch_add(volatile rb_atomic_t *ptr, rb_atomic_t val)
[328] Fix | Delete
{
[329] Fix | Delete
#if 0
[330] Fix | Delete
[331] Fix | Delete
#elif defined(HAVE_GCC_ATOMIC_BUILTINS)
[332] Fix | Delete
return __atomic_fetch_add(ptr, val, __ATOMIC_SEQ_CST);
[333] Fix | Delete
[334] Fix | Delete
#elif defined(HAVE_GCC_SYNC_BUILTINS)
[335] Fix | Delete
return __sync_fetch_and_add(ptr, val);
[336] Fix | Delete
[337] Fix | Delete
#elif defined(_WIN32)
[338] Fix | Delete
return InterlockedExchangeAdd(ptr, val);
[339] Fix | Delete
[340] Fix | Delete
#elif defined(__sun) && defined(HAVE_ATOMIC_H)
[341] Fix | Delete
/*
[342] Fix | Delete
* `atomic_add_int_nv` takes its second argument as `int`! Meanwhile our
[343] Fix | Delete
* `rb_atomic_t` is unsigned. We cannot pass `val` as-is. We have to
[344] Fix | Delete
* manually check integer overflow.
[345] Fix | Delete
*/
[346] Fix | Delete
RBIMPL_ASSERT_OR_ASSUME(val <= INT_MAX);
[347] Fix | Delete
return atomic_add_int_nv(ptr, val) - val;
[348] Fix | Delete
[349] Fix | Delete
#else
[350] Fix | Delete
# error Unsupported platform.
[351] Fix | Delete
#endif
[352] Fix | Delete
}
[353] Fix | Delete
[354] Fix | Delete
RBIMPL_ATTR_ARTIFICIAL()
[355] Fix | Delete
RBIMPL_ATTR_NOALIAS()
[356] Fix | Delete
RBIMPL_ATTR_NONNULL((1))
[357] Fix | Delete
static inline void
[358] Fix | Delete
rbimpl_atomic_add(volatile rb_atomic_t *ptr, rb_atomic_t val)
[359] Fix | Delete
{
[360] Fix | Delete
#if 0
[361] Fix | Delete
[362] Fix | Delete
#elif defined(HAVE_GCC_ATOMIC_BUILTINS)
[363] Fix | Delete
/*
[364] Fix | Delete
* GCC on amd64 is smart enough to detect this `__atomic_add_fetch`'s
[365] Fix | Delete
* return value is not used, then compiles it into single `LOCK ADD`
[366] Fix | Delete
* instruction.
[367] Fix | Delete
*/
[368] Fix | Delete
__atomic_add_fetch(ptr, val, __ATOMIC_SEQ_CST);
[369] Fix | Delete
[370] Fix | Delete
#elif defined(HAVE_GCC_SYNC_BUILTINS)
[371] Fix | Delete
__sync_add_and_fetch(ptr, val);
[372] Fix | Delete
[373] Fix | Delete
#elif defined(_WIN32)
[374] Fix | Delete
/*
[375] Fix | Delete
* `InterlockedExchangeAdd` is `LOCK XADD`. It seems there also is
[376] Fix | Delete
* `_InterlockedAdd` intrinsic in ARM Windows but not for x86? Sticking to
[377] Fix | Delete
* `InterlockedExchangeAdd` for better portability.
[378] Fix | Delete
*/
[379] Fix | Delete
InterlockedExchangeAdd(ptr, val);
[380] Fix | Delete
[381] Fix | Delete
#elif defined(__sun) && defined(HAVE_ATOMIC_H)
[382] Fix | Delete
/* Ditto for `atomic_add_int_nv`. */
[383] Fix | Delete
RBIMPL_ASSERT_OR_ASSUME(val <= INT_MAX);
[384] Fix | Delete
atomic_add_int(ptr, val);
[385] Fix | Delete
[386] Fix | Delete
#else
[387] Fix | Delete
# error Unsupported platform.
[388] Fix | Delete
#endif
[389] Fix | Delete
}
[390] Fix | Delete
[391] Fix | Delete
RBIMPL_ATTR_ARTIFICIAL()
[392] Fix | Delete
RBIMPL_ATTR_NOALIAS()
[393] Fix | Delete
RBIMPL_ATTR_NONNULL((1))
[394] Fix | Delete
static inline void
[395] Fix | Delete
rbimpl_atomic_size_add(volatile size_t *ptr, size_t val)
[396] Fix | Delete
{
[397] Fix | Delete
#if 0
[398] Fix | Delete
[399] Fix | Delete
#elif defined(HAVE_GCC_ATOMIC_BUILTINS)
[400] Fix | Delete
__atomic_add_fetch(ptr, val, __ATOMIC_SEQ_CST);
[401] Fix | Delete
[402] Fix | Delete
#elif defined(HAVE_GCC_SYNC_BUILTINS)
[403] Fix | Delete
__sync_add_and_fetch(ptr, val);
[404] Fix | Delete
[405] Fix | Delete
#elif defined(_WIN32) && defined(_M_AMD64)
[406] Fix | Delete
/* Ditto for `InterlockeExchangedAdd`. */
[407] Fix | Delete
InterlockedExchangeAdd64(ptr, val);
[408] Fix | Delete
[409] Fix | Delete
#elif defined(__sun) && defined(HAVE_ATOMIC_H) && (defined(_LP64) || defined(_I32LPx))
[410] Fix | Delete
/* Ditto for `atomic_add_int_nv`. */
[411] Fix | Delete
RBIMPL_ASSERT_OR_ASSUME(val <= LONG_MAX);
[412] Fix | Delete
atomic_add_long(ptr, val);
[413] Fix | Delete
[414] Fix | Delete
#else
[415] Fix | Delete
RBIMPL_STATIC_ASSERT(size_of_rb_atomic_t, sizeof *ptr == sizeof(rb_atomic_t));
[416] Fix | Delete
[417] Fix | Delete
volatile rb_atomic_t *const tmp = RBIMPL_CAST((volatile rb_atomic_t *)ptr);
[418] Fix | Delete
rbimpl_atomic_add(tmp, val);
[419] Fix | Delete
[420] Fix | Delete
#endif
[421] Fix | Delete
}
[422] Fix | Delete
[423] Fix | Delete
RBIMPL_ATTR_ARTIFICIAL()
[424] Fix | Delete
RBIMPL_ATTR_NOALIAS()
[425] Fix | Delete
RBIMPL_ATTR_NONNULL((1))
[426] Fix | Delete
static inline void
[427] Fix | Delete
rbimpl_atomic_inc(volatile rb_atomic_t *ptr)
[428] Fix | Delete
{
[429] Fix | Delete
#if 0
[430] Fix | Delete
[431] Fix | Delete
#elif defined(HAVE_GCC_ATOMIC_BUILTINS) || defined(HAVE_GCC_SYNC_BUILTINS)
[432] Fix | Delete
rbimpl_atomic_add(ptr, 1);
[433] Fix | Delete
[434] Fix | Delete
#elif defined(_WIN32)
[435] Fix | Delete
InterlockedIncrement(ptr);
[436] Fix | Delete
[437] Fix | Delete
#elif defined(__sun) && defined(HAVE_ATOMIC_H)
[438] Fix | Delete
atomic_inc_uint(ptr);
[439] Fix | Delete
[440] Fix | Delete
#else
[441] Fix | Delete
rbimpl_atomic_add(ptr, 1);
[442] Fix | Delete
[443] Fix | Delete
#endif
[444] Fix | Delete
}
[445] Fix | Delete
[446] Fix | Delete
RBIMPL_ATTR_ARTIFICIAL()
[447] Fix | Delete
RBIMPL_ATTR_NOALIAS()
[448] Fix | Delete
RBIMPL_ATTR_NONNULL((1))
[449] Fix | Delete
static inline void
[450] Fix | Delete
rbimpl_atomic_size_inc(volatile size_t *ptr)
[451] Fix | Delete
{
[452] Fix | Delete
#if 0
[453] Fix | Delete
[454] Fix | Delete
#elif defined(HAVE_GCC_ATOMIC_BUILTINS) || defined(HAVE_GCC_SYNC_BUILTINS)
[455] Fix | Delete
rbimpl_atomic_size_add(ptr, 1);
[456] Fix | Delete
[457] Fix | Delete
#elif defined(_WIN32) && defined(_M_AMD64)
[458] Fix | Delete
InterlockedIncrement64(ptr);
[459] Fix | Delete
[460] Fix | Delete
#elif defined(__sun) && defined(HAVE_ATOMIC_H) && (defined(_LP64) || defined(_I32LPx))
[461] Fix | Delete
atomic_inc_ulong(ptr);
[462] Fix | Delete
[463] Fix | Delete
#else
[464] Fix | Delete
rbimpl_atomic_size_add(ptr, 1);
[465] Fix | Delete
[466] Fix | Delete
#endif
[467] Fix | Delete
}
[468] Fix | Delete
[469] Fix | Delete
RBIMPL_ATTR_ARTIFICIAL()
[470] Fix | Delete
RBIMPL_ATTR_NOALIAS()
[471] Fix | Delete
RBIMPL_ATTR_NONNULL((1))
[472] Fix | Delete
static inline rb_atomic_t
[473] Fix | Delete
rbimpl_atomic_fetch_sub(volatile rb_atomic_t *ptr, rb_atomic_t val)
[474] Fix | Delete
{
[475] Fix | Delete
#if 0
[476] Fix | Delete
[477] Fix | Delete
#elif defined(HAVE_GCC_ATOMIC_BUILTINS)
[478] Fix | Delete
return __atomic_fetch_sub(ptr, val, __ATOMIC_SEQ_CST);
[479] Fix | Delete
[480] Fix | Delete
#elif defined(HAVE_GCC_SYNC_BUILTINS)
[481] Fix | Delete
return __sync_fetch_and_sub(ptr, val);
[482] Fix | Delete
[483] Fix | Delete
#elif defined(_WIN32)
[484] Fix | Delete
/* rb_atomic_t is signed here! Safe to do `-val`. */
[485] Fix | Delete
return InterlockedExchangeAdd(ptr, -val);
[486] Fix | Delete
[487] Fix | Delete
#elif defined(__sun) && defined(HAVE_ATOMIC_H)
[488] Fix | Delete
/* Ditto for `rbimpl_atomic_fetch_add`. */
[489] Fix | Delete
const signed neg = -1;
[490] Fix | Delete
RBIMPL_ASSERT_OR_ASSUME(val <= INT_MAX);
[491] Fix | Delete
return atomic_add_int_nv(ptr, neg * val) + val;
[492] Fix | Delete
[493] Fix | Delete
#else
[494] Fix | Delete
# error Unsupported platform.
[495] Fix | Delete
#endif
[496] Fix | Delete
}
[497] Fix | Delete
[498] Fix | Delete
RBIMPL_ATTR_ARTIFICIAL()
[499] Fix | Delete
12
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function