boolean tablenewtable (hdltablevariable *hvariable, hdlhashtable *htable) { /* create a new hashtable variable with an empty hashtable linked into it. */ register hdltablevariable hv; register hdlhashtable ht; if (!newtablevariable (true, 0L, hvariable, false)) return (false); hv = *hvariable; /*copy into register*/ if (!newhashtable (htable)) { disposehandle ((Handle) hv); return (false); } ht = *htable; /*copy into register*/ (**ht).timecreated = (**ht).timelastsave = timenow (); // 5.0a23 dmb /*leave the hashtableformats record unallocated, handle == nil*/ (**hv).variabledata = (long) ht; /*link the table into the variable rec*/ (**ht).hashtablerefcon = (long) hv; /*the pointing is mutual*/ (**ht).fldirty = true; /*it's never been saved*/ return (true); } /*tablenewtable*/
static boolean odbtabledirty (hdlhashtable htable, const bigstring bsname) { // hdltablediskrecord hf = (hdltablediskrecord) (**htable).hashtableformats; // if (hf != nil) (**htable).timelastsave = timenow (); /*modification time until saved*/ return (true); } /*tabledirty*/
boolean newoutlinerecord (hdloutlinerecord *houtline) { /* create a new outline record, returned in houtline. we assume nothing about outlinewindowinfo or outlinewindow, and we preserve outlinedata. the rectangles and displayinfo are all zero after we're called. 2.1b5 dmb: always initialize outlinesignature to LAND 4.0b7 dmb: initialize timelastsave to creation time; it's really a modification date. */ #if !fljustpacking tyconfigrecord lconfig; #endif register hdloutlinerecord ho; register boolean fl; if (!newclearhandle (sizeof (tyoutlinerecord), (Handle *) houtline)) return (false); ho = *houtline; /*copy into register*/ oppushoutline (ho); fl = opnewsummit (); oppopoutline (); if (!fl) { disposehandle ((Handle) ho); *houtline = nil; return (false); } (**ho).ctexpanded = 1; /*the summit line is expanded*/ (**ho).lineindent = 15; (**ho).linespacing = oneandalittlespaced; (**ho).defaultlineheight = 12; (**ho).maxlinelen = 255; (**ho).flbarcursoron = true; (**ho).flusebitmaps = true; (**ho).flbuildundo = true; #if !fljustpacking (**ho).caretoffset = -1; /*no saved caret location on activation*/ (**ho).selpoint.h = -1; /*no established horizontal cursor offset*/ #endif opinitcallbacks (ho); (**ho).timecreated = (**ho).timelastsave = timenow (); (**ho).iconheight = 16; /*by default, use small icons*/ (**ho).iconwidth = 16; /*by default, use small icons*/ (**ho).pixelsaftericon = 3; /*skip this many pixels between icon and text*/ (**ho).forecolor = blackcolor; (**ho).backcolor = whitecolor; (**ho).outlinescraptype = opscraptype; (**ho).outlinesignature = 'LAND'; #if !fljustpacking shellgetconfig (idoutlineconfig, &lconfig); (**ho).windowrect = lconfig.defaultwindowrect; (**ho).fontnum = lconfig.defaultfont; (**ho).fontsize = lconfig.defaultsize; (**ho).fontstyle = lconfig.defaultstyle; #endif return (true); } /*newoutlinerecord*/
int plot_xy_plot(const char* command, cairo_t* cairo, plot_args_t* pargs, void* baton) { plotxy_t* args = (plotxy_t*)baton; // Plot it! xylist_t* xyls; starxy_t myxy; starxy_t* xy = NULL; starxy_t* freexy = NULL; int Nxy; int i; #if 0 double t0; #endif plotstuff_builtin_apply(cairo, pargs); if (args->fn && dl_size(args->xyvals)) { ERROR("Can only plot one of xylist filename and xy_vals"); return -1; } if (!args->fn && !dl_size(args->xyvals)) { ERROR("Neither xylist filename nor xy_vals given!"); return -1; } if (args->fn) { #if 0 t0 = timenow(); #endif // Open xylist. xyls = xylist_open(args->fn); if (!xyls) { ERROR("Failed to open xylist from file \"%s\"", args->fn); return -1; } // we don't care about FLUX and BACKGROUND columns. xylist_set_include_flux(xyls, FALSE); xylist_set_include_background(xyls, FALSE); if (args->xcol) xylist_set_xname(xyls, args->xcol); if (args->ycol) xylist_set_yname(xyls, args->ycol); // Find number of entries in xylist. xy = xylist_read_field_num(xyls, args->ext, NULL); freexy = xy; xylist_close(xyls); if (!xy) { ERROR("Failed to read FITS extension %i from file %s.\n", args->ext, args->fn); return -1; } Nxy = starxy_n(xy); // If N is specified, apply it as a max. if (args->nobjs) Nxy = MIN(Nxy, args->nobjs); //logmsg("%g s to read xylist\n", timenow()-t0); } else { assert(dl_size(args->xyvals)); starxy_from_dl(&myxy, args->xyvals, FALSE, FALSE); xy = &myxy; Nxy = starxy_n(xy); } // Transform through WCSes. if (args->wcs) { double ra, dec, x, y; assert(pargs->wcs); /* // check for any overlap. double pralo,prahi,pdeclo,pdechi; double ralo,rahi,declo,dechi; anwcs_get_radec_bounds(pargs->wcs, 100, &pralo, &prahi, &pdeclo, &pdechi); anwcs_get_radec_bounds(args->wcs, 100, &ralo, &rahi, &declo, &dechi); if ( */ for (i=0; i<Nxy; i++) { anwcs_pixelxy2radec(args->wcs, // I used to add 1 here starxy_getx(xy, i), starxy_gety(xy, i), &ra, &dec); if (!plotstuff_radec2xy(pargs, ra, dec, &x, &y)) continue; logverb(" xy (%g,%g) -> RA,Dec (%g,%g) -> plot xy (%g,%g)\n", starxy_getx(xy,i), starxy_gety(xy,i), ra, dec, x, y); // add shift and scale... // FIXME -- not clear that we want to do this here... /* starxy_setx(xy, i, args->scale * (x - args->xoff)); starxy_sety(xy, i, args->scale * (y - args->yoff)); starxy_setx(xy, i, x-1); starxy_sety(xy, i, y-1); */ // Output coords: FITS -> 0-indexed image starxy_setx(xy, i, x-1); starxy_sety(xy, i, y-1); } } else { // Shift and scale xylist entries. if (args->xoff != 0.0 || args->yoff != 0.0) { for (i=0; i<Nxy; i++) { starxy_setx(xy, i, starxy_getx(xy, i) - args->xoff); starxy_sety(xy, i, starxy_gety(xy, i) - args->yoff); } } if (args->scale != 1.0) { for (i=0; i<Nxy; i++) { starxy_setx(xy, i, args->scale * starxy_getx(xy, i)); starxy_sety(xy, i, args->scale * starxy_gety(xy, i)); } } } // Plot markers. #if 0 t0 = timenow(); #endif for (i=args->firstobj; i<Nxy; i++) { double x = starxy_getx(xy, i); double y = starxy_gety(xy, i); if (plotstuff_marker_in_bounds(pargs, x, y)) plotstuff_stack_marker(pargs, x, y); } plotstuff_plot_stack(pargs, cairo); //logmsg("%g s to plot xylist\n", timenow()-t0); starxy_free(freexy); return 0; }
short __assert (char *expr, char *file, short line) { /* On OS X, DebugStr output gets automatically rerouted to stderr which in turn gets logged to console.log, viewable via Console.app. 2003-05-26 AR: Include date/time, app name, and app version. */ static boolean flnorentry = false; short day, month, year, hour, minute, second; tyfilespec myfspec; bigstring bs, bslogstamp, bsline, bsfile, bsmessage; if (flnorentry) return (0); flnorentry = true; /*get timestamp*/ secondstodatetime (timenow (), &day, &month, &year, &hour, &minute, &second); numbertostring ((long) year, bs); pushstring (bs, bslogstamp); pushchar ('-', bslogstamp); numbertostring ((long) month, bs); padwithzeros (bs, 2); pushstring (bs, bslogstamp); pushchar ('-', bslogstamp); numbertostring ((long) day, bs); padwithzeros (bs, 2); pushstring (bs, bslogstamp); pushchar (' ', bslogstamp); numbertostring ((long) hour, bs); padwithzeros (bs, 2); pushstring (bs, bslogstamp); pushchar (':', bslogstamp); numbertostring ((long) minute, bs); padwithzeros (bs, 2); pushstring (bs, bslogstamp); pushchar (':', bslogstamp); numbertostring ((long) second, bs); padwithzeros (bs, 2); pushstring (bs, bslogstamp); pushchar (' ', bslogstamp); /*get filespec for app*/ getapplicationfilespec (nil, &myfspec); pushstring (fsname (&myfspec), bslogstamp); pushchar (' ', bslogstamp); /*get version of app*/ filegetprogramversion (bs); pushchar ('(', bslogstamp); pushstring (bs, bslogstamp); pushchar (')', bslogstamp); /*get file name*/ moveleft (file, bsfile, (long) lenbigstring); convertcstring (bsfile); /*get line number*/ numbertostring ((long) line, bsline); /*ouput message*/ parsedialogstring ( "\p\r^0: Assertion failed in file ^1, at line ^2.\r", bslogstamp, bsfile, bsline, nil, bsmessage); DebugStr (bsmessage); /*send message to stderr*/ flnorentry = false; return (0); } /*__assert*/
void do_stat (int fd) { static char buffer[1024]; static double last = 0.0; static counters_t old_counter; double now; double t; counters_t new_counter; counters_t counter; int n; lseek (fd, 0, SEEK_SET); now = timenow(); n = read (fd, buffer, sizeof (buffer)); if (n < 0) { fprintf (stderr, "Can't read statfile\n"); exit (1); } buffer[n] = 0; n = sscanf(buffer, "%lu %lu %lu %lu %lu %lu %lu %llu %llu %llu %llu", &new_counter.msgs_alloc, &new_counter.msgs_max, &new_counter.errors, &new_counter.send_count, &new_counter.recv_count, &new_counter.route_count, &new_counter.drop_count, &new_counter.send_length, &new_counter.recv_length, &new_counter.route_length, &new_counter.drop_length); if (n < 11) { fprintf (stderr, "Can't parse statfile\n"); exit (1); } if (last == 0.0) { printf("M %lu(%lu) E %lu S %llu/%lu R %llu/%lu F %llu/%lu " "D %llu/%lu\n", new_counter.msgs_alloc, new_counter.msgs_max, new_counter.errors, new_counter.send_length, new_counter.send_count, new_counter.recv_length, new_counter.recv_count, new_counter.route_length, new_counter.route_count, new_counter.drop_length, new_counter.drop_count); } else { t = now - last; counter.msgs_alloc = new_counter.msgs_alloc; counter.msgs_max = new_counter.msgs_max; counter.errors = subul(new_counter.errors, old_counter.errors); counter.send_count = subul(new_counter.send_count, old_counter.send_count); counter.recv_count = subul(new_counter.recv_count, old_counter.recv_count); counter.route_count = subul(new_counter.route_count, old_counter.route_count); counter.drop_count = subul(new_counter.drop_count, old_counter.drop_count); counter.send_length = subull(new_counter.send_length, old_counter.send_length); counter.recv_length = subull(new_counter.recv_length, old_counter.recv_length); counter.route_length = subull(new_counter.route_length, old_counter.route_length); counter.drop_length = subull(new_counter.drop_length, old_counter.drop_length); printf ("M %3lu(%3lu) E %0.0f S %7.2f/%6.0f R %7.2f/%6.0f F %7.2f/%6.0f D %4.2f/%0.0f\n", counter.msgs_alloc, counter.msgs_max, rul(counter.errors,t), rull(counter.send_length,t*1024.0*1024.0), rul(counter.send_count, t), rull(counter.recv_length,t*1024.0*1024.0), rul(counter.recv_count, t), rull(counter.route_length,t*1024.0*1024.0), rul(counter.route_count, t), rull(counter.drop_length,t*1024.0*1024.0), rul(counter.drop_count, t)); } old_counter = new_counter; fflush (stdout); lseek (fd, 0, SEEK_SET); last = timenow(); }
int main(char argc,char ** argv) { if(argc < 2) { printf("Incorrect Arguments \n"); printf("Correct Format - Enter 1 for Regular Round Robin Scheduling 2 for priority Round Robin Scheduling\n"); exit(0); } PROC* readyQueue[50]; //queqe containing the list of all processess PROC* ProcessList[50]; //processess in the ready queue int terminated=0; //number of terminated processess int type = atoi(argv[1]); //type of the scheduler pid_t main_PID = getpid(); //PID of the scheduler int mid,read,rc,num_msg,k; key_t key; MESSAGE msg; struct msqid_ds msglist; struct sigaction action; action.sa_flags = SA_SIGINFO; action.sa_sigaction = &toIO; sigaction(SIGUSR1,&action,NULL); signal(SIGTERM,terminate); key = ftok(".",'V'); if((mid = msgget(key, IPC_CREAT | 0660))<0) { printf("Error Creating message queue\n"); exit(-1); } msgctl(mid, IPC_RMID, NULL); if((mid = msgget(key, IPC_CREAT | 0660))<0){ printf("Error Creating Message Queue\n"); exit(-1); } while(1) { //printf("Entered outer while loop"); rc = msgctl(mid,IPC_STAT,&msglist); //sense the message queue num_msg = msglist.msg_qnum; //get the number of message if(num_msg > 0) { for(k=0;k<num_msg;++k) { if(msgrcv(mid,&msg, sizeof(msg.message),FROMPROCESS,0) < 0) { error("msgrcv"); } if(strcmp(msg.message,"BEGI") == 0) { //if the process is coming for the first time PROC * P = malloc (sizeof(PROC)); P->index = count; //store the index of the process count++; P->PID = msg.PID; //set the PID of process //if its RRR then set the priority to 1 for all process if(type == 1) P->priority=1; else P->priority = msg.priority; msg.from = FROMSCHEDULER; msg.PID=main_PID; strcpy(msg.message,"REC"); if(msgsnd(mid, &msg, sizeof(msg.message), 0)<0) { error("msgsnd"); } P->arrival_time=time(NULL); P->waiting_time=0; P->turnaround_time=0; P->response_time=0; P->has_response=0; printf("Process P %d , PID = %d arrived\n",P->index,P->PID); P->inRQ=timenow(); ProcessList[P->index]=P; push(P,readyQueue); } else if(!strcmp(msg.message,"IO")) { PROC * P = malloc (sizeof(PROC)); int j=0; for(j=0;j<count;j++) { if (ProcessList[j]->PID==msg.PID) { P=ProcessList[j]; break; } } printf("%d : Process P%d , PID = %d returned from IO\n",(int)time(NULL),P->index,P->PID); P->inRQ=timenow(); push(P,readyQueue); } } } if(empty(readyQueue) == 0) { //printf("RQ not empty condition\n"); int in_io=0; int q=0; PROC * P = pop(readyQueue); struct timeval cur=timenow(); struct timeval rqt=(P->inRQ); unsigned long tv= (cur.tv_sec-rqt.tv_sec) + 1000000*(cur.tv_usec-rqt.tv_usec); P->waiting_time += tv; if(P->has_response==0) //setting the response flag to 1 after first IO operation { P->response_time=P->waiting_time; P->has_response=1; } kill(P->PID,SIGCONT); //printf("Process P %d is running\n",P->index); for(q=0;q<TIME_QUANTA;q++) { if(ioPID==P->PID) { ProcessList[P->index]=P; printf("%d : Process P%d , PID = %d requesting I/O\n",(int)time(NULL),P->index,ioPID); ioPID=-1; in_io=1; break; } if(term_flag==1) { ProcessList[P->index]=P; P->turnaround_time=time(NULL)-(P->arrival_time); printf("%d : Process P%d , PID = %d Terminated\n",(int)time(NULL),P->index,P->PID); term_flag=0; terminated++; break; } } if(terminated==count) break; } } FILE * fp; int file=atoi(argv[1]); if(file==1) fp=fopen("RR_Stats","w"); else fp=fopen("P_RR_Stats","w"); time_t avg_w=0,avg_t=0,avg_r=0; int l=0; for(l=0;l<count;l++) { fprintf(fp,"Process P%d\n Waiting Time(microsec): %lu\nTurnaround Time (s): %d Response Time(microsec): %d\n\n",l,ProcessList[l]->waiting_time,(int)ProcessList[l]->turnaround_time,(int)ProcessList[l]->response_time); avg_w += ProcessList[l]->waiting_time; avg_t += ProcessList[l]->turnaround_time; avg_r += ProcessList[l]->response_time; } avg_w/=count; avg_t/=count; avg_r/=count; fprintf(fp,"Average\n Avg Waiting Time(microsec): %lu\nTurnaround Time (s): %d\nResponse Time(microsec): %d\n",avg_w,(int)avg_t,(int)avg_r); printf("\nFinished\n"); fclose(fp); return 0; }