예제 #1
0
/*
ROUTINE: WaitTicks
PURPOSE:
  Wait ticks (60.15 Hz), then return.
*/
void WaitTicks(long ticks)
{
  ticks+=TickCount();
  while(TickCount()+30<ticks)if(CommandPeriod())PrintfExit("User typed cmd-. Exiting.");
  while(TickCount()<ticks) ;
  return;
}
예제 #2
0
파일: micro.c 프로젝트: shaoguangleo/rts2
PAR_ERROR
SendMicroBlock (unsigned char *p, int len)
{
  PAR_ERROR err = CE_NO_ERROR;
  short i;
  unsigned long t0;

  t0 = TickCount ();
  CameraOut (0x30, 4);
  // i = 0;

  // while(i <= len)
  for (i = 0; i <= len;)
    {
      if (!MicroStat ())
	{
	  if (TickCount () - t0 <= 5)
	    continue;
	  else
	    {
	      err = CE_TX_TIMEOUT;
	      CameraOut (0x30, 0);
	      break;
	    }
	}
      if (i == len)
	break;
      if (i == 1)
	CameraOut (0x30, control_out & 0xfb);
      MicroOut (*(p++));
      i++;
      t0 = TickCount ();
    }
  return err;
}
예제 #3
0
int main ()
{
	int ret;
	Rect windRect;
	long start,end,amount;
	
	/* Initialize all the needed managers. */
	InitGraf(&qd.thePort);
	InitFonts();
	InitWindows();
	InitMenus();
	TEInit();
	InitDialogs(nil);
	InitCursor();

	//ProfilerInit(collectDetailed, bestTimeBase, 1000, 50);
	//ProfilerSetStatus(true);

	windRect = qd.screenBits.bounds;
	InsetRect(&windRect, 50, 50);
	pWindow = NewCWindow(nil, &windRect, "\pMpeg", true, documentProc, (WindowPtr) -1, false, 0);
    
    start = TickCount();
    main2();
    end = TickCount();
    amount = end - start;
    fprintf(stderr, "Time taken %d memoryAllocator %d \n", amount,counter);

   //	ProfilerDump("\pProfile.out");
     
    do {
	} while (!Button());


}
예제 #4
0
void hold_for_visible_delay(
	void)
{
	long start= TickCount();
	
	while(TickCount()<start+VISIBLE_DELAY);
}
예제 #5
0
/* 
 * Check messages and interrupts; return true if interrupted.
 * This is called frequently - it must be quick!
 */
