/[LeafOK_CVS]/lbbs/src/memory_pool.c
ViewVC logotype

Diff of /lbbs/src/memory_pool.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 1.9 by sysadm, Tue Nov 11 00:28:05 2025 UTC Revision 1.10 by sysadm, Fri Dec 19 06:16:27 2025 UTC
# Line 21  MEMORY_POOL *memory_pool_init(size_t nod Line 21  MEMORY_POOL *memory_pool_init(size_t nod
21    
22          if (node_size < sizeof(void *))          if (node_size < sizeof(void *))
23          {          {
24                  log_error("Error: node_size < sizeof(void *)\n");                  log_error("Error: node_size < sizeof(void *)");
25                  return NULL;                  return NULL;
26          }          }
27    
28          p_pool = malloc(sizeof(MEMORY_POOL));          p_pool = malloc(sizeof(MEMORY_POOL));
29          if (p_pool == NULL)          if (p_pool == NULL)
30          {          {
31                  log_error("malloc(MEMORY_POOL) error: OOM\n");                  log_error("malloc(MEMORY_POOL) error: OOM");
32                  return NULL;                  return NULL;
33          }          }
34    
# Line 41  MEMORY_POOL *memory_pool_init(size_t nod Line 41  MEMORY_POOL *memory_pool_init(size_t nod
41          p_pool->p_chunks = malloc(sizeof(void *) * (size_t)chunk_count_limit);          p_pool->p_chunks = malloc(sizeof(void *) * (size_t)chunk_count_limit);
42          if (p_pool->p_chunks == NULL)          if (p_pool->p_chunks == NULL)
43          {          {
44                  log_error("malloc(sizeof(void *) * %d) error: OOM\n", chunk_count_limit);                  log_error("malloc(sizeof(void *) * %d) error: OOM", chunk_count_limit);
45                  free(p_pool);                  free(p_pool);
46                  return NULL;                  return NULL;
47          }          }
# Line 62  void memory_pool_cleanup(MEMORY_POOL *p_ Line 62  void memory_pool_cleanup(MEMORY_POOL *p_
62    
63          if (p_pool->node_count_allocated > 0)          if (p_pool->node_count_allocated > 0)
64          {          {
65                  log_error("Still have %d in-use nodes\n", p_pool->node_count_allocated);                  log_error("Still have %d in-use nodes", p_pool->node_count_allocated);
66          }          }
67    
68          while (p_pool->chunk_count > 0)          while (p_pool->chunk_count > 0)
# Line 83  inline static void *memory_pool_add_chun Line 83  inline static void *memory_pool_add_chun
83    
84          if (p_pool->chunk_count >= p_pool->chunk_count_limit)          if (p_pool->chunk_count >= p_pool->chunk_count_limit)
85          {          {
86                  log_error("Chunk count limit %d reached\n", p_pool->chunk_count);                  log_error("Chunk count limit %d reached", p_pool->chunk_count);
87                  return NULL;                  return NULL;
88          }          }
89          p_chunk = malloc(p_pool->node_size * p_pool->node_count_per_chunk);          p_chunk = malloc(p_pool->node_size * p_pool->node_count_per_chunk);
90          if (p_chunk == NULL)          if (p_chunk == NULL)
91          {          {
92                  log_error("malloc(%d * %d) error: OOM\n", p_pool->node_size, p_pool->node_count_per_chunk);                  log_error("malloc(%d * %d) error: OOM", p_pool->node_size, p_pool->node_count_per_chunk);
93                  return NULL;                  return NULL;
94          }          }
95    
# Line 117  void *memory_pool_alloc(MEMORY_POOL *p_p Line 117  void *memory_pool_alloc(MEMORY_POOL *p_p
117    
118          if (p_pool == NULL)          if (p_pool == NULL)
119          {          {
120                  log_error("NULL pointer error\n");                  log_error("NULL pointer error");
121                  return NULL;                  return NULL;
122          }          }
123    
124          if (p_pool->p_free == NULL && memory_pool_add_chunk(p_pool) == NULL)          if (p_pool->p_free == NULL && memory_pool_add_chunk(p_pool) == NULL)
125          {          {
126                  log_error("Add chunk error\n");                  log_error("Add chunk error");
127                  return NULL;                  return NULL;
128          }          }
129    
# Line 140  void memory_pool_free(MEMORY_POOL *p_poo Line 140  void memory_pool_free(MEMORY_POOL *p_poo
140  {  {
141          if (p_pool == NULL)          if (p_pool == NULL)
142          {          {
143                  log_error("NULL pointer error\n");                  log_error("NULL pointer error");
144                  return;                  return;
145          }          }
146    
# Line 163  int memory_pool_check_node(MEMORY_POOL * Line 163  int memory_pool_check_node(MEMORY_POOL *
163    
164          if (p_pool == NULL || p_node == NULL)          if (p_pool == NULL || p_node == NULL)
165          {          {
166                  log_error("NULL pointer error\n");                  log_error("NULL pointer error");
167                  return -1;                  return -1;
168          }          }
169    
# Line 179  int memory_pool_check_node(MEMORY_POOL * Line 179  int memory_pool_check_node(MEMORY_POOL *
179                          }                          }
180                          else                          else
181                          {                          {
182                                  log_error("Address of node (%p) is not aligned with border of chunk %d [%p, %p)\n",                                  log_error("Address of node (%p) is not aligned with border of chunk %d [%p, %p)",
183                                                    i, p_node >= p_pool->p_chunks[i], (char *)(p_pool->p_chunks[i]) + chunk_size);                                                    i, p_node >= p_pool->p_chunks[i], (char *)(p_pool->p_chunks[i]) + chunk_size);
184                                  return -3;                                  return -3;
185                          }                          }
186                  }                  }
187          }          }
188    
189          log_error("Address of node is not in range of chunks\n");          log_error("Address of node is not in range of chunks");
190          return -2;          return -2;
191  }  }


Legend:
Removed lines/characters  
Changed lines/characters
  Added lines/characters

webmaster@leafok.com
ViewVC Help
Powered by ViewVC 1.3.0-beta1