18 #ifndef FOEDUS_ASSORTED_ASSORTED_FUNC_HPP_
19 #define FOEDUS_ASSORTED_ASSORTED_FUNC_HPP_
43 template <
typename T, u
int64_t ALIGNMENT>
45 uint64_t left = (value + ALIGNMENT - 1);
46 uint64_t right = -ALIGNMENT;
47 uint64_t result = left & right;
48 ASSERT_ND(result >= static_cast<uint64_t>(value));
50 ASSERT_ND(result < static_cast<uint64_t>(value) + ALIGNMENT);
51 return static_cast<T
>(result);
58 template <
typename T>
inline T
align8(T value) {
return align<T, 8>(value); }
64 template <
typename T>
inline T
align16(T value) {
return align<T, 16>(value); }
70 template <
typename T>
inline T
align64(T value) {
return align<T, 64>(value); }
84 std::string
replace_all(
const std::string& target,
const std::string& search,
85 const std::string& replacement);
90 std::string
replace_all(
const std::string& target,
const std::string& search,
103 std::string
os_error(
int error_number);
130 friend std::ostream&
operator<<(std::ostream& o,
const Hex& v);
144 HexString(
const std::string& str, uint32_t max_bytes = 64U)
163 Top(
const char* data, uint32_t data_len, uint32_t max_bytes = 8)
169 friend std::ostream&
operator<<(std::ostream& o,
const Top& v);
194 template<u
int64_t SIZE1, u
int64_t SIZE2>
197 "Static Size Check failed. Look for a message like this to see the value of Size1 and "
198 "Size2: 'In instantiation of int foedus::assorted::static_size_check() [with long unsigned"
199 " int SIZE1 = <size1>ul; long unsigned int SIZE2 = <size2>ul]'");
214 template <
typename T>
256 #define SPINLOCK_WHILE(x) \
257 for (foedus::assorted::SpinlockStat __spins; (x); __spins.yield_backoff())
260 #define STATIC_SIZE_CHECK_CONCAT_DETAIL(x, y) x##y
261 #define STATIC_SIZE_CHECK_CONCAT(x, y) STATIC_SIZE_CHECK_CONCAT_DETAIL(x, y)
262 #define STATIC_SIZE_CHECK_METHOD_NAME \
263 STATIC_SIZE_CHECK_CONCAT(_dummy_static_size_check, __COUNTER__)
264 #define STATIC_SIZE_CHECK(desired, actual) \
265 inline void STATIC_SIZE_CHECK_METHOD_NAME() { \
266 foedus::assorted::static_size_check< desired, actual >();\
313 #define INSTANTIATE_ALL_INTEGER_TYPES(M) M(int64_t); \
314 M(int32_t); M(int16_t); M(int8_t); M(uint64_t); \
315 M(uint32_t); M(uint16_t); M(uint8_t);
317 #define INSTANTIATE_ALL_INTEGER_PLUS_BOOL_TYPES(M) INSTANTIATE_ALL_INTEGER_TYPES(M);\
320 #define INSTANTIATE_ALL_NUMERIC_TYPES(M) INSTANTIATE_ALL_INTEGER_TYPES(M);\
321 M(bool); M(float); M(double);
323 #define INSTANTIATE_ALL_TYPES(M) INSTANTIATE_ALL_NUMERIC_TYPES(M);\
327 #endif // FOEDUS_ASSORTED_ASSORTED_FUNC_HPP_
T align16(T value)
16-alignment.
T align8(T value)
8-alignment.
T align64(T value)
64-alignment.
Root package of FOEDUS (Fast Optimistic Engine for Data Unification Services).
friend std::ostream & operator<<(std::ostream &o, const Hex &v)
int static_size_check()
Alternative for static_assert(sizeof(foo) == sizeof(bar), "oh crap") to display sizeof(foo).
std::string get_current_executable_path()
Returns the full path of current executable.
std::string replace_all(const std::string &target, const std::string &search, const std::string &replacement)
target.replaceAll(search, replacement).
Top(const char *data, uint32_t data_len, uint32_t max_bytes=8)
Hex(T val, int fix_digits=-1)
Equivalent to std::hex in case the stream doesn't support it.
#define CXX11_STATIC_ASSERT(expr, message)
Used in public headers in place of "static_assert" of C++11.
void spinlock_yield()
Invoke _mm_pause(), x86 PAUSE instruction, or something equivalent in the env.
Helper for SPINLOCK_WHILE.
Write only first few bytes to stream.
std::string os_error()
Thread-safe strerror(errno).
T align(T value)
Returns the smallest multiply of ALIGNMENT that is equal or larger than the given number...
uint64_t generate_almost_prime_below(uint64_t threshold)
Generate a prime or some number that is almost prime less than the given number.
std::string demangle_type_name(const char *mangled_name)
Demangle the given C++ type name if possible (otherwise the original string).
Convenient way of writing hex integers to stream.
int64_t int_div_ceil(int64_t dividee, int64_t dividor)
Efficient ceil(dividee/dividor) for integer.
std::string get_pretty_type_name()
Returns the name of the C++ type as readable as possible.
HexString(const std::string &str, uint32_t max_bytes=64U)
#define ASSERT_ND(x)
A warning-free wrapper macro of assert() that has no performance effect in release mode even when 'x'...
friend std::ostream & operator<<(std::ostream &o, const Top &v)
friend std::ostream & operator<<(std::ostream &o, const HexString &v)