Beispiel #1
0
ScmObj Scm_SignalName(int signum)
{
    struct sigdesc *desc = sigDesc;
    for (; desc->name; desc++) {
        if (desc->num == signum) {
            return SCM_MAKE_STR_IMMUTABLE(desc->name);
        }
    }
    return SCM_FALSE;
}
Beispiel #2
0
void *rts_callback_test (void *msec) {
  // perform lisp callback at msec rate
  qtime_t t;
  qdata_t i=0;
  qtype_t z=0;
  int mrate=(int) msec;
  struct timespec ts;
  

#ifdef HAVE_GAUCHE
  char tmp[64] = "cm gauche vm";
  ScmVM  *vm;
  ScmVM *parentvm;
  int res = 0;
  parentvm = Scm_VM();
  vm = Scm_NewVM(parentvm, SCM_MAKE_STR_IMMUTABLE(tmp));
  // probably should check to make sure there is no error
  res = Scm_AttachVM(vm);
#endif

  pthread_mutex_init(&queue_lock, NULL);
  //  pthread_cond_init(&pause_cond, NULL);

  if ( mrate < 1000) {
    ts.tv_nsec += mrate*1000000; 
  }
  else {
    ts.tv_sec+=mrate/1000;
    ts.tv_nsec+=(mrate % 1000)*1000000;
  }
  while (rts_state != RTS_STATUS_STOPPED) {
    if (rts_callb != NULL) {
      // lock lisp access mutex
      pthread_mutex_lock(&lisp_lock);
      t=rts_scheduler_time_usec();
#ifdef HAVE_GAUCHE
      SCM_UNWIND_PROTECT {
#endif
	
	(*rts_callb) (++i, z, t) ;  
	
#ifdef HAVE_GAUCHE
      }
      SCM_END_PROTECT;
#endif

      // unlock lisp access mutex
      //pthread_mutex_unlock(&lisp_lock);
   }
    nanosleep(&ts, NULL);
  }
Beispiel #3
0
void *rts_scheduler (void *reso) {
  struct timeval currenttime;
  struct timeval targettime;
  struct timeval deltatime;
  struct timeval intervaltime;
  struct timespec waittime;
  qtime_t utime, qtime, etime;
  qentry_t *entry;
  qdata_t edata;
  qtype_t etype;
#ifdef HAVE_GAUCHE
  char tmp[64] = "cm gauche vm";
  ScmVM  *vm;
  ScmVM *parentvm;
  int res = 0;

  parentvm = Scm_VM();
  vm = Scm_NewVM(parentvm, SCM_MAKE_STR_IMMUTABLE(tmp));
  // probably should check to make sure there is no error
  res = Scm_AttachVM(vm);
#endif

  intervaltime.tv_sec = 0;
  intervaltime.tv_usec = (int32_t)reso; // 100=.1 millisecond
  deltatime.tv_sec = 0;
  while (TRUE) {
    pthread_mutex_lock(&state_lock);
    if (rts_state == RTS_STATUS_STOPPED)
      break;
    else 
      while (rts_state == RTS_STATUS_PAUSED)
	pthread_cond_wait(&pause_cond, &state_lock);
    pthread_mutex_unlock(&state_lock);

    gettimeofday(&currenttime, NULL);
    //add_timevals(&currenttime, &intervaltime, &targettime);
    timeradd(&currenttime, &intervaltime, &targettime);
    while (TRUE) {
      pthread_mutex_lock(&queue_lock);
      if (rts_queue_empty_p()) {
	pthread_mutex_unlock(&queue_lock);
	break;
      }
      entry=rts_queue_pop();
      qtime=qentry_time(entry);
      utime=rts_scheduler_time_usec();
      if (qtime>utime) {
	rts_queue_prepend(entry); 
	pthread_mutex_unlock(&queue_lock);
	break;
      }
      // drop entries more than a second late (?)
      if (qtime<(utime-1000000)) {
	qentry_free(entry);
	pthread_mutex_unlock(&queue_lock);
	break;
      }
	
      edata=qentry_data(entry);
      etype=qentry_type(entry);
      //etime=(rts_tunit == TIME_UNIT_MSEC) ? (utime/1000) : utime;
      // use queue time not clock time!
      etime=(rts_tunit == TIME_UNIT_MSEC) ? (qtime/1000) : qtime;

      qentry_free(entry); 
      pthread_mutex_unlock(&queue_lock);
      // queue unlocked during callback, enqueue should always lock
      pthread_mutex_lock(&lisp_lock);
      (*rts_callb) (edata, etype, etime);
      pthread_mutex_unlock(&lisp_lock);
    }
    gettimeofday(&currenttime, NULL);
    //fprintf(log_file, "%f \n", currenttime.tv_usec / 1000.0);
    //find_positive_delta(&targettime, &currenttime, &deltatime);
    timersub(&targettime, &currenttime, &deltatime);
    if (deltatime.tv_usec > 0) {
      waittime.tv_sec = deltatime.tv_sec;
      waittime.tv_nsec = deltatime.tv_usec * 1000L;
      //TIMEVAL_TO_TIMESPEC(&deltatime, &waittime);
      nanosleep(&waittime, NULL);
    }
  }
  rts_scheduler_reset();
  fclose(log_file);
  pthread_exit(NULL);
}