Пример #1
0
static Pair *
PairFromPool(cpBBTree *tree)
{
	// Share the pool of the master tree.
	// TODO would be lovely to move the pairs stuff into an external data structure.
	tree = GetMasterTree(tree);
	
	Pair *pair = tree->pooledPairs;
	
	if(pair){
		tree->pooledPairs = pair->a.next;
		return pair;
	} else {
		// Pool is exhausted, make more
		int count = CP_BUFFER_BYTES/sizeof(Pair);
		cpAssertHard(count, "Internal Error: Buffer size is too small.");
		
		Pair *buffer = (Pair *)cpcalloc(1, CP_BUFFER_BYTES);
		cpArrayPush(tree->allocatedBuffers, buffer);
		
		// push all but the first one, return the first instead
		for(int i=1; i<count; i++) PairRecycle(tree, buffer + i);
		return buffer;
	}
}
Пример #2
0
static void
PairsClear(Node *leaf, cpBBTree *tree)
{
	Pair *pair = leaf->PAIRS;
	leaf->PAIRS = NULL;
	
	while(pair){
		if(pair->a.leaf == leaf){
			Pair *next = pair->a.next;
			ThreadUnlink(pair->b);
			PairRecycle(tree, pair);
			pair = next;
		} else {
			Pair *next = pair->b.next;
			ThreadUnlink(pair->a);
			PairRecycle(tree, pair);
			pair = next;
		}
	}
}
Пример #3
0
static Pair *
PairFromPool(cpBBTree *tree)
{
    Pair *pair = tree->pooledPairs;
    
    if(pair){
        tree->pooledPairs = pair->a.next;
        return pair;
    } else {
        // Pool is exhausted, make more
        int count = CP_BUFFER_BYTES/sizeof(Pair);
        cpAssertHard(count, "Internal Error: Buffer size is too small.");
        
        Pair *buffer = (Pair *)cpcalloc(1, CP_BUFFER_BYTES);
        cpArrayPush(tree->allocatedBuffers, buffer);
        
        // push all but the first one, return the first instead
        for(int i=1; i<count; i++) PairRecycle(tree, buffer + i);
        return buffer;
    }
}