/**
* Atomic add
*/
template <typename ValueT>
inline ValueT add_and_fetch(volatile ValueT *ptr, ValueT val);
template <>
inline uint64_t add_and_fetch(volatile uint64_t *ptr, uint64_t val)
{
#if LEVELDB_IS_SOLARIS
return atomic_add_64_nv(ptr, val);
#else
return __sync_add_and_fetch(ptr, val);
#endif
}
template <>
inline uint32_t add_and_fetch(volatile uint32_t *ptr, uint32_t val)
{
#if LEVELDB_IS_SOLARIS
return atomic_add_32_nv(ptr, val);
#else
return __sync_add_and_fetch(ptr, val);
#endif
}
#if defined(__APPLE__) || defined(__OpenBSD__) || (defined(__s390__) && !defined(__s390x__))
template <>
inline size_t add_and_fetch(volatile size_t *ptr, size_t val)
{
return __sync_add_and_fetch(ptr, val);
}
#endif
});
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
The C standard does not exactly define sizes of
short
,int
,long
,long long
and theirunsigned
versions. Only minimum sizes are enforced. For sake of example consider x86_64 architecture.long
on Linux is 64-bit whereas on 64-bit Windows it is 32-bit. Common approach to make code more portable is to use length-specific types likeuint16_t
orint32_t
defined by C99'sstdint.h
header file. Three kinds of integer types are defined there:uint8_t
,uint16_t
,int32_t
, etc.uint_least8_t
,uint_least16_t
,int_least32_t
, etc.uint_fast8_t
,uint_fast16_t
,int_fast32_t
, etc.一句话就是为了代码的可移值性。