Ejemplo n.º 1
0
void * rwOp(void* arg) {
	struct data_t *data;
	data = (struct data_t *) arg;
	char* b1 = initializeBlock(true,data -> blockSize); 
	char* b2 = initializeBlock(true, data -> blockSize); 
	char* tm = initializeBlock(false, data -> blockSize);

	char* b1_2 = b1; 
	char* b2_2 = b2; 
	char* tm2 = tm;

	SEQ(b1, b1_2, b2, b2_2, tm, tm2, data);
	RAND(b1, b1_2, b2, b2_2, tm, tm2, data);

	pthread_exit(NULL); 
}
/********************************************************************
* Clear an existing block
* Free all sentences in the Block struct and set iLength to 0.
********************************************************************/
void clearBlock(struct Block *stBlock) {
    int i;

    DEBUG ? printf("clearBlock\n") : 0;
    for (i = 0; i < stBlock->iLength; i++) {
        if (stBlock->stSentence[i]) {
            clearSentence(stBlock->stSentence[i]);
            free(stBlock->stSentence[i]);
        }
    }
    free(stBlock->stSentence);
    initializeBlock(&stBlock);
}
Ejemplo n.º 3
0
void Pool::increasePool()
{
	std::cout << "Expanding pool..." << std::endl;
	new_byte_array = new char*[poolSize+1];
	new_byte_array[poolSize] = new char[len];
		
	if(byte_array != nullptr)
		std::memcpy(new_byte_array,byte_array,poolSize);
	initializeBlock(new_byte_array[poolSize]);

	delete[] byte_array;
	byte_array = new_byte_array;

	freeptr = &byte_array[poolSize][0];
	endptr = &byte_array[poolSize][len];
	poolSize++;
}
/********************************************************************
* Read sentence block from the socket...keeps reading sentences
* until it encounters !done, !trap or !fatal from the socket
********************************************************************/
struct Block readBlock(int fdSock) {
    struct Sentence stSentence;
    struct Block    stBlock;

    initializeBlock(&stBlock);

    DEBUG ? printf("readBlock\n") : 0;

    do {
        stSentence = readSentence(fdSock);
        DEBUG ? printf("readSentence succeeded.\n") : 0;

        addSentenceToBlock(&stBlock, &stSentence);
        DEBUG ? printf("addSentenceToBlock succeeded\n") : 0;
    } while (stSentence.iReturnValue == 0);


    DEBUG ? printf("readBlock completed successfully\n") : 0;

    return stBlock;
}