Exemple #1
0
void loop() {
  unsigned char ticks_needed = TICKS_TO_GATHER;
  while(1){
    doTick(); // 1
    doSleep(); // 2
    if (q_random() % 4) {
      // Be normal. A "second" is 10 ticks long.
      for(unsigned char i = 0; i < IRQS_PER_SECOND - 2; i++)
        doSleep();
    } else {
      // This is a special "second" - it's *11* ticks long.
      // Every tenth one, we're goging to insert a "stutter tick"
      if (--ticks_needed == 0) {
        doTick();
        for(unsigned char i = 0; i < PAUSE_TICKS; i++)
          doSleep();
        ticks_needed = TICKS_TO_GATHER;
      } else {
        doSleep();
      }
      for (unsigned char i = 0; i < IRQS_PER_SECOND - 2; i++) // yes, -2, not -3.
        doSleep();
    }
  }
}
Exemple #2
0
int
tempDirToucherMain(int argc, char *argv[]) {
	initialize(argc, argv, 2);
	installSignalHandlers();
	maybeDaemonize();
	maybeWritePidfile();

	while (1) {
		if (dirExists(dir)) {
			DEBUG("Touching directory");
			touchDir(dir);
			if (!doSleep(sleepInterval)) {
				break;
			}
		} else {
			DEBUG("Directory no longer exists, exiting");
			break;
		}
	}

	maybeDeletePidFile();
	if (shouldCleanup) {
		DEBUG("Cleaning up directory");
		performCleanup(dir);
	}

	return 0;
}
Exemple #3
0
int
main(int argc, char *argv[]) {
	initialize(argc, argv);
	installSignalHandlers();
	maybeDaemonize();
	maybeWritePidfile();

	while (1) {
		if (dirExists(dir)) {
			touchDir(dir);
			if (!doSleep(1800)) {
				break;
			}
		} else {
			break;
		}
	}

	maybeDeletePidFile();
	if (shouldCleanup) {
		performCleanup(dir);
	}

	return 0;
}
Exemple #4
0
int main(int argc,char** argv) {
  int a = get_a(argc);
  printf("%i\n", a);
  while(1) {
    printf("%i\n", a);
    doSleep(1);
    a+=1;
  }
}
Exemple #5
0
void loop() {
  while(1) {
    // Do this about once a minute-ish.
    if (q_random() % 30 != 0) {
      // a normal second.
      doTick();
      for(int i = 0; i < IRQS_PER_SECOND - 1; i++)
        doSleep();
      continue;
    }

    // Time to play a song!
    unsigned int song = q_random() % SONG_COUNT;
    unsigned char *current_song = (unsigned char*)pgm_read_ptr(song_table + song);
    while(1) {
      unsigned char song_data = pgm_read_byte(current_song++);
      if (song_data == 0) break; // song over
      doTick();
      for(int i = 0; i < song_data; i++)
        doSleep();
    }
  }
}
Exemple #6
0
IOReturn AppleGPIO::powerStateWillChangeTo (IOPMPowerFlags theFlags, unsigned long, IOService*)
{	
    if ( ! (theFlags & IOPMPowerOn) ) {
        // Sleep sequence:
		DLOG("AppleGPIO::powerStateWillChangeTo - sleep\n");
		doSleep();
   } else {
        // Wake sequence:
		DLOG("AppleGPIO::powerStateWillChangeTo - wake\n");
		doWake();
    }
	
    return IOPMAckImplied;
}
Exemple #7
0
void loop() {
  static unsigned int fractional_position = 0;
  static unsigned int tick_counter = 0;

  unsigned int limit = WHOLE;
  if (fractional_position < NUMERATOR) limit++;
  if (tick_counter++ >= limit) {
    tick_counter = 0;
    fractional_position++;
    if (fractional_position >= DENOMINATOR) fractional_position = 0;
    doTick();
  } else {
    doSleep();
  }
}
Exemple #8
0
void loop() {
  unsigned char cycle_direction = 0; // fast
  unsigned long cycle_position = 0;
  while(1) {
    for(unsigned char i = 0; i < IRQS_PER_SECOND + (CYCLE_MAGNITUDE * (cycle_direction?-1:1)); i++) {
      if (i == 0)
        doTick();
      else
        doSleep();
    }
    if (cycle_position++ >= CYCLE_LENGTH) {
      cycle_position = 0;
      cycle_direction = !cycle_direction;
    }
  }
} 
Exemple #9
0
int CONTROL_SET(SIO_INFO *s)
{
  BOOL b;

  if (s!=NULL) {
    if (s->control_state & SIO_CONTROL_RTS)
      b=EscapeCommFunction(s->fd,SETRTS);
    else
      b=EscapeCommFunction(s->fd,CLRRTS);
    if (s->control_state & SIO_CONTROL_DTR)
      b=EscapeCommFunction(s->fd,SETDTR);
    else
      b=EscapeCommFunction(s->fd,CLRDTR);
    PurgeComm(s->fd,PURGE_RXABORT|PURGE_RXCLEAR);
    doSleep(100); /* 10 is too short */
  } else {
    return(-1);
  }
}
// . return false if blocked, otherwise true
// . sets g_errno on error
bool RdbMerge::resumeMerge ( ) {
	// return true if not suspended
	if ( ! m_isSuspended ) return true;
	// turn off the suspension so getNextList() will work
	m_isSuspended = false;
	// the usual loop
 loop:
	// . this returns false if blocked, true otherwise
	// . sets g_errno on error
	// . we return true if it blocked
	if ( ! getNextList ( ) ) return false;
	// if g_errno is out of memory then msg3 wasn't able to get the lists
	// so we should sleep and retry...
	// or if no thread slots were available...
	if ( g_errno == ENOMEM || g_errno == ENOTHREADSLOTS ) { 
		doSleep(); return false; }
	// if list is empty or we had an error then we're done
	if ( g_errno || m_doneMerging ) { doneMerging(); return true; }
	// . otherwise dump the list we read to our target file
	// . this returns false if blocked, true otherwise
	if ( ! dumpList ( ) ) return false;
	// repeat ad nauseam
	goto loop;
}
Exemple #11
0
void* LED_output() {

while (1) {

switch (LED_mode) {

	case 1:
		pinMode(2,OUTPUT);
		digitalWrite(2,1);
		doSleep(0,250000000);
		digitalWrite(2,0);
		doSleep(0,250000000);
		break;

	case 2:
		pinMode(2,OUTPUT);
		digitalWrite(2,1);
		doSleep(0,500000000);
		digitalWrite(2,0);
		doSleep(0,250000000);
		break;

	case 3:
		pinMode(0,OUTPUT);
		pinMode(2,OUTPUT);
		digitalWrite(0,1);
		doSleep(0,500000000);
		digitalWrite(0,0);
		doSleep(0,500000000);
		digitalWrite(2,1);
		doSleep(0,500000000);
		digitalWrite(2,0);
		doSleep(0,500000000);
		break;

	case 4:
		pinMode(0,OUTPUT);
		digitalWrite(0,1);
		doSleep(0,250000000);
		digitalWrite(0,0);
		doSleep(0,250000000);
		break;

	case 5:
		pinMode(0,OUTPUT);
		digitalWrite(0,1);
		doSleep(0,500000000);
		digitalWrite(0,0);
		doSleep(0,250000000);
		break;

	default: /*signaling ERROR*/
		pinMode(3,OUTPUT);
		digitalWrite(3,1);
		doSleep(0,750000000);
		digitalWrite(3,0);
		doSleep(0,250000000);
		break;
	}
}
return 0;
}
// . return false if blocked, true otherwise
// . sets g_errno on error
bool RdbMerge::getNextList ( ) {
	// return true if g_errno is set
	if ( g_errno || m_doneMerging ) return true;
	// it's suspended so we count this as blocking
	if ( m_isSuspended ) {
		m_isReadyToSave = true;
		return false;
	}
	// if the power is off, suspend the merging
	if ( ! g_process.m_powerIsOn ) {
		m_isReadyToSave = true;
		doSleep();
		return false;
	}
	// no chop threads
	m_numThreads = 0;
	// get base, returns NULL and sets g_errno to ENOCOLLREC on error
	RdbBase *base; if (!(base=getRdbBase(m_rdbId,m_collnum))) return true;
	// . if a contributor has just surpassed a "part" in his BigFile
	//   then we can delete that part from the BigFile and the map
	for ( long i = m_startFileNum ; i < m_startFileNum + m_numFiles; i++ ){
		RdbMap    *map    = base->m_maps[i];
		long       page   = map->getPage ( m_startKey );
		long long  offset = map->getAbsoluteOffset ( page );
		BigFile   *file   = base->m_files[i];
		long       part   = file->getPartNum ( offset ) ;
		if ( part == 0 ) continue;
		// i've seen this bug happen if we chop a part off on our
		// last dump and the merge never completes for some reason...
		// so if we're in the last part then don't chop the part b4 us
		if ( part >= file->m_maxParts - 1 ) continue;
		// if we already unlinked part # (part-1) then continue
		if ( ! file->doesPartExist ( part - 1 ) ) continue;
		// . otherwise, excise from the map
		// . we must be able to chop the mapped segments corresponding
		//   EXACTLY to the part file
		// . therefore, PAGES_PER_SEGMENT define'd in RdbMap.h must
		//   evenly divide MAX_PART_SIZE in BigFile.h
		// . i do this check in RdbMap.cpp
		if ( ! map->chopHead ( MAX_PART_SIZE ) ) {
			// we had an error!
			log("db: Failed to remove data from map for "
			    "%s.part%li.",
			    file->getFilename(),part);
			return true;
		}
		// . also, unlink any part files BELOW part # "part"
		// . this returns false if it blocked, true otherwise
		// . this sets g_errno on error
		// . now we just unlink part file #(part-1) explicitly
		if ( ! file->chopHead ( part - 1 , chopWrapper , this ) ) 
			m_numThreads++;
		if ( ! g_errno ) continue;
		log("db: Failed to unlink file %s.part%li.",
		    file->getFilename(),part);
		return true;
	}
	// wait for file to be unlinked before getting list
	if ( m_numThreads > 0 ) return false;
	// otherwise, get it now
	return getAnotherList ( );
}
Exemple #13
0
int SIO_Delay(SIO_INFO *s,unsigned long delay)
{
  return doSleep(delay);
}