Пример #1
0
gsi_u32 gsiWaitForSemaphore(GSISemaphoreID theSemaphore, gsi_u32 theTimeoutMs)
{
	gsi_time startTime = current_time();
	gsi_bool infinite = (theTimeoutMs == GSI_INFINITE)?gsi_true:gsi_false;

	do
	{
		if(OS_TryLockMutex(&theSemaphore.mLock) == TRUE)
		{
			if(theSemaphore.mValue > 0)
			{
				theSemaphore.mValue--;
				OS_UnlockMutex(&theSemaphore.mLock);
				return 1;
			}

			OS_UnlockMutex(&theSemaphore.mLock);
		}

		if(theTimeoutMs != 0)
			msleep(2);

	} while(gsi_is_true(infinite) || ((current_time() - startTime) < theTimeoutMs));

	return 0;
}
Пример #2
0
/*
 *	This is where we actually do the stuff in GTK_system_loop.
 */
static gint gtk_idle_handler(gpointer *data)
{
	int ret;

//	g_print("Timer = %d\n", TM_GetTicks());

	OS_LockMutex(&command_mutex);

	while (TM_Ticked) {
		TM_TickHandler(0);
//			TM_Ticked--;
		TM_Ticked = 0;
	}

	ret = v9t9_return = v9t9_execute();
		
	if (ret == em_TooFast) {
#if defined(UNDER_UNIX)		
		unix_system_pause();	
#else
		win32_system_pause();
#endif						
	}
	else if (ret == em_Quitting || ret == em_Dying) {
		gtk_main_quit();
		return FALSE;
	}
	OS_UnlockMutex(&command_mutex);

	// continue to call me...  :)
	return TRUE;
}
Пример #3
0
void
GTK_system_log(u32 srcflags, const gchar *text)
{
	if (LOG_IS_VISIBLE(srcflags)) {
		GTK_append_log(text, NULL, NULL);
	}
	if (LOG_IS_FATAL(srcflags)) {
		GtkWidget *dialog = create_fatal_dialog();
		GtkLabel *label;

		fatal_dialog_button_clicked = 0;

		// set message
		label = gtk_object_get_data(GTK_OBJECT(dialog), "message_label");
		if (label) {
			gtk_label_set_text(label, text);
		}
	   
		// display modal dialog
		gtk_grab_add(dialog);
		gtk_widget_show(dialog);
		
		OS_UnlockMutex(&command_mutex);

		while (!fatal_dialog_button_clicked && VALID_WINDOW(dialog)) 
			gtk_main_iteration();
		if (VALID_WINDOW(dialog))
			gtk_grab_remove(dialog);
	}
}
Пример #4
0
void gsiReleaseSemaphore(GSISemaphoreID theSemaphore, gsi_i32 theReleaseCount)
{
	OS_LockMutex(&theSemaphore.mLock);

	theSemaphore.mValue += theReleaseCount;
	if(theSemaphore.mValue > theSemaphore.mMax)
		theSemaphore.mValue = theSemaphore.mMax;

	OS_UnlockMutex(&theSemaphore.mLock);
}
Пример #5
0
/*	
 *	Send a command to V9t9
 */
void
GTK_send_command(const gchar *text)
{
	GdkColor red = { 0, 0x8000, 0x0000, 0x0000 };

	GTK_append_log(text, &red, NULL);
	GTK_append_log("\n", &red, NULL);

	OS_LockMutex(&command_mutex);
	command_exec_text((char *)text);
	OS_UnlockMutex(&command_mutex);
}
Пример #6
0
void gsiLeaveCriticalSection(GSICriticalSection *theCrit)
{
	OS_UnlockMutex(theCrit);
}