int gp_check_interrupts(const gs_memory_t *mem)
{
	/* static variables need to go away for thread safety */
	static unsigned long	lastYieldTicks = 0;
	int iRetVal = 0;
	
	if ((TickCount() - lastYieldTicks) > 2) {
	    lastYieldTicks = TickCount();
	    if (pgsdll_callback) {
		/* WARNING: The use of the old gsdll interface is deprecated. 
		 * The caller should use the newer gsapi_set_poll.
		 * If the caller needs access to "hwndtext", it should do 
		 * this via caller_handle which is passed to poll_fn.
		 */
		/* the hwnd parameter which is submitted in gsdll_init 
		 * to the DLL is returned in every gsdll_poll message 
		 * in the count parameter
		 */
		iRetVal = (*pgsdll_callback)(GSDLL_POLL, 0, (long) hwndtext);
	    } else {
	    	if (mem == NULL) {
	    		/* this is not thread safe */
	    		mem = gs_lib_ctx_get_non_gc_memory_t();
	    	}
		if (mem && mem->gs_lib_ctx && mem->gs_lib_ctx->poll_fn)
		    iRetVal = (*mem->gs_lib_ctx->poll_fn)(mem->gs_lib_ctx->caller_handle);
	    }
	}
	return iRetVal;
}
예제 #6
0
static pascal OSStatus MyMainThreadYielder(void)
{
	OSStatus err;
	static UInt32 gTimeLastPrinted;
	
	if ( TickCount() > (gTimeLastPrinted + 30) ) {
		printf(".");
		fflush(stdout);
		gTimeLastPrinted = TickCount();
	}

	#if TARGET_API_MAC_CARBON
		{
			err = noErr;
			if (GetCurrentKeyModifiers() & alphaLock) {
				err = kOTCanceledErr;
			}
		}
	#else
		{
			EventRecord event;
			
			err = noErr;
			(void) OSEventAvail(0, &event);
			if (event.modifiers & alphaLock) {
				err = kOTCanceledErr;
			}
		}
	#endif
	return err;
}
예제 #7
0
CV_IMPL int cvWaitKey (int maxWait)
{
    EventRecord theEvent;

    // wait at least for one event (to allow mouse, etc. processing), exit if maxWait milliseconds passed (nullEvent)
    UInt32 start = TickCount();
    int iters=0;
    do
    {
        // remaining time until maxWait is over
        UInt32 wait = EventTimeToTicks (maxWait / 1000.0) - (TickCount() - start);
        if ((int)wait <= 0)
        {
            if( maxWait > 0 && iters > 0 )
                break;
            wait = 1;
        }
        iters++;
        WaitNextEvent (everyEvent, &theEvent, maxWait > 0 ? wait : kDurationForever, NULL);
    }
    while (lastKey == NO_KEY  &&  theEvent.what != nullEvent);

    int key = lastKey;
    lastKey = NO_KEY;
    return key;
}
예제 #8
0
파일: macstuff.c 프로젝트: AMDmi3/analog
void MacIdle(void)
{
  extern logical anywarns;
  static long time = 0;

  EventRecord myEvent;
  WindowPtr whichWindow;
#if TARGET_API_MAC_CARBON
  Rect tempRect;
#endif
  char theChar;

  if (TickCount()<time) return;
  if (mac_quit_now) {
    anywarns = FALSE;  /* kludge so that window doesn't sit around */
    my_exit(1);
  }
#if !TARGET_API_MAC_CARBON
  SystemTask();
#endif
  if (WaitNextEvent(everyEvent, &myEvent, 1, nil)) {

    if (!SIOUXHandleOneEvent(&myEvent)) switch (myEvent.what) {

    case mouseDown:
      switch (FindWindow(myEvent.where,&whichWindow)) {

      case inMenuBar:
	MenuSelect(myEvent.where);
	break;
#if !TARGET_API_MAC_CARBON
      case inSysWindow:
	SystemClick(&myEvent,whichWindow);
	break;
#endif
      case inContent:
	SelectWindow(whichWindow);
	break;
      case inDrag:
#if TARGET_API_MAC_CARBON
	GetRegionBounds(GetGrayRgn(),&tempRect);
	DragWindow(whichWindow,myEvent.where,&tempRect);
#else
	DragWindow(whichWindow,myEvent.where,&qd.screenBits.bounds);
#endif
	break;
      }
      break;
    case keyDown:
      theChar = myEvent.message & charCodeMask;
      break;
    case updateEvt:
      BeginUpdate((WindowPtr) myEvent.message);
      EndUpdate((WindowPtr) myEvent.message);
      break;
    }
  }
  time=TickCount()+20;
}
예제 #9
0
int domultitask_( long *sleepTime )
{
 	if( TickCount() > gNextCheck )   				/* Time to check for events again? */
    {
    	getchar();   								/* poll for char to have console call WNE */
		gNextCheck = TickCount() + gTickSlice;		/* Reset the tick count */
    }
    return 1;
}
예제 #10
0
static void CallSystemTask()
  {
   static unsigned long int lastCall;

   if (TickCount() < (lastCall + 10)) return;
   SystemTask();
   lastCall = TickCount();
   return;
  }
