78 static pool_global_stats_t pool_global_stats; |
78 static pool_global_stats_t pool_global_stats; |
79 |
79 |
80 static int |
80 static int |
81 pool_internal_init() |
81 pool_internal_init() |
82 { |
82 { |
83 if (pool_global_stats.lock == NULL) { |
83 //if (pool_global_stats.lock == NULL) { |
84 pool_global_stats.lock = PR_NewLock(); |
84 // pool_global_stats.lock = PR_NewLock(); // TODO: remove |
85 } |
85 //} |
86 |
86 |
87 if (pool_config.block_size == 0) { |
87 if (pool_config.block_size == 0) { |
88 //ereport(LOG_INFORM, XP_GetAdminStr(DBT_poolInitInternalAllocatorDisabled_)); |
88 //ereport(LOG_INFORM, XP_GetAdminStr(DBT_poolInitInternalAllocatorDisabled_)); |
89 } |
89 } |
90 |
90 |
232 |
232 |
233 if (newpool) { |
233 if (newpool) { |
234 /* Have to initialize now, as pools get created sometimes |
234 /* Have to initialize now, as pools get created sometimes |
235 * before pool_init can be called... |
235 * before pool_init can be called... |
236 */ |
236 */ |
237 if (pool_global_stats.lock == NULL) { |
237 //if (pool_global_stats.lock == NULL) { // TODO: remove |
238 pool_internal_init(); |
238 // pool_internal_init(); |
239 } |
239 //} |
240 |
240 |
241 newpool->used_blocks = NULL; |
241 newpool->used_blocks = NULL; |
242 newpool->free_blocks = NULL; |
242 newpool->free_blocks = NULL; |
243 newpool->free_size = 0; |
243 newpool->free_size = 0; |
244 newpool->free_num = 0; |
244 newpool->free_num = 0; |
260 //PR_SetError(PR_OUT_OF_MEMORY_ERROR, 0); |
260 //PR_SetError(PR_OUT_OF_MEMORY_ERROR, 0); |
261 return NULL; |
261 return NULL; |
262 } |
262 } |
263 |
263 |
264 /* Add to known pools list */ |
264 /* Add to known pools list */ |
265 PR_Lock(pool_global_stats.lock); |
265 |
266 newpool->next = pool_global_stats.poolList; |
266 // NOTICE: |
267 pool_global_stats.poolList = newpool; |
267 // known pools list removed |
268 ++pool_global_stats.createCnt; |
268 |
|
269 //PR_Lock(pool_global_stats.lock); |
|
270 //newpool->next = pool_global_stats.poolList; |
|
271 //pool_global_stats.poolList = newpool; |
|
272 //++pool_global_stats.createCnt; |
269 #ifdef PER_POOL_STATISTICS |
273 #ifdef PER_POOL_STATISTICS |
270 newpool->stats.poolId = pool_global_stats.createCnt; |
274 newpool->stats.poolId = pool_global_stats.createCnt; |
271 #endif /* PER_POOL_STATISTICS */ |
275 #endif /* PER_POOL_STATISTICS */ |
272 PR_Unlock(pool_global_stats.lock); |
276 //PR_Unlock(pool_global_stats.lock); |
273 |
277 |
274 } |
278 } |
275 else { |
279 else { |
276 //ereport(LOG_CATASTROPHE, XP_GetAdminStr(DBT_poolCreateOutOfMemory_1)); |
280 //ereport(LOG_CATASTROPHE, XP_GetAdminStr(DBT_poolCreateOutOfMemory_1)); |
277 //PR_SetError(PR_OUT_OF_MEMORY_ERROR, 0); |
281 //PR_SetError(PR_OUT_OF_MEMORY_ERROR, 0); |
335 { |
339 { |
336 pool_t *pool = (pool_t *)pool_handle; |
340 pool_t *pool = (pool_t *)pool_handle; |
337 block_t *tmp_blk; |
341 block_t *tmp_blk; |
338 unsigned long blen; |
342 unsigned long blen; |
339 |
343 |
340 PR_ASSERT(pool != NULL); |
344 //PR_ASSERT(pool != NULL); |
341 |
345 |
342 if (pool == NULL) |
346 if (pool == NULL) |
343 return; |
347 return; |
344 |
348 |
345 /* Fix up curr_block. There should always be a curr_block. */ |
349 /* Fix up curr_block. There should always be a curr_block. */ |
346 tmp_blk = pool->curr_block; |
350 tmp_blk = pool->curr_block; |
347 PR_ASSERT(tmp_blk != NULL); |
351 //PR_ASSERT(tmp_blk != NULL); |
348 |
352 |
349 /* Start with curr_block, then scan blocks on used_blocks list */ |
353 /* Start with curr_block, then scan blocks on used_blocks list */ |
350 for (;;) { |
354 for (;;) { |
351 |
355 |
352 /* Check if the mark is at the end of this block */ |
356 /* Check if the mark is at the end of this block */ |
363 blen = tmp_blk->start - (char *)mark; |
367 blen = tmp_blk->start - (char *)mark; |
364 } else { |
368 } else { |
365 blen = tmp_blk->end - (char *)mark; |
369 blen = tmp_blk->end - (char *)mark; |
366 } |
370 } |
367 pool->size -= blen; |
371 pool->size -= blen; |
368 PR_ASSERT(pool->size >= 0); |
372 //PR_ASSERT(pool->size >= 0); |
369 tmp_blk->start = (char *)mark; |
373 tmp_blk->start = (char *)mark; |
370 pool->curr_block = tmp_blk; |
374 pool->curr_block = tmp_blk; |
371 break; |
375 break; |
372 } |
376 } |
373 |
377 |
380 /* Count the entire size of a used_block */ |
384 /* Count the entire size of a used_block */ |
381 blen = tmp_blk->end - tmp_blk->data; |
385 blen = tmp_blk->end - tmp_blk->data; |
382 } |
386 } |
383 tmp_blk->start = tmp_blk->data; |
387 tmp_blk->start = tmp_blk->data; |
384 pool->size -= blen; |
388 pool->size -= blen; |
385 PR_ASSERT(pool->size >= 0); |
389 //PR_ASSERT(pool->size >= 0); |
386 |
390 |
387 /* |
391 /* |
388 * If there are no more used blocks after this one, then set |
392 * If there are no more used blocks after this one, then set |
389 * this block up as the current block and return. |
393 * this block up as the current block and return. |
390 */ |
394 */ |
391 if (pool->used_blocks == NULL) { |
395 if (pool->used_blocks == NULL) { |
392 PR_ASSERT(mark == NULL); |
396 //PR_ASSERT(mark == NULL); |
393 pool->curr_block = tmp_blk; |
397 pool->curr_block = tmp_blk; |
394 break; |
398 break; |
395 } |
399 } |
396 |
400 |
397 /* Otherwise free this block one way or another */ |
401 /* Otherwise free this block one way or another */ |
416 /* Limit exceeded - free block */ |
420 /* Limit exceeded - free block */ |
417 _free_block(tmp_blk); |
421 _free_block(tmp_blk); |
418 } |
422 } |
419 |
423 |
420 #ifdef PER_POOL_STATISTICS |
424 #ifdef PER_POOL_STATISTICS |
421 ++pool->stats.blkFree; |
425 //++pool->stats.blkFree; |
422 #endif /* PER_POOL_STATISTICS */ |
426 #endif /* PER_POOL_STATISTICS */ |
423 |
427 |
424 /* Remove next block from used blocks list */ |
428 /* Remove next block from used blocks list */ |
425 tmp_blk = pool->used_blocks; |
429 tmp_blk = pool->used_blocks; |
426 pool->used_blocks = tmp_blk->next; |
430 pool->used_blocks = tmp_blk->next; |
455 |
459 |
456 { |
460 { |
457 pool_t **ppool; |
461 pool_t **ppool; |
458 |
462 |
459 /* Remove from the known pools list */ |
463 /* Remove from the known pools list */ |
|
464 // NOTICE: known pools list removed |
|
465 /* |
460 PR_Lock(pool_global_stats.lock); |
466 PR_Lock(pool_global_stats.lock); |
461 for (ppool = &pool_global_stats.poolList; |
467 for (ppool = &pool_global_stats.poolList; |
462 *ppool; ppool = &(*ppool)->next) { |
468 *ppool; ppool = &(*ppool)->next) { |
463 if (*ppool == pool) { |
469 if (*ppool == pool) { |
464 ++pool_global_stats.destroyCnt; |
470 ++pool_global_stats.destroyCnt; |
465 *ppool = pool->next; |
471 *ppool = pool->next; |
466 break; |
472 break; |
467 } |
473 } |
468 } |
474 } |
469 PR_Unlock(pool_global_stats.lock); |
475 PR_Unlock(pool_global_stats.lock); |
|
476 */ |
470 } |
477 } |
471 |
478 |
472 #ifdef POOL_ZERO_DEBUG |
479 #ifdef POOL_ZERO_DEBUG |
473 memset(pool, POOL_ZERO_DEBUG, sizeof(pool)); |
480 memset(pool, POOL_ZERO_DEBUG, sizeof(pool)); |
474 #endif /* POOL_ZERO_DEBUG */ |
481 #endif /* POOL_ZERO_DEBUG */ |
507 |
514 |
508 curr_block->start -= reqsize; /* keep structs in tact */ |
515 curr_block->start -= reqsize; /* keep structs in tact */ |
509 |
516 |
510 /* Count unallocated bytes in current block in pool size */ |
517 /* Count unallocated bytes in current block in pool size */ |
511 pool->size += curr_block->end - curr_block->start; |
518 pool->size += curr_block->end - curr_block->start; |
512 PR_ASSERT(pool->size >= 0); |
519 //PR_ASSERT(pool->size >= 0); |
513 #ifdef PER_POOL_STATISTICS |
520 #ifdef PER_POOL_STATISTICS |
514 if (pool->size > pool->stats.maxAlloc) { |
521 if (pool->size > pool->stats.maxAlloc) { |
515 pool->stats.maxAlloc = pool->size; |
522 pool->stats.maxAlloc = pool->size; |
516 } |
523 } |
517 #endif /* PER_POOL_STATISTICS */ |
524 #endif /* PER_POOL_STATISTICS */ |
538 ptr = curr_block->start; |
545 ptr = curr_block->start; |
539 curr_block->start += reqsize; |
546 curr_block->start += reqsize; |
540 } |
547 } |
541 |
548 |
542 pool->size += reqsize; |
549 pool->size += reqsize; |
543 PR_ASSERT(pool->size >= 0); |
550 //PR_ASSERT(pool->size >= 0); |
544 |
551 |
545 #ifdef PER_POOL_STATISTICS |
552 #ifdef PER_POOL_STATISTICS |
546 if (pool->size > pool->stats.maxAlloc) { |
553 if (pool->size > pool->stats.maxAlloc) { |
547 pool->stats.maxAlloc = pool->size; |
554 pool->stats.maxAlloc = pool->size; |
548 } |
555 } |