| | |
| | | #ifndef BH_UTIL_SOXWOK67 |
| | | #define BH_UTIL_SOXWOK67 |
| | | |
| | | #include "macro.h" |
| | | #include <functional> |
| | | #include <mutex> |
| | | #include <stdint.h> |
| | |
| | | inline void Put16(void *p, uint16_t u) |
| | | { |
| | | auto ptr = static_cast<uint8_t *>(p); |
| | | ptr[0] = (uint8_t)(u >> 8u); |
| | | ptr[1] = (uint8_t)(u); |
| | | ptr[0] = (uint8_t) (u >> 8u); |
| | | ptr[1] = (uint8_t) (u); |
| | | } |
| | | |
| | | inline uint32_t Get32(const void *p) |
| | |
| | | inline void Put32(void *p, uint32_t u) |
| | | { |
| | | auto ptr = static_cast<uint8_t *>(p); |
| | | ptr[0] = (uint8_t)(u >> 24u); |
| | | ptr[1] = (uint8_t)(u >> 16u); |
| | | ptr[2] = (uint8_t)(u >> 8u); |
| | | ptr[3] = (uint8_t)(u); |
| | | ptr[0] = (uint8_t) (u >> 24u); |
| | | ptr[1] = (uint8_t) (u >> 16u); |
| | | ptr[2] = (uint8_t) (u >> 8u); |
| | | ptr[3] = (uint8_t) (u); |
| | | } |
| | | |
| | | inline uint64_t Get64(const void *p) |
| | |
| | | inline void Put64(void *p, uint64_t u) |
| | | { |
| | | auto ptr = static_cast<uint8_t *>(p); |
| | | ptr[0] = (uint8_t)(u >> 56); |
| | | ptr[1] = (uint8_t)(u >> 48); |
| | | ptr[2] = (uint8_t)(u >> 40u); |
| | | ptr[3] = (uint8_t)(u >> 32); |
| | | ptr[4] = (uint8_t)(u >> 24u); |
| | | ptr[5] = (uint8_t)(u >> 16u); |
| | | ptr[6] = (uint8_t)(u >> 8u); |
| | | ptr[7] = (uint8_t)(u); |
| | | ptr[0] = (uint8_t) (u >> 56); |
| | | ptr[1] = (uint8_t) (u >> 48); |
| | | ptr[2] = (uint8_t) (u >> 40u); |
| | | ptr[3] = (uint8_t) (u >> 32); |
| | | ptr[4] = (uint8_t) (u >> 24u); |
| | | ptr[5] = (uint8_t) (u >> 16u); |
| | | ptr[6] = (uint8_t) (u >> 8u); |
| | | ptr[7] = (uint8_t) (u); |
| | | } |
| | | |
| | | inline void PutInt(void *p, uint8_t u) { Put8(p, u); } |
| | | inline void PutInt(void *p, uint16_t u) { Put16(p, u); } |
| | | inline void PutInt(void *p, uint32_t u) { Put32(p, u); } |
| | | inline void PutInt(void *p, uint64_t u) { Put64(p, u); } |
| | | |
| | | constexpr uint64_t MaskBits(int nbits) { return (uint64_t(1) << nbits) - 1; } |
| | | |
| | | class ExitCall |
| | | { |
| | |
| | | return f(data_); |
| | | } |
| | | }; |
| | | |
| | | // macro helper |
| | | #define JOIN_IMPL(a, b) a##b |
| | | #define JOIN(a, b) JOIN_IMPL(a, b) |
| | | // defer function / lambda. |
| | | #define DEFERF(func) ExitCall JOIN(defer_, __LINE__)(func) |
| | | // defer simple expression |
| | | #define DEFER1(expr) DEFERF([&]() { expr; }) |
| | | |
| | | #endif /* end of include guard: BH_UTIL_SOXWOK67 */ |