uint32_t job_pool_jobs_count(void) { jobpool* jp = globalpool; uint32_t res; zassert(pthread_mutex_lock(&(jp->jobslock))); res = (jp->workers_total - jp->workers_avail) + queue_elements(jp->jobqueue); zassert(pthread_mutex_unlock(&(jp->jobslock))); return res; }
void job_heavyload_test(void) { jobpool* jp = globalpool; uint8_t hlstatus = 0; uint32_t load = 0; // make stupid gcc happy zassert(pthread_mutex_lock(&(jp->jobslock))); if (jp->workers_total - jp->workers_avail > jp->workers_himark) { hlstatus = 2; } if (jp->workers_total - jp->workers_avail < jp->workers_lomark) { hlstatus = 1; } if (hlstatus) { load = (jp->workers_total - jp->workers_avail) + queue_elements(jp->jobqueue); } zassert(pthread_mutex_unlock(&(jp->jobslock))); if (hlstatus) { masterconn_heavyload(load,hlstatus); } }
int main(void) { /* Declare YOUR variables here ! */ Stack mystk; Queue myqueue; char mess[BUFSIZ]; int i, nr; srand((unsigned int)time(NULL)); my_clearscrn(); printf("--- INITIALIZING A QUEUE, %d ELEMENTS, RANDOM INTEGER DATA ---", NR_OF_ITEMS); if ((myqueue = QUEUEinit(my_destroy)) == NULL) /* Initialize the queue... */ { printf("\nFatal error - bailing out...!"); exit(-1); } queue_elements(myqueue, NR_OF_ITEMS); /* Populate the queue... */ nr = QUEUEsize(myqueue)/2; /* Save half the size of the queue... */ sprintf(mess, "\nNext - let's DEQUEUE %d elements from our queue...", nr); prompt_and_pause(mess); prompt_and_pause("...and now PUSH them - on a brand, new STACK...!!"); if ((mystk = STACKinit(my_destroy)) == NULL) /* Set up a new stack... */ { printf("\nFatal error - bailing out...!"); exit(-1); } for (i = 0; i < nr; ++i) { void *piq, *pis; int retval; retval = QUEUEdequeue(myqueue, &piq); assert(retval == OK); sprintf(mess, "QUEUE: Dequeued: %02d (new frontvalue: %02d)", *(int *)piq, *(int *)QUEUEpeek(myqueue)); prompt_and_pause(mess); /* Check current stack top... */ pis = STACKpeek(mystk); /* Push the value just dequeued - from our queue... */ retval = STACKpush(mystk, piq); assert(retval == OK); if (pis == NULL) /* If this is the FIRST stack push... */ sprintf(mess, "STACK: Pushed : %02d (old stacktop : none)", *(int *)STACKpeek(mystk)); else sprintf(mess, "STACK: Pushed : %02d (old stacktop : %02d)", *(int *)STACKpeek(mystk), *(int *)pis); /* Print the message assembled above... */ prompt_and_pause(mess); } printf("\n--- CURRENT STATUS OF STACK AND QUEUE ---"); printf("\nStack: "); SLISTtraverse(mystk, print, SLIST_FWD); printf("\nQueue: "); SLISTtraverse(myqueue, print, SLIST_FWD); prompt_and_pause("\n\nLet's tidy up (destroy queue/stack) - Bye!"); SLISTdestroy(mystk); SLISTdestroy(myqueue); return 0; }