int usbAllocateEndpointExtension (UsbEndpoint *endpoint) { UsbDevice *device = endpoint->device; UsbDeviceExtension *devx = device->extension; UsbEndpointExtension *eptx; if ((eptx = malloc(sizeof(*eptx)))) { if ((eptx->requests = newQueue(NULL, NULL))) { int flags; { char name[0X80]; int length = 0; if (devx->configuration != 1) { int count; sprintf(&name[length], "cfg%d%n", devx->configuration, &count); length += count; } { int count; sprintf(&name[length], "if%d%n", devx->interface, &count); length += count; } if (devx->alternative != 0) { int count; sprintf(&name[length], ".%d%n", devx->alternative, &count); length += count; } { const UsbEndpointDescriptor *descriptor = endpoint->descriptor; UsbEndpointDirection direction = USB_ENDPOINT_DIRECTION(descriptor); const char *prefix; switch (direction) { case UsbEndpointDirection_Input: prefix = "in"; flags = O_RDONLY; break; case UsbEndpointDirection_Output: prefix = "out"; flags = O_WRONLY; break; default: logMessage(LOG_ERR, "USB unsupported endpoint direction: %02X", direction); goto nameError; } { int count; sprintf(&name[length], "%s%d%n", prefix, USB_ENDPOINT_NUMBER(descriptor), &count); length += count; } } eptx->name = strdup(name); } if (eptx->name) { if (usbOpenEndpointFiles(devx->path, eptx->name, &eptx->data, &eptx->status, flags)) { endpoint->extension = eptx; return 1; } free(eptx->name); } nameError: deallocateQueue(eptx->requests); } free(eptx); } return 0; }
/**************************** runSimulation ************************************ void runSimulation(Simulation sim, int iTimeLimit) Purpose: Goes through a list of events in a Simulation and run them as they are encountered. Parameters: I Simulation sim The simulation variable containing the list of events. I int iTimeLimit A time limit upon which the simulation will terminate if it is reached before all of the events are ran. Returns: Notes: *******************************************************************************/ void runSimulation(Simulation sim, int iTimeLimit) { //Variables Event event; Server server1, server2; Queue queue1, queue2; //create servers and queues server1 = newServer("Server 1"); queue1 = newQueue("Queue 1"); if (sim->cRunType == 'A') { server2 = newServer("Server 2"); queue2 = newQueue("Queue 2"); } //begin simulation printHeader(sim); while (removeLL(sim->eventList, &event)) { if (event.iTime > iTimeLimit) { printFooter(sim, queue1, queue2); freeServersAndQueues(sim, server1, server2, queue1, queue2); ErrExit(ERR_BAD_INPUT, "Event time (%d) is out of simulation bounds (%d)\n", event.iTime, iTimeLimit); } sim->iClock = event.iTime; switch (event.iEventType) { case EVT_ARRIVAL: arrival(sim, &event.widget); queueUp(sim, &event.widget, queue1); seize(sim, queue1, server1); break; case EVT_SERVER1_COMPLETE: release(sim, queue1, server1); if (sim->cRunType == 'A') //Alternative A follows up with server 2 { queueUp(sim, &event.widget, queue2); seize(sim, queue2, server2); } else //Alternative B and Current leave after server 1 { leaveSystem(sim, &event.widget); } break; case EVT_SERVER2_COMPLETE: release(sim, queue2, server2); leaveSystem(sim, &event.widget); break; default: ErrExit(ERR_ALGORITHM, "Unknown event type: %d\n", event.iEventType); } } printFooter(sim, queue1, queue2); freeServersAndQueues(sim, server1, server2, queue1, queue2); }
void *filter(void *p){ queue_t *inQueue = (queue_t *) p; queue_t *outQueue = NULL; unsigned long long val = 0; unsigned long long divider = 2; pthread_t *nextThread = NULL; while(1){ val = dequeue(inQueue); if(outQueue != NULL){ // If the value 1 is given, start with terminating this filter. if(val == 1){ enqueue(outQueue, val); void *result; pthread_join(*nextThread, &result); free(nextThread); freeQueue(outQueue); break; } /* * If the value is not a multiple of this filter's divider * send it to the next filter. */ if(val % divider != 0){ enqueue(outQueue, val); } }else{ /* * No next filter yet, the first value in the queue is this * filter's divider. */ divider = val; if(val == 1){ break; } printf("%llu\n", divider); /* * Search for the next non multiple of the divider, the * value found will be the divider of the next filter. * If a 1 (terminate) is found, we don't have to build the * next filter. */ do{ val = dequeue(inQueue); }while(val != 1 && val % divider == 0); if(val != 1){ outQueue = newQueue(); if(outQueue == NULL){ break; } enqueue(outQueue, val); nextThread = startFilter(outQueue); }else{ break; } } } return NULL; }
void bandwidth(Graph* g, int* result) { int* degree = (int*) malloc((g->nvertices+1) * sizeof(int)); int* visit = (int*) malloc((g->nvertices+1) * sizeof(int)); int i; int min = 1; for(i=1; i<=g->nvertices; i++) { visit[i] = 0; int size = 0; Node* node = g->nodes[i]; while(node != NULL) { size++; node = node->next; } degree[i] = size; if (degree[min] > size) { min = i; } } Queue* q = newQueue(g->nvertices); enqueue(q, min); int ri = 0; while (!emptyQueue(q)) { int v = dequeue(q); if (!visit[v]) { visit[v] = 1; result[ri++] = v; // sort the edge by the other vertex's degree if (g->nodes[v] != NULL) { Node* head = g->nodes[v]->next; g->nodes[v]->next = NULL; while (head != NULL) { Node* prev = NULL; Node* current = g->nodes[v]; while (current != NULL) { if (degree[current->label] <= degree[head->label]) { prev = current; current = current->next; } else { break; } } if (current == NULL) { prev->next = head; head = head->next; prev->next->next = NULL; } else { if (prev == NULL) { g->nodes[v] = head; head = head->next; g->nodes[v]->next = current; } else { prev->next = head; head = head->next; prev->next->next = current; } } } } Node* node = g->nodes[v]; while (node != NULL) { if (!visit[node->label]) { enqueue(q,node->label); } node = node->next; } } } }
void initArrayOfQueue(Queue * stimuliQ[BARS]) { int i; for (i = 0; i < BARS; i++) { stimuliQ[i] = newQueue(); } }
static Queue * createCommandQueue (void *data) { return newQueue(deallocateCommandQueueItem, NULL); }
static Queue * createKeyEventQueue (void *data) { return newQueue(deallocateKeyEventQueueItem, NULL); }
int main ( int argc, char *argv[]) { if (argc > 4 || argc < 3) { printf ("%s\n","Número de argumentos inválido."); printf ("%s\n","La sintaxis correcta es: arbol [-x] -f <nombre de archivo de salida>"); }else if (argc == 3) { if (strcmp(argv[1] , "-f") == 0){ // Se prepara la creacion del archivo. FILE *archivo; char caracter; int len= 1000; char buffer[len]; int i=0; int cont=0; archivo = fopen(argv[2],"w"); queue *cola; cola = newQueue(); node *primero; int a = 1; int b= 2; int c; //se procede a la escritura para una entrada de 3 argumentos. c = b + b; fprintf(archivo,"%d",c); /* Escribe los datos */ fprintf(archivo,"%s","\n"); /* Escribe los datos */ fclose(archivo); /* Cierra los archivos */ return 0; }else{ printf ("%s\n","error de sintaxis"); printf ("%s\n","La sintaxis correcta es: arbol [-x] -f <nombre de archivo de salida>"); }// fin del else. }//fin del else if else{ // Se prepara la creacion del archivo. FILE *archivo; char caracter; int len= 1000; char buffer[len]; int i=0; int cont=0; archivo = fopen(argv[3],"w"); queue *cola; cola = newQueue(); node *primero; int a = 1; int b= 2; int c; //se procede a la escritura para una entrada de 4 argumentos. c = a + b; fprintf(archivo,"%d",c); /* Escribe los datos */ fprintf(archivo,"%s","\n"); /* Escribe los datos */ fclose(archivo); /* Cierra los archivos */ return 0; }//fin del else. }
tnode* generateTree(int s, char str[]) { tnode* root = getNode(0,'o'); tnode* tmp; queue* q = newQueue(); push(root, q); int i,t = pow(2,s)-1; for (i=0; i<t; i++) { tmp = pop(q); int a = tmp->data; char b = reverse(tmp->orand); tmp->lchild = getNode(2*a+1,b); tmp->lchild->parent = tmp; push(tmp->lchild, q); tmp->rchild = getNode(2*a+2,b); tmp->rchild->parent = tmp; push(tmp->rchild, q); } /*------NOW EVALUATING All NODES-------*/ t++; int j=0; for (i=0; i<t; i++) { tmp = pop(q); if((tmp->data)%2 != 0) { tmp->data = evaluate(str,j,s); // printf("--%d",tmp->data); j++; } else { tmp->data = evaluate(str,j,s); // printf("--%d",tmp->data); j++; push(tmp->parent, q); } } while(!isEmpty(q)) { tmp = pop(q); if((tmp->data)%2 != 0 || tmp->data == 0) { if(tmp->orand == 'o') tmp->data = max(tmp->lchild->data, tmp->rchild->data); else tmp->data = min(tmp->lchild->data, tmp->rchild->data); } else { if(tmp->orand == 'o') tmp->data = max(tmp->lchild->data, tmp->rchild->data); else tmp->data = min(tmp->lchild->data, tmp->rchild->data); push(tmp->parent, q); } } return root; }