void *calqueue_get(void) { calqueue_node *node; void *payload; node = calqueue_deq(); if(node == NULL) { return NULL; } payload = node->payload; rsfree(node); return payload; }
calqueue_node *calqueue_get(void) { calqueue_node *node; pthread_spin_lock(&cal_spinlock); node = calqueue_deq(); pthread_spin_unlock(&cal_spinlock); if (node == NULL) { return NULL; } //printf("calqueue: estraendo %f, cwidth %f, bukettop %f, nbuckets %d, lastprio %f\n", node->timestamp, cwidth, buckettop, nbuckets, lastprio); return node; }
// This function returns the width that the buckets should have // based on a random sample of the queue so that there will be about 3 // items in each bucket. static double new_width(void) { //printf("calqueue: sto eseguendo new_width\n"); int nsamples, templastbucket, i, j; double templastprio; double tempbuckettop, average, newaverage; calqueue_node *temp[25]; // Init the temp node structure for (i = 0; i < 25; i++) { temp[i] = NULL; } // How many queue elements to sample? if (qsize < 2) return 1.0; if (qsize <= 5) nsamples = qsize; else nsamples = 5 + (int)((double)qsize / 10); if (nsamples > 25) nsamples = 25; // Store the current situation templastbucket = lastbucket; templastprio = lastprio; tempbuckettop = buckettop; resize_enabled = false; average = 0.; for (i = 0; i < nsamples; i++) { // Dequeue nodes to get a test sample and sum up the differences in time temp[i] = calqueue_deq(); if (i > 0) average += temp[i]->timestamp - temp[i - 1]->timestamp; } // Get the average average = average / (double)(nsamples - 1); newaverage = 0.; j = 0; // Re-insert temp node 0 //calqueue_put(temp[0]->timestamp, temp[0]->payload); calqueue_enq(temp[0]); // Recalculate ignoring large separations for (i = 1; i < nsamples; i++) { if ((temp[i]->timestamp - temp[i - 1]->timestamp) < (average * 2.0)) { newaverage += (temp[i]->timestamp - temp[i - 1]->timestamp); j++; } //calqueue_put(temp[i]->timestamp, temp[i]->payload); calqueue_enq(temp[i]); } // Free the temp structure (the events have been re-injected in the queue) // for (i = 0; i < 25; i++) { // if (temp[i] != NULL) { // free(temp[i]); // } // } // Compute new width newaverage = (newaverage / (double)j) * 3.0; /* this is the new width */ // Restore the original condition lastbucket = templastbucket; /* restore the original conditions */ lastprio = templastprio; buckettop = tempbuckettop; resize_enabled = true; return newaverage; }