static void leaveDrive(int haveError) { if(!currentDrive) return; leaveDirectory(haveError); if(!concise && !haveError) { if(dirsOnDrive > 1) { printf("\nTotal files listed:\n"); printSummary(filesOnDrive, bytesOnDrive); } if(RootDir && !fast) { char *s1 = NULL; mt_off_t bytes = getfree(RootDir); if(bytes == -1) { fprintf(stderr, "Fat error\n"); goto exit_1; } printf(" %s bytes free\n\n", dotted_num(bytes,17, &s1)); #ifdef TEST_SIZE ((Fs_t*)GetFs(RootDir))->freeSpace = 0; bytes = getfree(RootDir); printf(" %s bytes free\n\n", dotted_num(bytes,17, &s1)); #endif if(s1) free(s1); } } exit_1: FREE(&RootDir); currentDrive = '\0'; }
void timerprocessor_c::add(timer_subscriber_c *t, double ttl, void * par, bool delete_same) { if (delete_same) del(t, par); timer_subscriber_entry_s *e = getfree(t, ttl, par); m_items.add(e); t->added(); }
void addVertex (Site* s, float x, float y) { Info_t* ip; PtItem* p; PtItem* curr; PtItem* prev; Point* origin = &(s->coord); PtItem tmp; int cmp; /* fprintf (stderr, "addVertex (%d, %f, %f)\n", s->sitenbr, x, y); */ ip = nodeInfo + (s->sitenbr); curr = ip->verts; tmp.p.x = x; tmp.p.y = y; cmp = compare(origin, &tmp, curr); if (cmp == 0) return; else if (cmp < 0) { p = (PtItem *) getfree(&pfl); p->p.x = x; p->p.y = y; p->next = curr; ip->verts = p; return; } prev = curr; curr = curr->next; while ((cmp = compare(origin, &tmp, curr)) > 0) { prev = curr; curr = curr->next; } if (cmp == 0) return; p = (PtItem *) getfree(&pfl); p->p.x = x; p->p.y = y; prev->next = p; p->next = curr; /* This test should be unnecessary */ /* if (!sorted(origin,ip->verts)) */ /* error (ip,s,x,y); */ }
void bdelayedwrite() { debug(1 + BUFFER_DL, "bdelayedwrite() {}\n"); buffer *buff = getfree(); if (buff->pid == getpid()) bsyncwrite(buff); }
void addVertex (Site* s, float x, float y) { Info_t* ip; PtItem* p; PtItem* curr; PtItem* prev; Point* origin = &(s->coord); PtItem tmp; /* fprintf (stderr, "addVertex (%d, %f, %f)\n", s->sitenbr, x, y); */ ip = nodeInfo + (s->sitenbr); curr = ip->verts; tmp.p.x = x; tmp.p.y = y; if (lessThan(origin, &tmp, curr)) { p = (PtItem *) getfree(&pfl); p->p.x = x; p->p.y = y; p->next = curr; ip->verts = p; return; } prev = curr; curr = curr->next; while (!lessThan (origin, &tmp, curr)) { prev = curr; curr = curr->next; } if ((x == prev->p.x) && (y == prev->p.y)) return; p = (PtItem *) getfree(&pfl); p->p.x = x; p->p.y = y; prev->next = p; p->next = curr; if (!sorted(origin,ip->verts)) error (ip,s,x,y); }
struct VoronoiDiagramGenerator::Halfedge* VoronoiDiagramGenerator::HEcreate(struct VoronoiDiagramGenerator::Edge *e,int pm) { struct Halfedge *answer; answer = (struct Halfedge *) getfree(&hfl); answer -> ELedge = e; answer -> ELpm = pm; answer -> PQnext = (struct Halfedge *) NULL; answer -> vertex = (struct Site *) NULL; answer -> ELrefcnt = 0; return(answer); }
Halfedge * HEcreate(Edge * e, int pm) { Halfedge * answer ; answer = (Halfedge *)getfree(&hfl) ; answer->ELedge = e ; answer->ELpm = pm ; answer->PQnext = (Halfedge *)NULL ; answer->vertex = (Site *)NULL ; answer->ELrefcnt = 0 ; return (answer) ; }
int main(void) { unsigned short i; char *tmtz, *net, *avgs, *root, *vol, *bat; tmtz = net = avgs = root = vol = bat = NULL; char *line; static unsigned long long rec = 0, sent = 0; if (!(dpy = XOpenDisplay(NULL))) { fprintf(stderr, "dwmstatus: cannot open display.\n"); return 1; } parse_netdev(&rec, &sent); for (i = 0;; sleep(1), i++) { if (i % 10 == 0) { free(bat); bat = batstat(); } if (i % 5 == 0) { free(avgs); free(root); free(vol); avgs = loadavg(); root = getfree("/"); vol = runcmd("amixer get PCM | grep -om1 '[0-9]*%'"); } net = netusage(&rec, &sent); tmtz = mktimes("%a %b %d %T"); line = smprintf("♪ %s ⚡ %s │ %s │ / %s │ %s │ %s", vol, bat, net, root, avgs, tmtz); XStoreName(dpy, DefaultRootWindow(dpy), line); XSync(dpy, False); free(net); free(tmtz); free(line); if (i == 60) i = 0; } XCloseDisplay(dpy); return 0; }
static void rt_task1() { while (1) { printf("REALTIME START\n"); getfree(); show_freelist(¤t->mm.heap); #ifdef CONFIG_SYSCALL display_devtab(); #endif sleep(3); printf("REALTIME END\n"); yield(); } }
//create a new site where the HalfEdges el1 and el2 intersect - note that the Point in the argument list is not used, don't know why it's there struct VoronoiDiagramGenerator::Site * VoronoiDiagramGenerator::intersect(struct VoronoiDiagramGenerator::Halfedge *el1, struct VoronoiDiagramGenerator::Halfedge *el2, struct VoronoiDiagramGenerator::Point *p) { struct Edge *e1,*e2, *e; struct Halfedge *el; float d, xint, yint; int right_of_site; struct Site *v; e1 = el1 -> ELedge; e2 = el2 -> ELedge; if(e1 == (struct Edge*)NULL || e2 == (struct Edge*)NULL) return ((struct Site *) NULL); //if the two edges bisect the same parent, return null if (e1->reg[1] == e2->reg[1]) return ((struct Site *) NULL); d = e1->a * e2->b - e1->b * e2->a; if (-1.0e-10<d && d<1.0e-10) return ((struct Site *) NULL); xint = (e1->c*e2->b - e2->c*e1->b)/d; yint = (e2->c*e1->a - e1->c*e2->a)/d; if( (e1->reg[1]->coord.y < e2->reg[1]->coord.y) || (e1->reg[1]->coord.y == e2->reg[1]->coord.y && e1->reg[1]->coord.x < e2->reg[1]->coord.x) ) { el = el1; e = e1; } else { el = el2; e = e2; }; right_of_site = xint >= e -> reg[1] -> coord.x; if ((right_of_site && el -> ELpm == le) || (!right_of_site && el -> ELpm == re)) return ((struct Site *) NULL); //create a new site at the point of intersection - this is a new vector event waiting to happen v = (struct Site *) getfree(&sfl); v -> refcnt = 0; v -> coord.x = xint; v -> coord.y = yint; return(v); }
Edge *bisect(Site * s1, Site * s2) { double dx, dy, adx, ady; Edge *newedge; newedge = (Edge *) getfree(&efl); newedge->reg[0] = s1; newedge->reg[1] = s2; ref(s1); ref(s2); newedge->ep[0] = (Site *) NULL; newedge->ep[1] = (Site *) NULL; dx = s2->coord.x - s1->coord.x; dy = s2->coord.y - s1->coord.y; adx = dx > 0 ? dx : -dx; ady = dy > 0 ? dy : -dy; newedge->c = s1->coord.x * dx + s1->coord.y * dy + (dx * dx + dy * dy) * 0.5; if (adx > ady) { newedge->a = 1.0; newedge->b = dy / dx; newedge->c /= dx; } else { newedge->b = 1.0; newedge->a = dx / dy; newedge->c /= dy; }; newedge->edgenbr = nedges; #ifdef STANDALONE out_bisector(newedge); #endif nedges += 1; return (newedge); }
struct Edge * VoronoiDiagramGenerator::bisect(struct Site *s1,struct Site *s2) { float dx,dy,adx,ady; struct Edge *newedge; newedge = (struct Edge *) getfree(&efl); newedge->ignore = 0; newedge -> reg[0] = s1; //store the sites that this edge is bisecting newedge -> reg[1] = s2; ref(s1); ref(s2); newedge -> ep[0] = (struct Site *) NULL; //to begin with, there are no endpoints on the bisector - it goes to infinity newedge -> ep[1] = (struct Site *) NULL; dx = s2->coord.x - s1->coord.x; //get the difference in x dist between the sites dy = s2->coord.y - s1->coord.y; adx = dx>0 ? dx : -dx; //make sure that the difference in positive ady = dy>0 ? dy : -dy; newedge -> c = (float)(s1->coord.x * dx + s1->coord.y * dy + (dx*dx + dy*dy)*0.5);//get the slope of the line if (adx>ady) { newedge -> a = 1.0; newedge -> b = dy/dx; newedge -> c /= dx;//set formula of line, with x fixed to 1 } else { newedge -> b = 1.0; newedge -> a = dx/dy; newedge -> c /= dy;//set formula of line, with y fixed to 1 }; newedge -> edgenbr = nedges; //printf("\nbisect(%d) ((%f,%f) and (%f,%f)",nedges,s1->coord.x,s1->coord.y,s2->coord.x,s2->coord.y); nedges += 1; edges.push_back(newedge); return(newedge); }
buffer *getblk(int fs, ino_t inode, int block) { debug(1 + BUFFER_DL, "getblk(fs:%d, inode:%d, block:%d) {\n", fs, (int)inode, block); // wait for semaphore to start while (!semWait(semid)) { // skip signal interruptions if (errno != EINTR) { perror("getblk, semWait"); debug(2 + BUFFER_DL, "ERROR en getblk, semWait."); exit(1); } } // search for specified buffer or return a new one buffer *buff = NULL; while (buff == NULL) { // search hash list for block int pos = bc->header.hash[block % MAXHASH]; buffer *hl_buff = (pos > -1) ? &(bc->buffers[pos]) : NULL; int times = 0; while(pos > -1 && (hl_buff->inode != inode || hl_buff->block != block)) { times ++; if (times == MAXBUFF) { printf("[%d] times: %d ... \n", getpid(), times); int end = pos; do { bdebug(0, &(bc->buffers[pos])); pos = bc->buffers[pos].hashnext; } while (end != pos); exit(0); } pos = hl_buff->hashnext; hl_buff = (pos > -1) ? &(bc->buffers[pos]) : NULL; } // return the buffer if already loaded if (hl_buff != NULL && hl_buff->inode == inode && hl_buff->block == block) { // sleep until the targeted buffer becomes free if (BS_CMP(hl_buff->status, BS_LOCKED)) { bwait(hl_buff); continue; } // take ownership off buffer hl_buff->fd = getfd(inode); hl_buff->pid = getpid(); // lock the found buffer BS_SET(hl_buff->status, BS_LOCKED); // will return found buffer buff = hl_buff; // allocate the block in a new buffer } else { buffer *new_buff = getfree(); // sleep until any buffer becomes free if (new_buff == NULL) { bwait(NULL); continue; } // asynchronous write buffer to disk while (BS_CMP(new_buff->status, BS_DELAYED)) { basyncwrite(new_buff); // wait for free buffer to be written usleep(1000); } // set new buffer properties and proper hash list drophash(new_buff); new_buff->valid = 0; new_buff->inode = inode; new_buff->block = block; new_buff->fd = getfd(inode); new_buff->pid = getpid(); rehash(new_buff); // lock the new buffer and mark it as not valid BS_SET(new_buff->status, BS_LOCKED); BS_CLR(new_buff->status, BS_VALID); // will return the new buffer buff = new_buff; } } // extract the buffer from free list setused(buff); // free the semaphore if (!semSignal(semid)) { perror("getblk, semSignal"); debug(2 + BUFFER_DL, "ERROR en getblk, semSignal."); exit(1); } bdebug(2 + BUFFER_DL, buff); debug(1 + BUFFER_DL, "} -> %p\n", buff); return buff; }
int main(int argc,char* argv[]) { char buffer[100]; int n=0; struct sigaction s; s.sa_sigaction = &handler; sigemptyset(&s.sa_mask); s.sa_flags =SA_SIGINFO; sigaction (SIGUSR1, &s, NULL); //create platforms for(int i=0;i<3;i++) { pids[i]=fork(); if(pids[i]==0) { char buf[24]; sprintf(buf,"%d",32004+i); execlp("./pf","./pf",buf,(char*)NULL); } } //initially each platform is free for(int i=0;i<3;i++) { idle[i]=1; } int rsfd=raw_socket(143); printf("SM - rsfd:%d\n",rsfd); int sfd[3]; //accept unix domain socket conn from platforms int usfd=unix_socket("soc.socket"); for(int i=0;i<3;i++) { nusfd[i]=accept(usfd,NULL,NULL); printf("nusfd %d : %d\n",i,nusfd[i]); } //tracks for different directions are laid int p[3]={32001,32002,32003}; int maxfd=-1; struct sockaddr_in myaddr[3]; fd_set readset; FD_ZERO(&readset); for(int i=0;i<3;i++) { sfd[i]=inet_serv_socket(p[i]); if(maxfd<sfd[i]) { maxfd=sfd[i]; } } sockaddr_in cliaddr; socklen_t clen; int pid; int nsfd; int pos=-1; while(1) { //poll on tracks from differnt directions for incoming trains FD_ZERO(&readset); for(int i=0;i<3;i++) { if(sfd[i]!=-1) FD_SET(sfd[i],&readset); } select(maxfd+1,&readset,NULL,NULL,NULL); pos=-1; for(int i=0;i<3;i++) { if(FD_ISSET(sfd[i],&readset)) { pos=i; break; } } printf("all running\n"); //TODO:pass annoncements to all platforms //get free platform int r=getfree(); if(r>=0) { int nsfd=accept(sfd[pos],NULL,NULL); //send announcements to all platforms char buff[1000];char tmp[20]; struct sockaddr_in servaddr; servaddr.sin_family=AF_INET; servaddr.sin_port=htons(0); servaddr.sin_addr.s_addr=htonl(INADDR_ANY); bzero(buff,1000); bzero(tmp,20); sprintf(tmp,"%d\n",r); strcpy(buff,"a train arriving at platform "); strcat(buff,tmp); sendto(rsfd,buff,1000,0,(struct sockaddr*)&servaddr,sizeof(servaddr)); //mark platform selected busy idle[r]=0; //pass fd to selected platform sendfd(nusfd[r],nsfd); close(nsfd); } } return 0; }
int main(){ FOO net; readmin(&net); getfree(&net); }
/* * Initialize for Zmodem receive attempt, try to activate Zmodem sender * Handles ZSINIT frame * Return ZFILE if Zmodem filename received, -1 on error, * ZCOMPL if transaction finished, else 0: can be ymodem. */ int tryz(void) { int c, n; int cmdzack1flg; if (protocol != ZM_ZMODEM) return 0; for (n = zmodem_requested ?15:10; --n >= 0; ) { /* * Set buffer length (0) and capability flags */ Syslog('z', "tryz attempt %d", n); stohdr(0L); Txhdr[ZF0] = CANFC32|CANFDX|CANOVIO; if (Zctlesc) Txhdr[ZF0] |= TESCCTL; zshhdr(tryzhdrtype, Txhdr); if (tryzhdrtype == ZSKIP) /* Don't skip too far */ tryzhdrtype = ZRINIT; /* CAF 8-21-87 */ again: switch (zgethdr(Rxhdr)) { case ZRQINIT: continue; case ZEOF: continue; case TIMEOUT: Syslog('z', "Zmodem: tryz() timeout attempt %d", n); continue; case ZFILE: zconv = Rxhdr[ZF0]; if (!zconv) { Syslog('z', "*** !zconv %d", zconv); zconv = ZCBIN; } zmanag = Rxhdr[ZF1]; ztrans = Rxhdr[ZF2]; tryzhdrtype = ZRINIT; c = zrdata(secbuf, MAXBLOCK); io_mode(0, 3); if (c == GOTCRCW) { Syslog('z', "tryz return ZFILE"); return ZFILE; } zshhdr(ZNAK, Txhdr); goto again; case ZSINIT: /* this once was: * Zctlesc = TESCCTL & Rxhdr[ZF0]; * trouble: if rz get --escape flag: * - it sends TESCCTL to sz, * get a ZSINIT _without_ TESCCTL (yeah - sender didn't know), * overwrites Zctlesc flag ... * - sender receives TESCCTL and uses "|=..." * so: sz escapes, but rz doesn't unescape ... not good. */ Zctlesc |= TESCCTL & Rxhdr[ZF0]; if (zrdata(Attn, ZATTNLEN) == GOTCRCW) { stohdr(1L); zshhdr(ZACK, Txhdr); goto again; } zshhdr(ZNAK, Txhdr); goto again; case ZFREECNT: stohdr(getfree()); zshhdr(ZACK, Txhdr); goto again; case ZCOMMAND: cmdzack1flg = Rxhdr[ZF0]; if (zrdata(secbuf, MAXBLOCK) == GOTCRCW) { if (cmdzack1flg & ZCACK1) stohdr(0L); else Syslog('+', "Zmodem: request for command \"%s\" ignored", printable(secbuf,-32)); stohdr(0L); do { zshhdr(ZCOMPL, Txhdr); } while (++errors<20 && zgethdr(Rxhdr) != ZFIN); return ackbibi(); } zshhdr(ZNAK, Txhdr); goto again; case ZCOMPL: goto again; case ZRINIT: Syslog('z', "tryz: got ZRINIT"); return TERROR; case ZFIN: /* do not beleive in first ZFIN */ ackbibi(); return ZCOMPL; case TERROR: case HANGUP: case ZCAN: return TERROR; default: continue; } } return 0; }
Site * getsite () { return ((Site *) getfree(&sfl)); }
/* * Initialize for Zmodem receive attempt, try to activate Zmodem sender * Handles ZSINIT frame * Return ZFILE if Zmodem filename received, -1 on error, * ZCOMPL if transaction finished, else 0 */ static int tryz(void) { int c, n; int cmdzack1flg; for (n = Zmodem ? 15 : 5; --n >= 0;) { /* Set buffer length (0) and capability flags */ stohdr(0L); Txhdr[ZF0] = CANFC32 | CANFDX | CANOVIO | CANBRK; if (Zctlesc) Txhdr[ZF0] |= TESCCTL; /* TESCCTL == ESCCTL */ zshhdr(tryzhdrtype, Txhdr); if (tryzhdrtype == ZSKIP) /* Don't skip too far */ tryzhdrtype = ZRINIT; /* CAF 8-21-87 */ again: switch (zgethdr(Rxhdr, 0)) { case ZRQINIT: continue; case ZEOF: continue; case TIMEOUT: continue; case ZFILE: zconv = Rxhdr[ZF0]; zmanag = Rxhdr[ZF1]; ztrans = Rxhdr[ZF2]; tryzhdrtype = ZRINIT; c = zrdata(secbuf, MAX_BLOCK); mode(3); if (c == GOTCRCW) return ZFILE; zshhdr(ZNAK, Txhdr); goto again; case ZSINIT: Zctlesc = TESCCTL & Rxhdr[ZF0]; if (zrdata(Attn, ZATTNLEN) == GOTCRCW) { stohdr(1L); zshhdr(ZACK, Txhdr); goto again; } zshhdr(ZNAK, Txhdr); goto again; case ZFREECNT: stohdr(getfree()); zshhdr(ZACK, Txhdr); goto again; case ZCOMMAND: cmdzack1flg = Rxhdr[ZF0]; if (zrdata(secbuf, MAX_BLOCK) == GOTCRCW) { if (Verbose) { fprintf(stderr, "lrz: remote requested command\n"); fprintf(stderr, "lrz: %s\n", secbuf); } if (Verbose) fprintf(stderr, "lrz: not executed\n"); zshhdr(ZCOMPL, Txhdr); return ZCOMPL; } goto again; case ZCOMPL: goto again; default: continue; case ZFIN: ackbibi(); return ZCOMPL; case ZCAN: return ERROR; } } return 0; }
void VoronoiDiagramGenerator::clip_line(struct Edge *e) { struct Site *s1, *s2; float x1=0,x2=0,y1=0,y2=0, temp = 0; Site *v1= 0, *v2 = 0; bool needNewVertex1 = false,needNewVertex2 = false; x1 = e->reg[0]->coord.x; x2 = e->reg[1]->coord.x; y1 = e->reg[0]->coord.y; y2 = e->reg[1]->coord.y; //if the distance between the two points this line was created from is less than //the square root of 2, then ignore it if(sqrt(((x2 - x1) * (x2 - x1)) + ((y2 - y1) * (y2 - y1))) < minDistanceBetweenSites) { return; } pxmin = borderMinX; pxmax = borderMaxX; pymin = borderMinY; pymax = borderMaxY; // printf("\nEdge (%d), minX = %f, maxX = %f, minY = %f, maxY = %f",e->edgenbr,pxmin, pxmax, pymin,pymax); if(e -> a == 1.0 && e ->b >= 0.0) { s1 = e -> ep[1]; s2 = e -> ep[0]; } else { s1 = e -> ep[0]; s2 = e -> ep[1]; }; v1 = s1; v2 = s2; if(e -> a == 1.0) { y1 = pymin; if (s1!=(struct Site *)NULL && s1->coord.y > pymin) { y1 = s1->coord.y; } else { needNewVertex1 = true; } if(y1>pymax) { y1 = pymax; needNewVertex1 = true; } x1 = e -> c - e -> b * y1; y2 = pymax; if (s2!=(struct Site *)NULL && s2->coord.y < pymax) { y2 = s2->coord.y; } else { needNewVertex2 = true; } if(y2<pymin) { y2 = pymin; needNewVertex2 = true; } x2 = (e->c) - (e->b) * y2; if (((x1> pxmax) & (x2>pxmax)) | ((x1<pxmin)&(x2<pxmin))) { return; } if(x1> pxmax) { x1 = pxmax; y1 = (e -> c - x1)/e -> b;needNewVertex1 = true;} if(x1<pxmin) { x1 = pxmin; y1 = (e -> c - x1)/e -> b;needNewVertex1 = true;} if(x2>pxmax) { x2 = pxmax; y2 = (e -> c - x2)/e -> b;needNewVertex2 = true;} if(x2<pxmin) { x2 = pxmin; y2 = (e -> c - x2)/e -> b;needNewVertex2 = true;} } else { x1 = pxmin; if (s1!=(struct Site *)NULL && s1->coord.x > pxmin) { x1 = s1->coord.x; } else { needNewVertex1 = true; } if(x1>pxmax) { x1 = pxmax; needNewVertex1 = true; } y1 = e -> c - e -> a * x1; x2 = pxmax; if (s2!=(struct Site *)NULL && s2->coord.x < pxmax) { x2 = s2->coord.x; } else { needNewVertex2 = true; } if(x2<pxmin) { x2 = pxmin; needNewVertex2 = true; } y2 = e -> c - e -> a * x2; if (((y1> pymax) & (y2>pymax)) | ((y1<pymin)&(y2<pymin))) { return; } if(y1> pymax) { y1 = pymax; x1 = (e -> c - y1)/e -> a;needNewVertex1 = true;} if(y1<pymin) { y1 = pymin; x1 = (e -> c - y1)/e -> a;needNewVertex1 = true;} if(y2>pymax) { y2 = pymax; x2 = (e -> c - y2)/e -> a;needNewVertex2 = true;} if(y2<pymin) { y2 = pymin; x2 = (e -> c - y2)/e -> a;needNewVertex2 = true;} } //printf("\nPushing line (%f,%f,%f,%f)",x1,y1,x2,y2); // if(!((x1 == x2 && x2== pxmin) || (x1 == x2 && x2 == pxmax) || (y1 == y2 && y2 == pymin) || (y1 == y2 && y2 == pymax))) { pushGraphEdge(x1,y1,x2,y2); if(needNewVertex1) { //printf("\nCreate new vertex 1 v1 = (struct Site *) getfree(&sfl); v1 -> refcnt = 0; v1 -> coord.x = x1; v1 -> coord.y = y1; makevertex(v1); } if(needNewVertex2) { v2 = (struct Site *) getfree(&sfl); v2 -> refcnt = 0; v2 -> coord.x = x2; v2 -> coord.y = y2; makevertex(v2); } insertVertexLink(v1->sitenbr,v2->sitenbr); } }