acme
Foundational cross-platform layer of the ca2 framework
Toggle main menu visibility
Loading...
Searching...
No Matches
fixed_alloc_impl.h
1
#pragma once
2
3
4
inline
void
* fixed_alloc_sync::Alloc()
5
{
6
7
// veripseudo-random generator, don't need to be
8
// perfectly sequential or perfectly distributed,
9
// just fair well distributed
10
// but very important is extremely fast
11
::i32 i = m_i32;
12
if
(i >= m_iShareCount)
13
{
14
i = 0;
15
m_i32 = 1;
16
}
17
else
18
{
19
m_i32++;
20
}
21
22
23
void
* p =
nullptr
;
24
m_criticalsectiona[0].lock();
25
try
26
{
27
p = m_allocptra.get_data()[i]->Alloc();
28
}
29
catch
(...)
30
{
31
}
32
m_criticalsectiona[i].unlock();
33
if
(p ==
nullptr
)
34
return
nullptr
;
35
((::i32 *) p)[0] = i;
36
return
&((::i32 *)p)[1];
37
}
38
39
inline
void
fixed_alloc_sync::Free(
void
* p)
40
{
41
42
if
(p ==
nullptr
)
43
return
;
44
45
::i32 i = ((::i32 *)p)[-1];
46
47
critical_section_lock l(&m_criticalsectiona[i]);
48
49
m_allocptra.get_data()[i]->Free(&((::i32 *)p)[-1]);
50
51
}
52
53
54
55
inline
void
* fixed_alloc::Alloc()
56
{
57
58
// veripseudo-random generator, don't need to be
59
// perfectly sequential or perfectly distributed,
60
// just fair well distributed
61
// but very important is extremely fast
62
::i32 i = m_i32;
63
if
(i >= m_iShareCount)
64
{
65
i = 0;
66
m_i32 = 1;
67
}
68
else
69
{
70
m_i32++;
71
}
72
73
74
void
* p = m_allocptra.get_data()[i]->Alloc();
75
76
((::i32 *) p)[0] = i;
77
78
return
&((::i32 *)p)[1];
79
80
}
81
82
inline
void
fixed_alloc::Free(
void
* p)
83
{
84
85
if
(p ==
nullptr
)
86
return
;
87
88
::i32 i = ((::i32 *)p)[-1];
89
90
m_allocptra.get_data()[i]->Free(&((::i32 *)p)[-1]);
91
92
}
93
94
95
96
97
98
99
extern
CLASS_DECL_ACME
fixed_alloc_array
g_fixedalloca;
fixed_alloc_array
Definition
fixed_alloc.h:125
platform
fixed_alloc_impl.h
Generated by
1.17.0