-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
107 lines (83 loc) · 2.07 KB
/
main.cpp
File metadata and controls
107 lines (83 loc) · 2.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#include "stable.hpp"
#include "mm.hpp"
#include "mm/system.hpp"
#include "mm.ipp"
#include "mm/allocator.ipp"
#include "mm/allocator/blocksHolder.ipp"
#include "mm/allocator/block.ipp"
#include "mm/utils/intrusiveDeque.ipp"
#include "mm/utils/sized_cast.ipp"
#include "mm/allocator/bitIndex.ipp"
#include "mm/allocator/bitIndex/level.ipp"
int main(int argc, char *argv[])
{
(void)argc;
(void)argv;
free(malloc(220));
return 0;
}
namespace
{
std::atomic_flag mtx_954129 = ATOMIC_FLAG_INIT;
struct Locker
{
Locker()
{
while(mtx_954129.test_and_set(std::memory_order_acquire))
{
std::this_thread::yield();
}
}
~Locker()
{
mtx_954129.clear(std::memory_order_release);
}
};
}
extern "C"
{
void *mm_malloc(size_t size)
{
Locker l;
return mm::alloc(size);
}
void *mm_calloc(size_t n, size_t size)
{
Locker l;
void *res = mm::alloc(size*n);
::memset(res, 0, size*n);
return res;
}
void *mm_realloc(void *ptr, size_t size)
{
if(likely(ptr))
{
Locker l;
size_t oldSize = mm::size(ptr);
if(unlikely(oldSize >= size))
{
return ptr;
}
else
{
void *mem = mm::alloc(size);
memcpy(mem, ptr, oldSize);
mm::free(ptr);
return mem;
}
}
Locker l;
return mm::alloc(size);
}
void mm_free(void *mem)
{
Locker l;
return mm::free(mem);
}
#pragma GCC visibility push(default)
void *malloc(size_t) __attribute__ ((alias ("mm_malloc")));
void *calloc(size_t, size_t) __attribute__ ((alias ("mm_calloc")));
void *realloc(void *, size_t) __attribute__ ((alias ("mm_realloc")));
void free(void *) __attribute__ ((alias ("mm_free")));
#pragma GCC visibility pop
}