12
12
* `insert_after`. If `insert_after` is NULL, then insert block at the
13
13
* head of the linked list.
14
14
*/
15
- static struct mp_block * mem_pool_alloc_block (struct mem_pool * mem_pool , size_t block_alloc , struct mp_block * insert_after )
15
+ static struct mp_block * mem_pool_alloc_block (struct mem_pool * pool ,
16
+ size_t block_alloc ,
17
+ struct mp_block * insert_after )
16
18
{
17
19
struct mp_block * p ;
18
20
19
- mem_pool -> pool_alloc += sizeof (struct mp_block ) + block_alloc ;
21
+ pool -> pool_alloc += sizeof (struct mp_block ) + block_alloc ;
20
22
p = xmalloc (st_add (sizeof (struct mp_block ), block_alloc ));
21
23
22
24
p -> next_free = (char * )p -> space ;
@@ -26,8 +28,8 @@ static struct mp_block *mem_pool_alloc_block(struct mem_pool *mem_pool, size_t b
26
28
p -> next_block = insert_after -> next_block ;
27
29
insert_after -> next_block = p ;
28
30
} else {
29
- p -> next_block = mem_pool -> mp_block ;
30
- mem_pool -> mp_block = p ;
31
+ p -> next_block = pool -> mp_block ;
32
+ pool -> mp_block = p ;
31
33
}
32
34
33
35
return p ;
@@ -42,11 +44,11 @@ void mem_pool_init(struct mem_pool *pool, size_t initial_size)
42
44
mem_pool_alloc_block (pool , initial_size , NULL );
43
45
}
44
46
45
- void mem_pool_discard (struct mem_pool * mem_pool , int invalidate_memory )
47
+ void mem_pool_discard (struct mem_pool * pool , int invalidate_memory )
46
48
{
47
49
struct mp_block * block , * block_to_free ;
48
50
49
- block = mem_pool -> mp_block ;
51
+ block = pool -> mp_block ;
50
52
while (block )
51
53
{
52
54
block_to_free = block ;
@@ -58,11 +60,11 @@ void mem_pool_discard(struct mem_pool *mem_pool, int invalidate_memory)
58
60
free (block_to_free );
59
61
}
60
62
61
- mem_pool -> mp_block = NULL ;
62
- mem_pool -> pool_alloc = 0 ;
63
+ pool -> mp_block = NULL ;
64
+ pool -> pool_alloc = 0 ;
63
65
}
64
66
65
- void * mem_pool_alloc (struct mem_pool * mem_pool , size_t len )
67
+ void * mem_pool_alloc (struct mem_pool * pool , size_t len )
66
68
{
67
69
struct mp_block * p = NULL ;
68
70
void * r ;
@@ -71,26 +73,26 @@ void *mem_pool_alloc(struct mem_pool *mem_pool, size_t len)
71
73
if (len & (sizeof (uintmax_t ) - 1 ))
72
74
len += sizeof (uintmax_t ) - (len & (sizeof (uintmax_t ) - 1 ));
73
75
74
- if (mem_pool -> mp_block &&
75
- mem_pool -> mp_block -> end - mem_pool -> mp_block -> next_free >= len )
76
- p = mem_pool -> mp_block ;
76
+ if (pool -> mp_block &&
77
+ pool -> mp_block -> end - pool -> mp_block -> next_free >= len )
78
+ p = pool -> mp_block ;
77
79
78
80
if (!p ) {
79
- if (len >= (mem_pool -> block_alloc / 2 ))
80
- return mem_pool_alloc_block (mem_pool , len , mem_pool -> mp_block );
81
+ if (len >= (pool -> block_alloc / 2 ))
82
+ return mem_pool_alloc_block (pool , len , pool -> mp_block );
81
83
82
- p = mem_pool_alloc_block (mem_pool , mem_pool -> block_alloc , NULL );
84
+ p = mem_pool_alloc_block (pool , pool -> block_alloc , NULL );
83
85
}
84
86
85
87
r = p -> next_free ;
86
88
p -> next_free += len ;
87
89
return r ;
88
90
}
89
91
90
- void * mem_pool_calloc (struct mem_pool * mem_pool , size_t count , size_t size )
92
+ void * mem_pool_calloc (struct mem_pool * pool , size_t count , size_t size )
91
93
{
92
94
size_t len = st_mult (count , size );
93
- void * r = mem_pool_alloc (mem_pool , len );
95
+ void * r = mem_pool_alloc (pool , len );
94
96
memset (r , 0 , len );
95
97
return r ;
96
98
}
@@ -113,12 +115,12 @@ char *mem_pool_strndup(struct mem_pool *pool, const char *str, size_t len)
113
115
return memcpy (ret , str , actual_len );
114
116
}
115
117
116
- int mem_pool_contains (struct mem_pool * mem_pool , void * mem )
118
+ int mem_pool_contains (struct mem_pool * pool , void * mem )
117
119
{
118
120
struct mp_block * p ;
119
121
120
122
/* Check if memory is allocated in a block */
121
- for (p = mem_pool -> mp_block ; p ; p = p -> next_block )
123
+ for (p = pool -> mp_block ; p ; p = p -> next_block )
122
124
if ((mem >= ((void * )p -> space )) &&
123
125
(mem < ((void * )p -> end )))
124
126
return 1 ;
0 commit comments