예제 #11
0
McoStatus Techkon::GetPaperDensity(void)
{
long tick = TickCount();

while (TickCount() - tick < 240)
	{
	if ((!IsBufferEmpty()) && (IsDataPresent())) return getNextPatch(paperDensity);
	}
return MCO_FAILURE;
}
예제 #12
0
void stay_awake(
	void)
{
	if (TickCount()>last_fake_keyboard_event+FAKE_KEYBOARD_EVENT_PERIOD)
	{
		last_fake_keyboard_event= TickCount();
		PostEvent(keyDown, 0);
	}
	
	return;
}
예제 #13
0
McoStatus Techkon::sendReadCommand(void)
{
int32 tc;

if (sp == 0L) return MCO_SERIAL_ERROR;

tc = TickCount();

sendCommand(Tech_Measure);
do {} while (IsBufferEmpty() && (TickCount() - tc < 120));
return MCO_SUCCESS;
}
예제 #14
0
// Uses usleep to sleep for full duration even if a signal is received
static void SleepTicks(UInt32 ticksToSleep) {
    UInt32 endSleep, timeNow, ticksRemaining;

    timeNow = TickCount();
    ticksRemaining = ticksToSleep;
    endSleep = timeNow + ticksToSleep;
    while ( (timeNow < endSleep) && (ticksRemaining <= ticksToSleep) ) {
        usleep(16667 * ticksRemaining);
        timeNow = TickCount();
        ticksRemaining = endSleep - timeNow;
    } 
}
예제 #15
0
McoStatus TCR::moveToPatch(int32 patchNum, int ref)
{
char st[500];
int32 dx_i,dy_i;
double dist;
long tc;
int waitTime;
int32	table[2];

if (sp == 0L) return MCO_SERIAL_ERROR;

translateToTable(&pointArray[patchNum*2],table);

//dx_i = table[0]-current_x;
//dy_i = table[1]-current_y;

//sprintf(st,"PR %ld %ld;",dx_i,dy_i);	// the move command

table[0] = MaxVal(table[0],min_x);
table[0] = MinVal(table[0],max_x);

table[1] = MaxVal(table[1],min_y);
table[1] = MinVal(table[1],max_y);

sprintf(st,"PA %ld %ld;",(long)table[0],(long)table[1]);	// the move command

sp->sendData(st,strlen(st));


dx_i = table[0]-current_x;
dy_i = table[1]-current_y;

// wait a time that is determined by the distance moved
dist = sqrt((double)(dx_i*dx_i+dy_i*dy_i))*0.025;

// assume that it moves 250mm/sec

waitTime = 36+(int)(60.0*dist/150.0);

tc = TickCount();
while (TickCount() - tc < waitTime) {}

//current_x = pointArray[patchNum*2];
//current_y = pointArray[patchNum*2+1];

current_x += dx_i;
current_y += dy_i;

return MCO_SUCCESS;
}
예제 #16
0
Boolean MCScreenDC::abortkey()
{ /* check for Command-. system abort key */
	if (MCabortscript)
		return True;
	static uint4 alarmcount;
	uint4 newcount = TickCount();
	if (newcount < alarmcount)
		return False;
	alarmcount = newcount + 30;
			
	// MW-2008-07-31: [[ Bug 6850 ]] Variable watcher breaks out when using scroll wheel.
	//   This bug was caused by the previous version of checking for an abortkey causing
	//   Carbon events to be handled. This can result in things such WheelUp/WheelDown
	//   events being dispatched *inside* previous invocations.
	if (CheckEventQueueForUserCancel())
	{
		if (MCallowinterrupts && !MCdefaultstackptr -> cantabort())
			return True;
		else
			MCinterrupt = True;
			
		// OK-2010-04-29: [[Bug]] - cantAbort / allowInterrupts not working on OS X
		return False;
	}
			
	if (MCnsockets != 0)
		MCS_handle_sockets();
	return False;
}
예제 #17
0
파일: logging.cpp 프로젝트: yoantie/baselib
	// writes the common header info to the stream
	void LogMessage::Init(const char* file, int line) {
		std::string filename(file);
		size_t last_slash_pos = filename.find_last_of("\\/");
		if (last_slash_pos != std::string::npos)
			filename = filename.substr(last_slash_pos + 1);

		stream_ <<  '[';
		stream_ << ::GetCurrentProcessId() << ':';
		stream_ << ::GetCurrentThreadId() << ':';
		if (log_timestamp) {
			time_t t = time(NULL);
			struct tm local_time = {0};
			localtime_s(&local_time, &t);
			struct tm* tm_time = &local_time;
			stream_ << std::setfill('0')
				<< std::setw(2) << 1 + tm_time->tm_mon
				<< std::setw(2) << tm_time->tm_mday
				<< '/'
				<< std::setw(2) << tm_time->tm_hour
				<< std::setw(2) << tm_time->tm_min
				<< std::setw(2) << tm_time->tm_sec
				<< ':';
		}
		if (log_tickcount)
			stream_ << TickCount() << ':';
		if (severity_ >= 0)
			stream_ << log_severity_name(severity_);
		else
			stream_ << "VERBOSE" << -severity_;

		stream_ << ":" << filename << "(" << line << ")] ";

		message_start_ = stream_.tellp();
	}
