Пример #1
0
int sthread_cond_wait(sthread_cond_t *cond, sthread_mutex_t *mutex)
{
	if(cond->cond) {
		__DEBUG_PRINT(("tid %d cond 1 \n", __selftid));
		setup_sync();
		wait_to_enter();
		__DEBUG_PRINT(("tid %d cond 2 \n", __selftid));
//		if(__threadpool[])
		v_next_mutex(mutex->mutex);
		__threadpool[__selftid].mutex = NULL;
		__mvspace_commit();
		__threadpool[__selftid].state = E_STOPPED;
		__threadpool[__selftid].cond = cond->cond;
		
		__DEBUG_PRINT(("tid %d cond 3 \n", __selftid));
		v_next_and_wait();
		__DEBUG_PRINT(("tid %d cond 4 \n", __selftid));

		__mvspace_pull();

		__DEBUG_PRINT(("tid %d cond 5 \n", __selftid));
		wait_sem(cond->cond->locks, __selftid);
		__threadpool[__selftid].mutex = mutex->mutex;
		__DEBUG_PRINT(("tid %d cond 5.5 \n", __selftid));
		wait_sem(mutex->mutex->locks, __selftid);
		__threadpool[__selftid].state = E_NORMAL;

		__DEBUG_PRINT(("tid %d cond 6 \n", __selftid));
		leave_sync();
		return 0;
	}
	return -1;
}
Пример #2
0
int sthread_cond_signal(sthread_cond_t *cond)
{
	if(cond->cond)
	{
		int i;
		__DEBUG_PRINT(("tid %d signal 1 \n", __selftid));
		setup_sync();
		__DEBUG_PRINT(("tid %d signal 2 \n", __selftid));
		wait_to_enter();
		__DEBUG_PRINT(("tid %d signal 3 \n", __selftid));
		__mvspace_commit();
		v_next_and_wait();
		__DEBUG_PRINT(("tid %d signal 3 \n", __selftid));
		__mvspace_pull();

		for(i=0;i<MAXTHREADS;i++)
			post_sem(cond->cond->locks, i);
		__DEBUG_PRINT(("tid %d signal 4 \n", __selftid));

		leave_sync();
		__DEBUG_PRINT(("tid %d signal 5 \n", __selftid));
			
		return 0;
	}
	return -1;
}
Пример #3
0
int sthread_barrier_wait(sthread_barrier_t *barrier)
{
	if(barrier->barrier) {
		setup_sync();
		//setup_barrier_sync(barrier->barrier);
		__DEBUG_PRINT(("tid %d barrier1\n", __selftid));
		wait_to_enter();
		__mvspace_commit();
		__threadpool[__selftid].state = E_STOPPED;
		__threadpool[__selftid].barrier = barrier->barrier;
		__DEBUG_PRINT(("tid %d barrier2\n", __selftid));
		v_next_and_wait();
		setup_barrier_sync(barrier->barrier);
		__sync_fetch_and_add(&(barrier->barrier->num), 1);
		__DEBUG_PRINT(("tid %d barrier3\n", __selftid));
		__mvspace_pull();

		if(barrier->barrier->total == barrier->barrier->num) {
			int i;
			for(i=0;i<MAXTHREADS;i++) {
				if(__threadpool[i].barrier == barrier->barrier)
					__threadpool[i].state = E_NORMAL;
			}
		__DEBUG_PRINT(("tid %d barrier3.5\n", __selftid));
			barrier->barrier->inited = 0;
			post_sem(barrier->barrier->sema, 0);
		}
		__DEBUG_PRINT(("tid %d barrier4\n", __selftid));
		wait_sem(barrier->barrier->sema, 0);
		__DEBUG_PRINT(("tid %d barrier5\n", __selftid));
		post_sem(barrier->barrier->sema, 0);
		__threadpool[__selftid].barrier = NULL;
		__threadpool[__selftid].state = E_NORMAL;

		leave_sync();

		return 0;
	}
	return -1;
}
Пример #4
0
int install_user_gui(GtkWidget *main_window)
{
   int r;
   char user[MAX_PREF_LEN];
   unsigned long user_id;
   const char *svalue;
   long old_user_id;
   char *old_user;

   r = dialog_install_user(GTK_WINDOW(main_window), user, MAX_PREF_LEN, &user_id);
   if (r == DIALOG_SAID_1) {
      /* Temporarily set the user and user ID */
      get_pref(PREF_USER, NULL, &svalue);
      get_pref(PREF_USER_ID, &old_user_id, NULL);
      if (svalue) {
         old_user = strdup(svalue);
      } else {
         old_user = strdup("");
      }

      set_pref(PREF_USER, 0, user, FALSE);
      set_pref(PREF_USER_ID, user_id, NULL, TRUE);

      jp_logf(JP_LOG_DEBUG, "user is %s\n", user);
      jp_logf(JP_LOG_DEBUG, "user id is %ld\n", user_id);
      
      r = setup_sync(SYNC_NO_PLUGINS | SYNC_INSTALL_USER);

      jp_logf(JP_LOG_DEBUG, "old user is %s\n", old_user);
      jp_logf(JP_LOG_DEBUG, "old user id is %ld\n", old_user_id);
      set_pref(PREF_USER, 0, old_user, FALSE);
      set_pref(PREF_USER_ID, old_user_id, NULL, TRUE);
      free(old_user);
      
      return r;
   } 

   return -1;
}