/* set tree to use a shared memory pool */ int cp_avltree_share_mempool(cp_avltree *tree, cp_shared_mempool *pool) { int rc; if ((rc = cp_avltree_txlock(tree, COLLECTION_LOCK_WRITE))) return rc; if (tree->mempool) { if (tree->items) { rc = ENOTEMPTY; goto DONE; } cp_mempool_destroy(tree->mempool); } tree->mempool = cp_shared_mempool_register(pool, sizeof(cp_avlnode)); if (tree->mempool == NULL) { rc = ENOMEM; goto DONE; } DONE: cp_avltree_txunlock(tree); return rc; }
/* set tree to use given mempool or allocate a new one if pool is NULL */ int cp_avltree_use_mempool(cp_avltree *tree, cp_mempool *pool) { int rc = 0; if ((rc = cp_avltree_txlock(tree, COLLECTION_LOCK_WRITE))) return rc; if (pool) { if (pool->item_size < sizeof(cp_avlnode)) { rc = EINVAL; goto DONE; } if (tree->mempool) { if (tree->items) { rc = ENOTEMPTY; goto DONE; } cp_mempool_destroy(tree->mempool); } cp_mempool_inc_refcount(pool); tree->mempool = pool; } else { tree->mempool = cp_mempool_create_by_option(COLLECTION_MODE_NOSYNC, sizeof(cp_avlnode), 0); if (tree->mempool == NULL) { rc = ENOMEM; goto DONE; } } DONE: cp_avltree_txunlock(tree); return rc; }
lkfqDestQueue(lkfq_tc_t * pQ) { CCURASSERT(pQ); if(pQ->tQFree.pRbQs) { lkfqFlushFreeList(pQ); lfds611_queue_delete(pQ->tQFree.pRbQs, NULL, NULL ); pQ->tQFree.pRbQs = NULL; pthread_mutex_destroy(&(pQ->tQFree.tLock)); } if(pQ->tQAlloc.pRbQs) { lkfqFlushAllocList(pQ); lfds611_queue_delete(pQ->tQAlloc.pRbQs, NULL, NULL ); pQ->tQAlloc.pRbQs = NULL; pthread_mutex_destroy(&(pQ->tQAlloc.tLock)); } if(pQ->pMp) cp_mempool_destroy(pQ->pMp); }