static inline __must_check int init3Queues(struct xordev *dev) { int result = 0; TRY(OR_RETURN(result), result, initQueues(dev), "initialize destination device queues"); TRY(OR_GOTO(fail), result, initQueues(dev + 1), "initialize source1 device queues"); TRY(OR_GOTO(fail), result, initQueues(dev + 2), "initialize source2 device queues"); return result; fail: exit3Queues(dev + 2); return result; }
void initByDevices() { if(my_devices.size() == 0){ // FIXME insert error handling here } cl_platform_id platform; clGetDeviceInfo(my_devices[0].id(), CL_DEVICE_PLATFORM, sizeof(cl_platform_id), &platform, NULL); cl_context_properties properties[] = { CL_CONTEXT_PLATFORM, reinterpret_cast<cl_context_properties>(platform), 0 }; cl_int err; cl_context context = clCreateContext( properties, // context properties my_devices.size(), // number of devices my_devices.data(), // device IDs NULL, // error handling function NULL, // user data for error handling function &err // error code ); CLPP_CHECK_ERROR(err); my_resource.reset(context); initQueues(); }
int CAN_device_init(uint8_t channel, uint32_t baud) { pr_info("Initializing CAN"); pr_info_int(channel); pr_info_int_msg(" with baud rate ", baud); if (!initQueues()) { pr_info("CAN init queues failed\r\n"); return 0; } switch (channel) { case 0: CAN_device_init_1(baud); break; case 1: CAN_device_init_2(baud); break; default: pr_info("CAN init device failed\r\n"); return 0; } /* Clear out all filter values except 0. It accepts all. */ CAN_device_set_filter(channel, 0, 1, 0, 0, true); for (size_t i = 1; i < CAN_FILTER_COUNT; ++i) CAN_device_set_filter(channel, i, 0, 0, 0, false); pr_info("CAN init success!\r\n"); return 1; }
void LexFileStream::close() { if(m_f == stdin) { // setFileMode(stdin, m_oldMode); } else if(m_f) { // never close stdin fclose(m_f); } initQueues(); m_f = NULL; }
void Server::run_server() { //Buffer fuer Message message_t msg; //Queues erstellen initQueues(); write_msgid = w_msgid; read_msgid = r_msgid; // std::cout << "RUN SERVER" << std::endl; while (1 == 1) { if (msgrcv(r_msgid, &msg, sizeof(message_t) - sizeof(long), 0 , 0) == -1) { /* error handling */ std::cout << "Cant' receive message" << std::endl; } switch (msg.mType) { case 'R': regVehicle(msg.mText, msg.mPID); send_display(gridToString(grid)); break; case 'N': case 'W': case 'S': case 'E': moveVehicle(msg.mText, msg.mType); send_display(gridToString(grid)); break; case 'T': removeVehicle(msg.mText); send_display(gridToString(grid)); break; default: break; } } return; }
int CAN_device_init(uint8_t channel, uint32_t baud) { pr_info("CAN"); pr_info_int(channel); pr_info(" init @ "); pr_info_int(baud); if (initQueues()) { switch (channel) { case 0: CAN_device_init_1(baud); break; } pr_info(" win\r\n"); return 1; } else { pr_info(" fail\r\n"); return 0; } }
void initByPlatform(cl_platform_id platform, cl_device_type type) { cl_context_properties properties[] = { CL_CONTEXT_PLATFORM, reinterpret_cast<cl_context_properties>(platform), 0 }; cl_int err; cl_context context = clCreateContextFromType( properties, // context properties type, // type of devices NULL, // error handling function NULL, // user data for error handling function &err // error code ); CLPP_CHECK_ERROR(err); my_resource.reset(context); initQueues(); }
int main(int argc, char **argv) { PCB *job; // pointer used to move jobs between queues int jobPriority; int processStatus; //open file of jobs if(argc < 2) { printf("Dispatch list not found!\n"); return 0; } FILE *fd; fd = fopen(argv[1], "r"); if(fd == NULL) { printf("Could not open file %s.\n", argv[1]); return 0; } initQueues(); printf("Queues initialized successfully!\n"); createDispatchList(fd); printf("Read and stored all jobs in dispatch list!\n"); fclose(fd); // print out initial dispatch list if (VERBOSE) printQueue(dispatchName, dispatchQ); // START DISPATCHER while(1) { printf("\n-----------------------------------------\n"); printf("DISPATCHER TIME: %d SECONDS\n", clock); printf("-----------------------------------------\n"); if (SUPERVERBOSE) printf("DISPATCHER RESOURCE REPORT:\n"); if (SUPERVERBOSE) printf("Available Memory: %d\n", availableMem); if (SUPERVERBOSE) printf("Printers: %d\n", printers); if (SUPERVERBOSE) printf("Scanner: %d\n", scanner); if (SUPERVERBOSE) printf("Modem: %d\n", modem); if (SUPERVERBOSE) printf("CD Drives: %d\n", cddrives); // move all jobs with this time from dispatch to the submission queues // this happens on EVERY tick if (!isEmpty(dispatchQ)) { //assign all the jobs that are currently in the dispatch Queue while (dispatchQ->process->arrival_time <= clock) { //assign the jobs to the correct submission queue jobPriority = dispatchQ->process->priority; if (jobPriority == 0) { // realtimeq priority = 0 if (VERBOSE) printf("A new realtime job has arrived.\n"); job = dequeueFront(&dispatchQ); enqueueJob(realtimeQ, job); if (SUPERVERBOSE) printQueue(rtName, realtimeQ); } else if (jobPriority==1 || jobPriority==2 || jobPriority==3) { if (VERBOSE) printf("A new user job has arrived.\n"); job = dequeueFront(&dispatchQ); enqueueJob(userQ, job); if (SUPERVERBOSE) printQueue(userName, userQ); } if (isEmpty(dispatchQ)) break; } } // distribute user jobs into their priority queues bases on resources // happens on EVERY TICK if(isEmpty(userQ)==false){ int userQlength = getLength(userQ); int currJob = 0; // Go through entire queue only once while(currJob < userQlength){ //checking to make sure all the resources are avalable for the job if(resourcesAvailable(userQ)){ assignResources(userQ); printf("Successfuly allocated resources to a new user job.\n"); //gets the priority and the job off the userQ int userPriority; userPriority = userQ->process->priority; job = dequeueFront(&userQ); if (SUPERVERBOSE) printf("User Priority: %d\n", userPriority); //puts the job in the correct priority userQ if(userPriority==1){ enqueueJob(p1Q, job); } if(userPriority==2){ enqueueJob(p2Q, job); } if(userPriority ==3){ enqueueJob(p3Q, job); } // if resources arent avalable then job goes to the end of the queue } else { // safety check on if job requires too many resources if(userQ->process->mem_req > MAX_USER_MEMORY || userQ->process->printers > PRINTERS || userQ->process->scanners > SCANNERS || userQ->process->modems > MODEMS || userQ->process->cds > CDDRIVES) { // simply remove job job = dequeueFront(&userQ); free(job); userQlength--; }else { // cycle job to back of queue printf("A user job is waiting on resources...\n"); job = dequeueFront(&userQ); enqueueJob(userQ, job); } } currJob++; if (SUPERVERBOSE) printQueue(p1Name, p1Q); if (SUPERVERBOSE) printQueue(p2Name, p2Q); if (SUPERVERBOSE) printQueue(p3Name, p3Q); } // end while } // end userQ distributions /* Now check all the queues for a job to run. */ // Check the realtimeQ for a job first! if(isEmpty(realtimeQ)==false){ if(realtimeQ->process->pid < 0) { // job hasnt started yet so fork and exec realtimeQ->process->pid = fork(); if (realtimeQ->process->pid < 0) { fprintf(stderr, "Dispatcher failed to fork new process."); return 0; } else if(realtimeQ->process->pid == 0) { printJobDetails(realtimeQ); execl("./process", "process", "",NULL); } else { sleep(1); } } else { sleep(1); // RT processes never pause so just let it run } if (SUPERVERBOSE) printQueue(rtName, realtimeQ); realtimeQ->process->time_left--; //decrement time //check to see if it is zero if (VERBOSE) printf("Time left in real time process: %d\n", realtimeQ->process->time_left); if(realtimeQ->process->time_left == 0){ kill(realtimeQ->process->pid, SIGINT); // kill the process waitpid(realtimeQ->process->pid, &processStatus, WUNTRACED); freeMemSpace(realtimeQ); job = dequeueFront(&realtimeQ); free(job); } /* Now check lower priority Queues. The code for the lower priority queues will be very symmetrical */ } else if(isEmpty(p1Q)==false) { if(p1Q->process->pid < 0) { // job hasnt started yet so fork and exec p1Q->process->pid = fork(); if (p1Q->process->pid < 0) { fprintf(stderr, "Dispatcher failed to fork new process."); return 0; } else if(p1Q->process->pid == 0) { printJobDetails(p1Q); execl("./process", "process", "",NULL); } else { sleep(1); } } else { // it was previously paused, so resume it if (SUPERVERBOSE) printf("Attempting to resume process...\n"); kill(p1Q->process->pid, SIGCONT); sleep(1); // let it run for 1 s } if (SUPERVERBOSE) printQueue(p1Name, p1Q); //decrement time p1Q->process->time_left--; //check to see if it is zero if (VERBOSE) printf("Time left in p1Q process: %d\n", p1Q->process->time_left); if(p1Q->process->time_left == 0){ kill(p1Q->process->pid, SIGINT); // kill the process waitpid(p1Q->process->pid, &processStatus, WUNTRACED); freeMemSpace(p1Q); // free its memory // free all resources printers += p1Q->process->printers; scanner += p1Q->process->scanners; modem += p1Q->process->modems; cddrives += p1Q->process->cds; // remove the PCB from the queue job = dequeueFront(&p1Q); free(job); }else { // pause it and decrease its priority kill(p1Q->process->pid, SIGTSTP); waitpid(p1Q->process->pid, &processStatus, WUNTRACED); job = dequeueFront(&p1Q); enqueueJob(p2Q, job); } //check second user priority queue }else if(isEmpty(p2Q)==false){ if(p2Q->process->pid < 0) { // job hasnt started yet so fork and exec p2Q->process->pid = fork(); if (p2Q->process->pid < 0) { fprintf(stderr, "Dispatcher failed to fork new process."); return 0; } else if(p2Q->process->pid == 0) { printJobDetails(p2Q); execl("./process", "process", "",NULL); } else { sleep(1); } } else { // it was previously paused, so resume it if (SUPERVERBOSE) printf("Attempting to resume process...\n"); kill(p2Q->process->pid, SIGCONT); sleep(1); // let it run for 1 s } if (SUPERVERBOSE) printQueue(p2Name, p2Q); //decrement time p2Q->process->time_left--; //check to see if it is zero if (VERBOSE) printf("Time left in p2Q process: %d\n", p2Q->process->time_left); if(p2Q->process->time_left == 0){ kill(p2Q->process->pid, SIGINT); // kill the process waitpid(p2Q->process->pid, &processStatus, WUNTRACED); freeMemSpace(p2Q); // free its memory // free all resources printers += p2Q->process->printers; scanner += p2Q->process->scanners; modem += p2Q->process->modems; cddrives += p2Q->process->cds; // remove the PCB from the queue job = dequeueFront(&p2Q); free(job); }else { // pause it and decrease its priority kill(p2Q->process->pid, SIGTSTP); waitpid(p2Q->process->pid, &processStatus, WUNTRACED); job = dequeueFront(&p2Q); enqueueJob(p3Q, job); } //check third priority queue }else if(isEmpty(p3Q)==false){ if(p3Q->process->pid < 0) { // job hasnt started yet so fork and exec p3Q->process->pid = fork(); if (p3Q->process->pid < 0) { fprintf(stderr, "Dispatcher failed to fork new process."); return 0; } else if(p3Q->process->pid == 0) { printJobDetails(p3Q); execl("./process", "process", "",NULL); } else { sleep(1); } } else { // it was previously paused, so resume it if (SUPERVERBOSE) printf("Attempting to resume process...\n"); kill(p3Q->process->pid, SIGCONT); sleep(1); // let it run for 1 s } if (SUPERVERBOSE) printQueue(p3Name, p3Q); //decrement time p3Q->process->time_left--; //check to see if it is zero if (VERBOSE) printf("Time left in p3Q process: %d\n", p3Q->process->time_left); if(p3Q->process->time_left == 0){ kill(p3Q->process->pid, SIGINT); // kill the process waitpid(p3Q->process->pid, &processStatus, WUNTRACED); freeMemSpace(p3Q); // free its memory // free all resources printers += p3Q->process->printers; scanner += p3Q->process->scanners; modem += p3Q->process->modems; cddrives += p3Q->process->cds; // remove the PCB from the queue job = dequeueFront(&p3Q); free(job); } else { // pause it and cycle the queue b/c its now Round Robin kill(p3Q->process->pid, SIGTSTP); waitpid(p3Q->process->pid, &processStatus, WUNTRACED); job = dequeueFront(&p3Q); enqueueJob(p3Q, job); } } else { sleep(1); // if nothing new happens, sleep anyway } // increment clock clock++; // exit the dispatcher only once all queues are empty if(isEmpty(dispatchQ) && isEmpty(userQ) && isEmpty(realtimeQ) && isEmpty(p1Q) && isEmpty(p2Q) && isEmpty(p3Q)){ break; } } printf("All jobs ran to completion. Terminating dispatcher...\n"); // free all allocated mem before exiting freeQueues(); return 0; }
bool LexFileStream::open(const String &name) { close(); m_f = fopen(name, _T("rb")); initQueues(); return ok(); }