MCPcopy Create free account
hub / github.com/apache/incubator-pegasus / new_cacheline_aligned_int64_array

Function new_cacheline_aligned_int64_array

src/utils/long_adder.cpp:63–91  ·  view source on GitHub ↗

extern */

Source from the content-addressed store, hash-verified

61//
62
63/* extern */ cacheline_aligned_int64_ptr new_cacheline_aligned_int64_array(uint32_t size)
64{
65 void *buffer = nullptr;
66 int err = posix_memalign(&buffer, CACHELINE_SIZE, sizeof(cacheline_aligned_int64) * size);
67
68 // Generally there are 2 possible errors for posix_memalign as below:
69 // [EINVAL]
70 // The value of the alignment parameter is not a power of two multiple of sizeof(void *).
71 // [ENOMEM]
72 // There is insufficient memory available with the requested alignment.
73 // Thus making an assertion here is enough.
74 CHECK_EQ_MSG(err, 0, "error calling posix_memalign: {}", utils::safe_strerror(err));
75
76 cacheline_aligned_int64 *array = new (buffer) cacheline_aligned_int64[size];
77 for (uint32_t i = 0; i < size; ++i) {
78 cacheline_aligned_int64 *elem = &(array[i]);
79 CHECK_EQ_MSG(
80 (reinterpret_cast<const uintptr_t>(elem) & (sizeof(cacheline_aligned_int64) - 1)),
81 0,
82 "unaligned cacheline_aligned_int64: array={}, index={}, elem={}, mask={}",
83 fmt::ptr(array),
84 i,
85 fmt::ptr(elem),
86 sizeof(cacheline_aligned_int64) - 1);
87 array[i]._value.store(0);
88 }
89
90 return cacheline_aligned_int64_ptr(array, [](cacheline_aligned_int64 *array) { free(array); });
91}
92
93/* extern */ cacheline_aligned_int64_ptr new_cacheline_aligned_int64()
94{

Callers 4

retry_updateMethod · 0.85
concurrent_long_adderMethod · 0.85

Calls 2

safe_strerrorFunction · 0.85
storeMethod · 0.80

Tested by 1