Ejemplo n.º 1
0
/*
 * Initialize this Virtual Processor
 */
int st_init(void)
{
  _st_thread_t *thread;

  if (_st_active_count) {
    /* Already initialized */
    return 0;
  }

  /* We can ignore return value here */
  //st_set_eventsys(ST_EVENTSYS_DEFAULT);
  st_set_eventsys(ST_EVENTSYS_ALT);

  if (_st_io_init() < 0)
    return -1;

  memset(&_st_this_vp, 0, sizeof(_st_vp_t));

  ST_INIT_CLIST(&_ST_RUNQ);
  ST_INIT_CLIST(&_ST_IOQ);
  ST_INIT_CLIST(&_ST_ZOMBIEQ);
#ifdef DEBUG
  ST_INIT_CLIST(&_ST_THREADQ);
#endif

  if ((*_st_eventsys->init)() < 0)
    return -1;

  _st_this_vp.pagesize = getpagesize();
  _st_this_vp.last_clock = st_utime();

  /*
   * Create idle thread
   */
  _st_this_vp.idle_thread = st_thread_create(_st_idle_thread_start,
					     NULL, 0, 0);
  if (!_st_this_vp.idle_thread)
    return -1;
  _st_this_vp.idle_thread->flags = _ST_FL_IDLE_THREAD;
  _st_active_count--;
  _ST_DEL_RUNQ(_st_this_vp.idle_thread);

  /*
   * Initialize primordial thread
   */
  thread = (_st_thread_t *) calloc(1, sizeof(_st_thread_t) +
				   (ST_KEYS_MAX * sizeof(void *)));
  if (!thread)
    return -1;
  thread->private_data = (void **) (thread + 1);
  thread->state = _ST_ST_RUNNING;
  thread->flags = _ST_FL_PRIMORDIAL;
  _ST_SET_CURRENT_THREAD(thread);
  _st_active_count++;
#ifdef DEBUG
  _ST_ADD_THREADQ(thread);
#endif

  return 0;
}
Ejemplo n.º 2
0
/*
 * Initialize this Virtual Processor
 */
extern "C" int st_init(void)
{
	st_thread_t *thread;

	if (_st_active_count) {
		/* Already initialized */
		return 0;
	}

	if (_st_io_init() < 0)
		return -1;

	memset(&_st_this_vp, 0, sizeof(st_vp_t));

	ST_INIT_CLIST(&_ST_RUNQ);
	ST_INIT_CLIST(&_ST_IOQ);
	ST_INIT_CLIST(&_ST_SLEEPQ);
	ST_INIT_CLIST(&_ST_ZOMBIEQ);

	_st_this_vp.maxfd = -1;
	_st_this_vp.pagesize = getpagesize();
	_st_this_vp.last_clock = st_utime();

	/*
	 * Create idle thread
	 */
	_st_this_vp.idle_thread = st_thread_create(_st_idle_thread_start,
		NULL, 0, 0);
	if (!_st_this_vp.idle_thread)
		return -1;
	_st_this_vp.idle_thread->flags = _ST_FL_IDLE_THREAD;
	_st_active_count--;
	_ST_DEL_RUNQ(_st_this_vp.idle_thread);

	/*
	 * Initialize primordial thread
	 */
	thread = (st_thread_t *)calloc(1, sizeof(st_thread_t)+
		(ST_KEYS_MAX * sizeof(void *)));
	if (!thread)
		return -1;
	thread->private_data = (void **)(thread + 1);
	thread->state = _ST_ST_RUNNING;
	thread->flags = _ST_FL_PRIMORDIAL;
	_ST_SET_CURRENT_THREAD(thread);
	_st_active_count++;

	_st_notify_event = CreateEvent(NULL, TRUE, FALSE, NULL);
	_st_semaphore		 = CreateSemaphore(NULL, 0, 10,NULL);
	return 0;
}