char *test_destroy() { mu_assert(queue != NULL, "Failed toc reate queue #2"); Queue_destroy(queue); return NULL; }
static void* start_consumer(void* data) { Consumer* consumer = (Consumer*)data; int* x; int has_item = 0; while ((has_item = consumer->f_get_item(consumer->queue, &x)) != -1) { if (has_item == 1) { int i = *x; cx_free(x); consumer->processed++; XFLOG("Consumer[%d] - received %d", consumer->id, i); /* simulate processing delay */ #ifdef PROCESSING_DELAY_MAX_MSEC usleep((rand() % PROCESSING_DELAY_MAX_MSEC) * 1000); #endif // queue is destroyed on the last request if (i == (NITERATATIONS - 1)) { XFDBG("Consumer[%d] I'm processing the last request", consumer->id); Queue_destroy(consumer->queue); } } } XFDBG("Consumer[%d] Leaving inactive queue", consumer->id); pthread_exit(NULL); }
void Connection_free(Connection* conn) { if (conn->f_free_state) conn->f_free_state(conn->state); Queue_destroy(conn->response_queue); cx_free(conn); }
/** * Pretty formatting of a binary tree to the output stream * * Parameters: * fp FILE * to print to. Just use 'stdout' if you are unsure. * root Root of Huffman Coding Tree that we're printing * level Control how wide you want the tree to sparse (eg, level 1 has * the minimum space between nodes, while level 2 has a larger * space between nodes) * indent Change this to add some indent space to the left (eg, * indent of 0 means the lowest level of the left node will * stick to the left margin) */ static void HuffNode_printPretty_Worker(FILE * fp, HuffNode * root, int level, int indent) { int r, i; // for-loop indices int h = HuffNode_height(root); // eq of the length of branch for each node of each level int branch_sz = 2*((1 << h) - 1) - (3-level)*(1 << (h-1)); // distance between left neighbor node's right arm and right neighbor // node's left arm int node_spacing_sz = 2 + (level+1)*(1 << h); // starting space to the first node to print of each level // (for the left most node of each level only) int start_sz = branch_sz + (3-level) + indent; Queue * Q = Queue_create(); Queue_pushBack(Q, root); int curr_tree_width = 1; for (r = 1; r < h; r++) { print_branches(fp, Q, branch_sz, node_spacing_sz, start_sz, curr_tree_width); branch_sz = branch_sz / 2 - 1; node_spacing_sz = node_spacing_sz / 2 + 1; start_sz = branch_sz + (3-level) + indent; print_nodes(fp, Q, branch_sz, node_spacing_sz, start_sz, curr_tree_width); for (i = 0; i < curr_tree_width; i++) { HuffNode * currNode = Queue_popFront(Q); if(currNode) { Queue_pushBack(Q, currNode->left); Queue_pushBack(Q, currNode->right); } else { Queue_pushBack(Q, NULL); Queue_pushBack(Q, NULL); } } curr_tree_width *= 2; } print_branches(fp, Q, branch_sz, node_spacing_sz, start_sz, curr_tree_width); print_leaves(fp, Q, indent, level, curr_tree_width); Queue_destroy(Q); }