diff options
author | nga <nga@yandex-team.ru> | 2022-02-10 16:48:09 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:48:09 +0300 |
commit | 1f553f46fb4f3c5eec631352cdd900a0709016af (patch) | |
tree | a231fba2c03b440becaea6c86a2702d0bfb0336e /library/cpp/messagebus/memory.h | |
parent | c4de7efdedc25b49cbea74bd589eecb61b55b60a (diff) | |
download | ydb-1f553f46fb4f3c5eec631352cdd900a0709016af.tar.gz |
Restoring authorship annotation for <nga@yandex-team.ru>. Commit 1 of 2.
Diffstat (limited to 'library/cpp/messagebus/memory.h')
-rw-r--r-- | library/cpp/messagebus/memory.h | 74 |
1 files changed, 37 insertions, 37 deletions
diff --git a/library/cpp/messagebus/memory.h b/library/cpp/messagebus/memory.h index b2c0544491..e7bfc1827d 100644 --- a/library/cpp/messagebus/memory.h +++ b/library/cpp/messagebus/memory.h @@ -1,42 +1,42 @@ -#pragma once - -#ifndef CACHE_LINE_SIZE -#define CACHE_LINE_SIZE 64 -#endif - -#define CONCAT(a, b) a##b -#define LABEL(a) CONCAT(UniqueName_, a) -#define UNIQUE_NAME LABEL(__LINE__) - -#define CACHE_LINE_PADDING char UNIQUE_NAME[CACHE_LINE_SIZE]; - -static inline void* MallocAligned(size_t size, size_t alignment) { +#pragma once + +#ifndef CACHE_LINE_SIZE +#define CACHE_LINE_SIZE 64 +#endif + +#define CONCAT(a, b) a##b +#define LABEL(a) CONCAT(UniqueName_, a) +#define UNIQUE_NAME LABEL(__LINE__) + +#define CACHE_LINE_PADDING char UNIQUE_NAME[CACHE_LINE_SIZE]; + +static inline void* MallocAligned(size_t size, size_t alignment) { void** ptr = (void**)malloc(size + alignment + sizeof(size_t*)); - if (!ptr) { + if (!ptr) { return nullptr; - } - - size_t mask = ~(alignment - 1); - intptr_t roundedDown = intptr_t(ptr) & mask; + } + + size_t mask = ~(alignment - 1); + intptr_t roundedDown = intptr_t(ptr) & mask; void** alignedPtr = (void**)(roundedDown + alignment); - alignedPtr[-1] = ptr; - return alignedPtr; -} - -static inline void FreeAligned(void* ptr) { - if (!ptr) { - return; - } - + alignedPtr[-1] = ptr; + return alignedPtr; +} + +static inline void FreeAligned(void* ptr) { + if (!ptr) { + return; + } + void** typedPtr = (void**)ptr; void* originalPtr = typedPtr[-1]; - free(originalPtr); -} - -static inline void* MallocCacheAligned(size_t size) { - return MallocAligned(size, CACHE_LINE_SIZE); -} - -static inline void FreeCacheAligned(void* ptr) { - return FreeAligned(ptr); -} + free(originalPtr); +} + +static inline void* MallocCacheAligned(size_t size) { + return MallocAligned(size, CACHE_LINE_SIZE); +} + +static inline void FreeCacheAligned(void* ptr) { + return FreeAligned(ptr); +} |