aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/messagebus/memory.h
diff options
context:
space:
mode:
authornga <nga@yandex-team.ru>2022-02-10 16:48:09 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:48:09 +0300
commitc2a1af049e9deca890e9923abe64fe6c59060348 (patch)
treeb222e5ac2e2e98872661c51ccceee5da0d291e13 /library/cpp/messagebus/memory.h
parent1f553f46fb4f3c5eec631352cdd900a0709016af (diff)
downloadydb-c2a1af049e9deca890e9923abe64fe6c59060348.tar.gz
Restoring authorship annotation for <nga@yandex-team.ru>. Commit 2 of 2.
Diffstat (limited to 'library/cpp/messagebus/memory.h')
-rw-r--r--library/cpp/messagebus/memory.h74
1 files changed, 37 insertions, 37 deletions
diff --git a/library/cpp/messagebus/memory.h b/library/cpp/messagebus/memory.h
index e7bfc1827d7..b2c05444915 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);
+}