void handle_signal(int signum)
{
  switch (signum)
  {
    case SIGINT:
      notify_event(received_sigint);
      break;
    case SIGTERM:
      notify_event(received_sigterm);
      break;
#ifdef SIGHUP
    case SIGHUP:
      notify_event(received_sighup);
      break;
#endif
#ifdef SIGUSR1
    case SIGUSR1:
      notify_event(save_due);
      break;
#endif
#ifdef SIGUSR2
    case SIGUSR2:
      /* Do nothing for now. */
      break;
#endif
#if HAVE_FORK
    case SIGPIPE:
      notify_event(received_sigpipe);
      break;
#endif
  }
}
Beispiel #2
0
static void handle_signal(int signum)
{
  switch (signum)
  {
    case SIGINT:
      notify_event(received_sigint);
      break;
    case SIGTERM:
      notify_event(received_sigterm);
      break;
  }
}
void Selector_kq::mainloop()
{
    while (isRunning())
    {
        // at least can receive all error
        if (m_event.size() < m_nchange) m_event.resize(m_nchange);
        m_active = kevent(m_kqueue, change(), m_nchange, event(), m_event.size(), NULL);
        m_nchange = 0;

        if (m_active < 0)
        {
            if (errno == EINTR) continue;
            throw exception_errno("kevent");
        }

        if (m_active > m_max_active) m_max_active = m_active;

        for (int i = 0; i<m_active; ++i)
        {
            if (m_event[i].flags & EV_ERROR)
            {
                check_error(m_event[i]);
                continue;
            }

            switch (m_event[i].filter)
            {
            case EVFILT_READ:
                notify_event((Socket *)(m_event[i].udata), SEL_READ);
                break;

            case EVFILT_WRITE:
                notify_event((Socket *)(m_event[i].udata), SEL_WRITE);
                break;

            case EVFILT_SIGNAL:
                assert(m_event[i].ident == SIGALRM);
                sox::env::now = time(NULL);
                timout_run(Countdown::TIME_CLICK);
                interrupt();
                break;

            default:
                throw exception_errno(0, "unknown event");
            }
        }
        clearRemoved();
    }
}
Beispiel #4
0
void Events::update() {
    SDL_Event event;

    while (SDL_PollEvent(&event)) {
        notify_event(event);
    }
}
void check_progress(void)
{
  uint32_t current_time = time(NULL);

  if (current_time >= next_save_due)
  {
    next_save_due = current_time + save_period;
    notify_event(save_due);
  }

  if (current_time >= next_report_due)
  {
    next_report_due = current_time + REPORT_PERIOD;
    notify_event(report_due);
  }
}
Beispiel #6
0
void check_progress(void)
{
  uint32_t current_time = sec_clock();

  if (current_time >= next_save_due)
  {
    next_save_due += save_period;
    notify_event(save_due);
  }

  if (current_time >= next_report_due)
  {
    next_report_due += report_period;
    notify_event(report_due);
  }
}
Beispiel #7
0
static void report_factor(uint32_t subseq, uint32_t n, uint64_t p)
{
  uint64_t k;
  int64_t c;

  k = SEQ[SUBSEQ[subseq].seq].k;
  c = SEQ[SUBSEQ[subseq].seq].c;

  if (check_opt && !is_factor(k,c,n,p))
    error("%"PRIu64" DOES NOT DIVIDE %s.",p,kbnc_str(k,base,n,c));

  factor_count++;
  remaining_terms--;
  SUBSEQ[subseq].mcount--;
  if (SUBSEQ[subseq].mcount == 0)
    notify_event(subsequence_eliminated);

  if (p < min_factor_to_report)
    return;

  record_factor_time();
  save_factor(k,c,n,p);

  report("%"PRIu64" | %s",p,kbnc_str(k,base,n,c));
}
Beispiel #8
0
void *wait_example__ZN12wait_example8do_test1Ev_pid1_ZN12wait_example8do_test1Ev(void *arg)
{

	int this_addr;
    int alloca_20_point;
    int tmp__4;
    int tmp__5;
    int tmp__6;
    int this;

    ///+ code for struct used as input/output for pthreads
    struct inputs_wait_example__ZN12wait_example8do_test1Ev_pid1_ZN12wait_example8do_test1Ev *my_struct;
    my_struct = (struct inputs_wait_example__ZN12wait_example8do_test1Ev_pid1_ZN12wait_example8do_test1Ev *) arg;
    alloca_20_point = 0;
    this_addr = this;
    goto bb;

bb:
    tmp__4 = this_addr;
    wait_example_event_1 = notify_event();
    tmp__5 = this_addr;
    tmp__6 = this_addr;
    wait_event(wait_example_event_3); 
	events.e1=1;
	check_property();
    goto bb;
  
	wait_example__ZN12wait_example8do_test1Ev_pid1_ZN12wait_example8do_test1Ev_join = 1;

    pthread_exit(NULL);
}
/* Only react to SIGCHLD if the child has terminated, not if it has been
   stopped or continued.
*/
static void handle_sigchld(int signum)
{
  int tmp;

  tmp = errno;
  if (waitpid(-1,NULL,WNOHANG) > 0)
    notify_event(received_sigchld);
  errno = tmp;
}
void
startFuncBody(struct ThreadPool *p, ThreadFuncBase *f)
{
	p->fini_count = 0;
	p->func = f;

	for (int i=0; i<p->num_thread; i++) {
		notify_event(p->threads[i].to_client);
	}

	wait_event(p->to_master);

	return;
}
void
finiThreadPool(struct ThreadPool *p)
{
	p->fini_all = true;

	for (int i=0; i<p->num_thread; i++) {
		notify_event(p->threads[i].to_client);
	}
	for (int i=0; i<p->num_thread; i++) {
		p->threads[i].t.join();
	}

	delete [] p->threads;

	delete_event(p->to_master);
}
void Thread::func() {
	while (1) {
		wait_event(to_client);
		rmb();

		if (this->p->fini_all) {
			return;
		}

		(*p->func)();

		int count = ++p->fini_count;
		if (count == p->num_thread) {
			notify_event(p->to_master);
		}
	}
}
Beispiel #13
0
/**
 * @brief The main function.
 *
 * The main loop is executed here.
 * The input events are forwarded to the current screen.
 * The current screen is redrawn when necessary.
 */
