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

Function cacheline_aligned_alloc

src/utils/alloc.cpp:31–51  ·  view source on GitHub ↗

extern */

Source from the content-addressed store, hash-verified

29namespace dsn {
30
31/* extern */ void *cacheline_aligned_alloc(size_t size)
32{
33 if (dsn_unlikely(size == 0)) {
34 return nullptr;
35 }
36
37 void *buffer = nullptr;
38 // CACHELINE_SIZE must be a power of 2 and a multiple of sizeof(void *), which have been
39 // checked statically at compile time when CACHELINE_SIZE is defined as macro.
40 int err = posix_memalign(&buffer, CACHELINE_SIZE, size);
41
42 // Generally there are 2 possible errors for posix_memalign as below:
43 // [EINVAL]
44 // The value of the alignment parameter is not a power of two multiple of sizeof(void *).
45 // [ENOMEM]
46 // There is insufficient memory available with the requested alignment.
47 // Thus making an assertion here is enough.
48 CHECK_EQ_MSG(err, 0, "error calling posix_memalign: {}", utils::safe_strerror(err));
49
50 return buffer;
51}
52
53/* extern */ void cacheline_aligned_free(void *mem_block) { free(mem_block); }
54

Callers 1

Calls 1

safe_strerrorFunction · 0.85

Tested by

no test coverage detected