Esempio n. 1
0
void S_thread_init() {
  if (S_boot_time) {
    S_protect(&S_G.threadno);
    S_G.threadno = FIX(0);

#ifdef PTHREADS
   /* this is also reset in main.c after heap restoration */
    s_thread_mutex_init(&S_tc_mutex.pmutex);
    S_tc_mutex.owner = s_thread_self();
    S_tc_mutex.count = 0;
    s_thread_cond_init(&S_collect_cond);
    S_tc_mutex_depth = 0;
#endif /* PTHREADS */
  }
}
Esempio n. 2
0
int s_eventq_init (s_window_t *window)
{
	window->eventq = (s_eventq_t *) s_calloc(1, sizeof(s_eventq_t));
	window->eventq->queue = (s_list_t *) s_calloc(1, sizeof(s_list_t));
	if (s_thread_cond_init(&window->eventq->cond)) {
		goto err0;
	}
	if (s_thread_mutex_init(&window->eventq->mut)) {
		goto err1;
	}
        return 0;

err1:	s_thread_cond_destroy(window->eventq->cond);
err0:	s_free(window->eventq->queue);
	s_free(window->eventq);
	return 1;
}
Esempio n. 3
0
s_thread_t * s_thread_create (void * (*f) (void *), void *farg)
{
	s_thread_t *tid;
	s_thread_arg_t *arg;

	if ((s_thread_api == NULL) ||
	    (s_thread_api->thread_create == NULL)) {
		return NULL;
	}

	tid = (s_thread_t *) s_malloc(sizeof(s_thread_t));
	arg = (s_thread_arg_t *) s_malloc(sizeof(s_thread_arg_t));

	arg->r = &s_thread_run;
	arg->f = f;
	arg->arg = farg;
	s_thread_cond_init(&arg->cond);
	s_thread_mutex_init(&arg->mut);

	s_thread_mutex_lock(arg->mut);
	arg->flag = 0;
	s_thread_cond_signal(arg->cond);
	s_thread_mutex_unlock(arg->mut);

	s_thread_api->thread_create(tid, arg);

	s_thread_mutex_lock(arg->mut);
	while (arg->flag != 1) 
	{
		if (s_thread_cond_wait(arg->cond, arg->mut)) {
			debugf(DSYS, "s_thread_cond_wait failed");
			return NULL;
		}
	}
	s_thread_mutex_unlock(arg->mut);

	s_thread_cond_destroy(arg->cond);
	s_thread_mutex_destroy(arg->mut);
	s_free(arg);
	arg = NULL;

	return tid;
}