void Solarus::main_loop() {

  // main loop
  InputEvent *event;
  uint32_t now;
  uint32_t next_frame_date = System::now();
  uint32_t frame_interval = 25; // time interval between to displays
  int delay;
  bool just_displayed = false; // to detect when the FPS number needs to be decreased

  while (!is_exiting()) {

    // handle the input events
    event = InputEvent::get_event();
    if (event != NULL) {
      notify_event(*event);
      delete event;
    }

    // update the current screen
    update();

    // go to another screen?
    if (current_screen->is_screen_finished()) {
      Screen *next_screen = current_screen->get_next_screen();
      delete current_screen;

      if (next_screen != NULL) {
        current_screen = next_screen;
      }
      else {
        current_screen = new LanguageScreen(*this);
      }
    }
    else {

      now = System::now();
      delay = next_frame_date - now;
      // delay is the time remaining before the next display

      if (delay <= 0) { // it's time to display

        // see if the FPS number is too high
        if (just_displayed && frame_interval <= 30) {
          frame_interval += 5; // display the screen less often
          //std::cout << "\rFPS: " << (1000 / frame_interval) << std::flush;
        }

        next_frame_date = now + frame_interval;
        just_displayed = true;
        display();
      }
      else {
        just_displayed = false;

        // if we have time, let's sleep to avoid using all the processor
        System::sleep(1);

        if (delay >= 15) {
          // if we have much time, increase the FPS number
          frame_interval--;
          //std::cout << "\rFPS: " << (1000 / frame_interval) << std::flush;
        }
      }
    }
  }
}