void main() { init(); while(1) { //print world printworld(); //wait int key=waitevent(); //change cleanup(); switch(key) { case -1:return; case 0x1b:return; case 0x20: //press { if(release==0) speed++; break; } case 0xa0: //release { release=1; break; } case 0x40000052: //up { if(y0>=16) { y0-=16; y-=16; } break; } case 0x40000051: //down { if(y0<752) { y0+=16; y+=16; } break; } case 0xff: { ticktock(); break; } default:continue; } } }
void run (void) { ::printf ("counting till %i\n", cnt); for (int i=0; i<cnt; ++i) { DB.get() = DB.get().ival() + 1; ::printf ("DB.get() -> %i\n", DB.get().ival()); } *out = DB.get(); value ev = waitevent (); threadStopped.signal (); }
int mainloop() { XEvent event; /* the current event */ int go_on=1; /* whether or not we should continue */ while (go_on) { /* if we think there's a client out there, we need to time */ /* out if the client dies */ if (selset) selset=waitevent(); if (selset == -1) return(FAIL); XNextEvent(display,&event); if (handlexevent(event,&go_on) == FAIL) return(FAIL); } return(SUCCEED); }
/* * Handle the events from a message dialog, hide the window afterwards. */ static int handle_message_dialog(window w) { window old; dialog_data *d = data(w); old = currentdrawing(); d->hit = NOT_CHOSEN_YET; show(w); while (d->hit == NOT_CHOSEN_YET) { waitevent(); doevent(); } hide(w); if (old) drawto(old); return d->hit; }
int32_t close_ftdichip(uint32_t ftdihandle) { #ifdef DEBUGMODE printf("---close_ftdichip---\n"); #endif #if defined(FTDILIB) stop_thread=1; waitevent(STOP_THREAD_EVENT,10000); p_ftdi_usb_close((ftdi_context)ftdihandle); destroyevent(STOP_THREAD_EVENT); #else if(pFT_Close((FT_HANDLE*)ftdihandle)!=FT_OK) { return -1; } #endif return 0; }
void *lexthread(void * arg) #endif { sdrch_t *sdr=(sdrch_t*)arg; int cnt=0,lexch=0,state,i,nerr,errloc[LENLEXRS],time=0,dt,mid; uint64_t buffloc; double dfreq,cn0; char *data; uint8_t corri,sendbuf[LENLEXRCV],rsmsg[LENLEXRS]; uint8_t lexpre[LENLEXPRE]={0x1A,0xCF,0xFC,0x1D}; /* preamble */ sdrlex_t sdrlex={{0}}; sdrout_t out={0}; unsigned long tick=0; FILE *fplexlog=NULL,*fplexbin=NULL; short *rcode; cpx_t *xcode; if (sdrini.log) { fplexlog=fopen("LEXLOG.csv","w"); fplexbin=fopen("LEXBIN.bin","wb"); fprintf(fplexlog,"Tow,CN0,Time(ms),Error\n"); } /* start tcp server (lex) */ if (sdrini.lex) { out.soc_lex.port=sdrini.lexport; tcpsvrstart(&out.soc_lex); } data=(char*)sdrmalloc(sizeof(char)*sdr->nsamp*sdr->dtype); /* lex channel is last */ lexch=sdrini.nch; /* FFT code generation */ if (!(rcode=(short *)sdrmalloc(sizeof(short)*sdr->nsamp)) || !(xcode=cpxmalloc(sdr->nsamp))) { SDRPRINTF("error: initsdrch memory alocation\n"); return THRETVAL; } rescode(sdr->code,sdr->clen,0,0,sdr->ci,sdr->nsamp,rcode); /* resampled code */ cpxcpx(rcode,NULL,1.0,sdr->nsamp,xcode); /* FFT code */ cpxfft(NULL,xcode,sdr->nsamp); sdrfree(rcode); sleepms(3000*sdrini.nch); SDRPRINTF("**** LEX sdr thread start! ****\n"); do { /* wait event */ mlock(hlexmtx); waitevent(hlexeve,hlexmtx); unmlock(hlexmtx); /* assist from L1CA */ buffloc=sdrch[lexch].trk.codei[1]+sdrch[lexch].currnsamp+DSAMPLEX; dfreq=-sdrch[lexch].trk.D[1]*(FREQ6/FREQ1); /* get current data */ rcvgetbuff(&sdrini,buffloc,sdr->nsamp,sdr->ftype,sdr->dtype,data); tick=tickgetus(); /* LEX correlation */ corri=lexcorr_fft(sdr,data,sdr->dtype,sdr->ti,sdr->nsamp,dfreq,sdr->crate, sdr->nsamp,xcode,&cn0); dt=tickgetus()-tick; time+=dt; if (dt>4000) SDRPRINTF("error: dt=%.1fms(must be < 4ms)\n",(double)dt/1000); /* check computation time */ if (cnt%250==0) { //SDRPRINTF("time=%.2fms doppler=%.1f\n",(double)time/250000,dfreq); time=0; } shiftdata(&sdrlex.msg[0],&sdrlex.msg[1],1,LENLEXMSG-1); /* shift to left */ sdrlex.msg[LENLEXMSG-1]=corri; /* add last */ /* preamble search */ state=0; for (i=0;i<LENLEXPRE;i++) state+=abs(sdrlex.msg[i]-lexpre[i]); if (state==0) { /* reed solomon */ memset(rsmsg,0,LENLEXRS); memcpy(&rsmsg[9],&sdrlex.msg[LENLEXPRE],LENLEXRS-9); /* RS decode */ nerr=decode_rs_ccsds(rsmsg,errloc,0,0); if (nerr!=0) SDRPRINTF("RS correct %d symbols!\n",nerr); if (sdrini.log) { fprintf(fplexlog,"%f,%f,%d,%d\n", sdrch[lexch].trk.tow[0],cn0,time,nerr); fwrite(sdrlex.msg,1,LENLEXMSG,fplexbin); } if (nerr<0) { cnt++; continue; } /* <0 means failed to RS decode */ /* correct lex message */ memcpy(&sdrlex.msg[LENLEXPRE],&rsmsg[9],LENLEXRSK-9); mid=getbitu(sdrlex.msg,5*8,8); SDRPRINTF("LEX Message Type ID=%d\n",mid); /* generate send buffer */ sendbuf[0]=0xAA; /* sync code1 (see rcvlex.c) */ sendbuf[1]=0x55; /* sync code2 (see rcvlex.c) */ /* set tow (LEX message does not contain tow information...) */ setbitu(sendbuf,2*8,4*8,ROUND(sdrch[lexch].trk.tow[0]*1000)); /* set week ()*/ setbitu(sendbuf,6*8,2*8,sdrch[lexch].nav.sdreph.eph.week); memcpy(&sendbuf[8],sdrlex.msg,LENLEXMSG-LENLEXRSP); /* LEX message */ /* send LEX message */ if (sdrini.lex&&out.soc_lex.flag) send(out.soc_lex.c_soc,(char*)sendbuf,LENLEXRCV,0); } cnt++; } while (!sdrstat.stopflag); if (sdrini.log) { fclose(fplexlog); fclose(fplexbin); } if (out.soc_lex.flag) tcpsvrclose(&out.soc_lex); cpxfree(xcode); return THRETVAL; }
int main(int ac, char **av) { struct timespec timediff; struct sigaction sa; struct ex_types *funcs; struct trussinfo *trussinfo; char *fname; char *signame; char **command; pid_t childpid; int c, initial_open, status; fname = NULL; initial_open = 1; /* Initialize the trussinfo struct */ trussinfo = (struct trussinfo *)calloc(1, sizeof(struct trussinfo)); if (trussinfo == NULL) errx(1, "calloc() failed"); trussinfo->outfile = stderr; trussinfo->strsize = 32; trussinfo->pr_why = S_NONE; trussinfo->curthread = NULL; SLIST_INIT(&trussinfo->threadlist); while ((c = getopt(ac, av, "p:o:facedDs:S")) != -1) { switch (c) { case 'p': /* specified pid */ trussinfo->pid = atoi(optarg); /* make sure i don't trace me */ if (trussinfo->pid == getpid()) { fprintf(stderr, "attempt to grab self.\n"); exit(2); } break; case 'f': /* Follow fork()'s */ trussinfo->flags |= FOLLOWFORKS; break; case 'a': /* Print execve() argument strings. */ trussinfo->flags |= EXECVEARGS; break; case 'c': /* Count number of system calls and time. */ trussinfo->flags |= COUNTONLY; break; case 'e': /* Print execve() environment strings. */ trussinfo->flags |= EXECVEENVS; break; case 'd': /* Absolute timestamps */ trussinfo->flags |= ABSOLUTETIMESTAMPS; break; case 'D': /* Relative timestamps */ trussinfo->flags |= RELATIVETIMESTAMPS; break; case 'o': /* Specified output file */ fname = optarg; break; case 's': /* Specified string size */ trussinfo->strsize = atoi(optarg); break; case 'S': /* Don't trace signals */ trussinfo->flags |= NOSIGS; break; default: usage(); } } ac -= optind; av += optind; if ((trussinfo->pid == 0 && ac == 0) || (trussinfo->pid != 0 && ac != 0)) usage(); if (fname != NULL) { /* Use output file */ /* * Set close-on-exec ('e'), so that the output file is not * shared with the traced process. */ if ((trussinfo->outfile = fopen(fname, "we")) == NULL) err(1, "cannot open %s", fname); } /* * If truss starts the process itself, it will ignore some signals -- * they should be passed off to the process, which may or may not * exit. If, however, we are examining an already-running process, * then we restore the event mask on these same signals. */ if (trussinfo->pid == 0) { /* Start a command ourselves */ command = av; trussinfo->pid = setup_and_wait(command); signal(SIGINT, SIG_IGN); signal(SIGTERM, SIG_IGN); signal(SIGQUIT, SIG_IGN); } else { sa.sa_handler = restore_proc; sa.sa_flags = 0; sigemptyset(&sa.sa_mask); sigaction(SIGINT, &sa, NULL); sigaction(SIGQUIT, &sa, NULL); sigaction(SIGTERM, &sa, NULL); start_tracing(trussinfo->pid); } /* * At this point, if we started the process, it is stopped waiting to * be woken up, either in exit() or in execve(). */ START_TRACE: funcs = set_etype(trussinfo); initial_open = 0; /* * At this point, it's a simple loop, waiting for the process to * stop, finding out why, printing out why, and then continuing it. * All of the grunt work is done in the support routines. */ clock_gettime(CLOCK_REALTIME, &trussinfo->start_time); do { waitevent(trussinfo); switch (trussinfo->pr_why) { case S_SCE: funcs->enter_syscall(trussinfo, MAXARGS); clock_gettime(CLOCK_REALTIME, &trussinfo->curthread->before); break; case S_SCX: clock_gettime(CLOCK_REALTIME, &trussinfo->curthread->after); if (trussinfo->curthread->in_fork && (trussinfo->flags & FOLLOWFORKS)) { trussinfo->curthread->in_fork = 0; childpid = funcs->exit_syscall(trussinfo, trussinfo->pr_data); /* * Fork a new copy of ourself to trace * the child of the original traced * process. */ if (fork() == 0) { trussinfo->pid = childpid; start_tracing(trussinfo->pid); goto START_TRACE; } break; } funcs->exit_syscall(trussinfo, MAXARGS); break; case S_SIG: if (trussinfo->flags & NOSIGS) break; if (trussinfo->flags & FOLLOWFORKS) fprintf(trussinfo->outfile, "%5d: ", trussinfo->pid); if (trussinfo->flags & ABSOLUTETIMESTAMPS) { timespecsubt(&trussinfo->curthread->after, &trussinfo->start_time, &timediff); fprintf(trussinfo->outfile, "%jd.%09ld ", (intmax_t)timediff.tv_sec, timediff.tv_nsec); } if (trussinfo->flags & RELATIVETIMESTAMPS) { timespecsubt(&trussinfo->curthread->after, &trussinfo->curthread->before, &timediff); fprintf(trussinfo->outfile, "%jd.%09ld ", (intmax_t)timediff.tv_sec, timediff.tv_nsec); } signame = strsig(trussinfo->pr_data); fprintf(trussinfo->outfile, "SIGNAL %u (%s)\n", trussinfo->pr_data, signame == NULL ? "?" : signame); break; case S_EXIT: if (trussinfo->flags & COUNTONLY) break; if (trussinfo->flags & FOLLOWFORKS) fprintf(trussinfo->outfile, "%5d: ", trussinfo->pid); if (trussinfo->flags & ABSOLUTETIMESTAMPS) { timespecsubt(&trussinfo->curthread->after, &trussinfo->start_time, &timediff); fprintf(trussinfo->outfile, "%jd.%09ld ", (intmax_t)timediff.tv_sec, timediff.tv_nsec); } if (trussinfo->flags & RELATIVETIMESTAMPS) { timespecsubt(&trussinfo->curthread->after, &trussinfo->curthread->before, &timediff); fprintf(trussinfo->outfile, "%jd.%09ld ", (intmax_t)timediff.tv_sec, timediff.tv_nsec); } fprintf(trussinfo->outfile, "process exit, rval = %u\n", trussinfo->pr_data); break; default: break; } } while (trussinfo->pr_why != S_EXIT && trussinfo->pr_why != S_DETACHED); if (trussinfo->flags & FOLLOWFORKS) { do { childpid = wait(&status); } while (childpid != -1); } if (trussinfo->flags & COUNTONLY) print_summary(trussinfo); fflush(trussinfo->outfile); return (0); }
void R_WaitEvent(void) { if (!peekevent()) waitevent(); }
/* ... the usual ... */ int main(void) { presses = 0; firstpress = 0; lastpress = 0; lockdown = LOCKED_BY_DEFAULT; strobo = STROBE_BY_DEFAULT; /* initialize hardware */ init(); utx('I'); /* main loop */ while(1) { int event = waitevent(); switch(event) { case EVENT_RING: utx('R'); if(!lockdown) { /* if this is the first press, remember the time and enable signals */ if(!presses) { firstpress = gettick(); } /* blink the led */ ledoff(); waitticks(BLINKTIME); ledon(); /* if the number of presses reaches the limit, open the door */ presses++; /* record time of last keypress */ lastpress = gettick(); /* if pressed often enough */ if(presses >= PRESSES) { strobooff(); opendoor(); presses = 0; firstpress = 0; lastpress = 0; } } break; case EVENT_TIMEOUT: utx('T'); strobooff(); /* reset the sequence detector */ presses = 0; firstpress = 0; lastpress = 0; break; case EVENT_STROBE: if(strobo) stroboon(); break; case EVENT_CMD_OPEN: opendoor(); break; case EVENT_CMD_LOCK: utx('L'); lockdown = TRUE; break; case EVENT_CMD_UNLOCK: utx('U'); lockdown = FALSE; break; case EVENT_CMD_STROBO_ENABLE: utx('S'); strobo = TRUE; break; case EVENT_CMD_STROBO_DISABLE: utx('s'); strobooff(); strobo = FALSE; break; } } }
void EventThread::Entry() { struct eventreq theCurrentEvent; ::memset( &theCurrentEvent, '\0', sizeof(theCurrentEvent) ); while (!IsStopRequested()) { int theErrno = EINTR; while (theErrno == EINTR) { #if MACOSXEVENTQUEUE int theReturnValue = waitevent(&theCurrentEvent, NULL); #else int theReturnValue = select_waitevent(&theCurrentEvent, NULL); #endif //Sort of a hack. In the POSIX version of the server, waitevent can return //an actual POSIX errorcode. if (theReturnValue >= 0) theErrno = theReturnValue; else theErrno = OSThread::GetErrno(); if(IsStopRequested()) break; } if (IsStopRequested()) break; AssertV(theErrno == 0, theErrno); //ok, there's data waiting on this socket. Send a wakeup. if (theCurrentEvent.er_data != NULL) { //The cookie in this event is an ObjectID. Resolve that objectID into //a pointer. StrPtrLen idStr((char*)&theCurrentEvent.er_data, sizeof(theCurrentEvent.er_data)); OSRef* ref = fRefTable.Resolve(&idStr); if (ref != NULL) { EventContext* theContext = (EventContext*)ref->GetObject(); #if DEBUG theContext->fModwatched = false; #endif theContext->ProcessEvent(theCurrentEvent.er_eventbits); fRefTable.Release(ref); } } #if EVENT_CONTEXT_DEBUG SInt64 yieldStart = OS::Milliseconds(); #endif this->ThreadYield(); #if EVENT_CONTEXT_DEBUG SInt64 yieldDur = OS::Milliseconds() - yieldStart; static SInt64 numZeroYields; if ( yieldDur > 1 ) { qtss_printf( "EventThread time in OSTHread::Yield %i, numZeroYields %i\n", (SInt32)yieldDur, (SInt32)numZeroYields ); numZeroYields = 0; } else numZeroYields++; #endif } }
void main() { init(); while(1) { //printworld printworld(); //wait int key=waitevent(); //分发 switch(key) { case -1:return; case 0x1b:return; case 'a': { if(x1>0) x1--; break; } case 'd': { if(x1<2) x1++; break; } case 'w': { if(y1>0) y1--; break; } case 's': { if(y1<2) y1++; break; } case 0x20: { if(table[y1][x1] == 0) { table[y1][x1]=1; } int temp=check(); if(temp==1){string(100,0,"red win !!!!");} if(temp==3){string(100,0,"no winner");} break; } case 0x40000050: //left { if(x2>0) x2--; break; } case 0x4000004f: //right { if(x2<2) x2++; break; } case 0x40000052: //up { if(y2>0) y2--; break; } case 0x40000051: //down { if(y2<2) y2++; break; } case 0xd: { if(table[y2][x2] == 0) { table[y2][x2]=2; } int temp=check(); if(temp==2){string(100,0,"blue win !!!!");} if(temp==3){string(100,0,"no winner");} break; } default:continue; } } }