예제 #18
0
/* wait for MacTCP to finish whatever it's doing, with user cancel
 */
static short tcp_wait(struct tcpstate *ts, tcpinfo *tcp)
{
	KeyMap mapkeys;
#define keys ((unsigned char *)mapkeys)
	short percent;

	while (!tcp_checkdriver()
		|| (tcp && (tcp->state & TCP_DNSINUSE) && ! (volatile) tcp->dnrdone)
		|| (tcp && (tcp->state & TCP_PBINUSE) && (volatile short) tcp->pb.ioResult == 1)) {
		if (ts) {
			if (!ts->waiticks) return (0);
			percent = ((TickCount() - ts->waitstart) * 100) / ts->waiticks;
			if (percent > 100) percent = 100;
			if (percent != ts->waitpercent) {
				(*ts->tcp_initp)(ts->waitpercent = percent);
			}
			if (percent == 100) return (0);
		}
		SystemTask();
		GetKeys(mapkeys);
		if ((keys[0x37 >> 3] >> (0x37 & 7))
			& (keys[0x2f >> 3] >> (0x2f & 7)) & 1) {
			return (0);
		}
	}
	
	return (1);
}
예제 #19
0
/* clean up the TCP task
 */
static short tcp_closep(na_win *win)
{
	short i, j;
	tcpinfo *tcp;
	tcpwb *wb;
	TCPiopb pb;
	
	tstate->waitstart = TickCount();
	tstate->waitpercent = 0;
	tcp_wait(tstate, NULL);
	memset((void *) &pb, 0, sizeof (pb));
	for (i = 0; i < MAX_TCPCON; ++i) {
		if ((tcp = tstate->tcpbufs[i]) != NULL) {
			/* wait for MacTCP to finish what it's doing, but permit user cancel */
			if (!tcp->server || tcp->state != TCP_CONNECT) tcp_wait(tstate, tcp);
			if (!tcp->gethost) {
				pb.ioCRefNum = tstate->tcp_driver;
				pb.tcpStream = tcp->stream;
				pb.csCode = TCPRelease;
				PBControl((ParmBlkPtr) &pb, false);
			}
			freewb(tcp->wb);
			freewb(tcp->wb + 1);
			DisposPtr((Ptr) tcp);
			tstate->tcpbufs[i] = NULL;
		}
	}
	tcpstate = NULL;
	if (tstate->tcp_driver) CloseResolver();
	
	return (NA_CLOSED);
}
예제 #20
0
파일: music.c 프로젝트: DrItanium/moo
void queue_song(
	short song_index)
{
	if (music_state && music_state->initialized && get_sound_volume())
	{
		if (!music_state->channel)
		{	
			allocate_music_channel();
		}
	
		if (music_state->channel)
		{
			if (music_playing())
			{
				/* By setting the song_index after we tell it to fade, we will */
				/*  cause the new song to start at the end of the fade. */
				fade_out_music(10*MACINTOSH_TICKS_PER_SECOND);
				music_state->song_index= song_index;
			}
			else
			{
				assert(music_state->state==_no_song_playing);
		
				/* Must be done everytime in case Jason killed it in sound.c */
				music_state->channel->userInfo= (long) music_state;
				music_state->song_index= song_index;
				music_state->state= _delaying_for_loop;
				music_state->phase= 1;
				music_state->ticks_at_last_update= TickCount();
				music_state->flags &= ~_song_completed;
				/* next time through we will start.. */
			}
		}
	}
}
예제 #21
0
// ticks() --
// -- returns the number of milliseconds elapsed since
//    a system dependent date.
unsigned long
GOS::ticks()
{
#if defined(UNIX)
    struct timeval tv;
    if (gettimeofday(&tv, NULL) < 0)
        G_THROW(errmsg());
    return (unsigned long)( ((tv.tv_sec & 0xfffff)*1000)
                            + (tv.tv_usec/1000) );
#elif defined(WIN32)
    DWORD clk = GetTickCount();
    return (unsigned long)clk;
#elif defined(OS2)
    ULONG clk = 0;
    DosQuerySysInfo(QSV_MS_COUNT, QSV_MS_COUNT, (PVOID)&clk, sizeof(ULONG));
    return clk;
#elif defined(macintosh)
    return (unsigned long)((double)TickCount()*16.66);
#else
    struct timeval tv;
    if (gettimeofday(&tv, NULL) < 0)
        G_THROW(errmsg());
    return (unsigned long)( ((tv.tv_sec & 0xfffff)*1000)
                            + (tv.tv_usec/1000) );

#endif
}
예제 #22
0
CMacAsyncFile::~CMacAsyncFile()
{
    if (m_DeferredTaskStruct.dtAddr != NULL)
    {
#ifdef _CARBON
	DisposeDeferredTaskUPP(m_DeferredTaskStruct.dtAddr);
#else
	DisposeRoutineDescriptor(m_DeferredTaskStruct.dtAddr);
#endif
	m_DeferredTaskStruct.dtAddr = NULL;
    }    

    Close();

    HX_DELETE(mAsyncQueue);
    HX_DELETE(m_pPendingCallbackList);
    HX_DELETE(m_pTimedPQList);
    HX_DELETE(m_pLocationPQList);
    HX_DELETE(mReadQueue);
#if defined(_DEBUG) && defined(LOG_MULTIPLE_DEFERRED_TASKS)
    HXBOOL bWaitedForDeferred = FALSE;
    if ( m_bDeferredTaskPending )
    {
	bWaitedForDeferred = TRUE;
	DebugStr("\pCMacAsyncFile dtor -- a deferred task is pending!;g");
    }
#endif
    
    UINT32 timeout = TickCount() + 300L;
    m_bIsQuitting = TRUE;
    while ( m_bDeferredTaskPending && timeout - TickCount() > 0 )
    {
	// sit-n-spin, awaiting completion of callbacks.
    }
    
#if defined(_DEBUG) && defined(LOG_MULTIPLE_DEFERRED_TASKS)
    if ( bWaitedForDeferred )
    {
	if ( m_bDeferredTaskPending )
	{
	    DebugStr("\pdeferred task STILL pending! This is gonna hurt;g");
	}
	else
	{
	    DebugStr( "\pDeferred tasks were successfully purged;g" );
	}
    }
예제 #23
0
/*
	PsychEstimateGetSecsValueAtTickCountZero()
	Note that the tick counter rolls over about every 27 months. Its possible to have machine uptime of that long 
	but it seems unlikely so we don't worry about roll over when calculating 
*/
void PsychEstimateGetSecsValueAtTickCountZero(void)
{
	double		nowTicks, nowSecs;
	
	nowTicks=(double)TickCount();
	PsychGetAdjustedPrecisionTimerSeconds(&nowSecs);
	estimatedGetSecsValueAtTickCountZero=nowSecs - nowTicks * (1/60.15); 
}
예제 #24
0
파일: main.cpp 프로젝트: gchilders/boinc
int boinc_main_loop() {
    int retval;

    retval = initialize();
    if (retval) return retval;

#ifdef __APPLE__
    // If we run too soon during system boot we can cause a kernel panic
    if (gstate.executing_as_daemon) {
        if (TickCount() < (120*60)) {   // If system has been up for less than 2 minutes
            boinc_sleep(30.);
        }
    }
#endif

    retval = gstate.init();
    if (retval) {
        log_message_error("gstate.init() failed", retval);
        return retval;
    }

    log_message_startup("Initialization completed");

    while (1) {
        if (!gstate.poll_slow_events()) {
            gstate.do_io_or_sleep(POLL_INTERVAL);
        }
        fflush(stderr);
        fflush(stdout);

        if (gstate.time_to_exit()) {
            msg_printf(NULL, MSG_INFO, "Time to exit");
            break;
        }
        if (gstate.requested_exit) {
            if (cc_config.abort_jobs_on_exit) {
                if (!gstate.in_abort_sequence) {
                    msg_printf(NULL, MSG_INFO,
                               "Exit requested; starting abort sequence"
                              );
                    gstate.start_abort_sequence();
                }
            } else {
                msg_printf(NULL, MSG_INFO, "Exiting");
                break;
            }
        }
        if (gstate.in_abort_sequence) {
            if (gstate.abort_sequence_done()) {
                msg_printf(NULL, MSG_INFO, "Abort sequence done; exiting");
                break;
            }
        }
    }

    return finalize();
}
예제 #25
0
bool CBOINCClientManager::IsSystemBooting() {
    bool bReturnValue = false;
#if   defined(__WXMSW__)
    if (GetTickCount() < (1000*60*5)) bReturnValue = true;  // If system has been up for less than 5 minutes 
#elif defined(__WXMAC__)
    if (TickCount() < (120*60)) bReturnValue = true;        // If system has been up for less than 2 minutes 
#endif
    return bReturnValue;
}
예제 #26
0
void stime_start(int resolution)

{

  gSTimeStartTime = TickCount();

  gSTimeResolution = resolution;

}
예제 #27
0
void InitMultiTask( long sliceInTicks ) 
{
	if ( sliceInTicks > 0 )
		gTickSlice = sliceInTicks;	

	InitAnimatedCursors( 128 );
	
	/* Start the tick count */
	gNextCheck = TickCount() + gTickSlice;
}
예제 #28
0
void ag_random_seed(void)
{
#ifdef D3_OS_WINDOWS
	ag_seed=GetTickCount();
#else
	ag_seed=TickCount();
#endif

	srandom(ag_seed);
}
예제 #29
0
static void recordTicks(void)
{
	/*debugging stuff*/
	if (GUBED & 8)
	{
		long            thisticks, mticks, i;
		if (CurrentN < 0)
		{
			SymhTicks = Lookup("TICKS");
			if (SymhTicks == (Symbolhandle) 0)
			{
				mticks  = NTICKS*(MAXTICKS/NTICKS);
				SymhTicks = RInstall("TICKS", mticks);
			}
			else
			{
				mticks = symbolSize(SymhTicks);
			}
			for (i = 0;i < mticks; i++)
			{
				setMissing(DATAVALUE(SymhTicks, i));
			}
			Lastticks = TickCount();
			CurrentN = 0;
		}
		else if (CurrentN < DIMVAL(SymhTicks, 1))
		{
			thisticks = TickCount();
			DATAVALUE(SymhTicks, CurrentN++) = (double) (thisticks - Lastticks);
			Lastticks = thisticks;
		}
		else
		{
			GUBED &= ~8;
			CurrentN = -1;
		}
	} /*if (GUBED & 8)*/
	else
	{
		CurrentN = -1;
	}
} /*recordTicks()*/	
예제 #30
0
void InitMultiTask( long sliceInTicks ) 
{
	if ( sliceInTicks > 0 )
		gTickSlice = sliceInTicks;	
	
	/* Set console so we can interogate for input (to trigger WNE) without waiting for input */
	csetmode( C_RAW, stdin );

	/* Start the tick count */
	gNextCheck = TickCount() + gTickSlice;
}