int
main()
{
	unsigned int i, repeat;
	unsigned int num_threads = sizeof(testfiles) / sizeof(testfiles[0]);
	DWORD results[MAX_ARGC];
	BOOL ret;

	xmlInitParser();
	for (repeat = 0;repeat < TEST_REPEAT_COUNT;repeat++)
	{
		xmlLoadCatalog(catalog);

		for (i = 0; i < num_threads; i++)
		{
			results[i] = 0;
			tid[i] = (HANDLE) -1;
		}

		for (i = 0; i < num_threads; i++)
		{
			DWORD useless;
			tid[i] = CreateThread(NULL, 0,
				thread_specific_data, testfiles[i], 0, &useless);
			if (tid[i] == NULL)
			{
				perror("CreateThread");
				exit(1);
			}
		}

		if (WaitForMultipleObjects (num_threads, tid, TRUE, INFINITE) == WAIT_FAILED)
			perror ("WaitForMultipleObjects failed");

		for (i = 0; i < num_threads; i++)
		{
			ret = GetExitCodeThread (tid[i], &results[i]);
			if (ret == 0)
			{
				perror("GetExitCodeThread");
				exit(1);
			}
			CloseHandle (tid[i]);
		}

		xmlCatalogCleanup();
		for (i = 0; i < num_threads; i++) {
		    if (results[i] != (DWORD) Okay)
			printf("Thread %d handling %s failed\n", i, testfiles[i]);
		}
	}

	xmlCleanupParser();
	xmlMemoryDump();

	return (0);
}
Exemplo n.º 2
0
int
main(void)
{
    unsigned int i, repeat;
    unsigned int num_threads = sizeof(testfiles) / sizeof(testfiles[0]);
    void *results[MAX_ARGC];
    status_t ret;

    xmlInitParser();
    printf("Parser initialized\n");
    for (repeat = 0;repeat < 500;repeat++) {
    printf("repeat: %d\n",repeat);
	xmlLoadCatalog(catalog);
	printf("loaded catalog: %s\n", catalog);
	for (i = 0; i < num_threads; i++) {
	    results[i] = NULL;
	    tid[i] = (thread_id) -1;
	}
	printf("cleaned threads\n");
	for (i = 0; i < num_threads; i++) {
		tid[i] = spawn_thread(thread_specific_data, "xmlTestThread", B_NORMAL_PRIORITY, (void *) testfiles[i]);
		if (tid[i] < B_OK) {
			perror("beos_thread_create");
			exit(1);
		}
		printf("beos_thread_create %d -> %d\n", i, tid[i]);
	}
	for (i = 0; i < num_threads; i++) {
	    ret = wait_for_thread(tid[i], &results[i]);
	    printf("beos_thread_wait %d -> %d\n", i, ret);
	    if (ret != B_OK) {
			perror("beos_thread_wait");
			exit(1);
	    }
	}

	xmlCatalogCleanup();
	ret = B_OK;
	for (i = 0; i < num_threads; i++)
	    if (results[i] != (void *) Okay) {
			printf("Thread %d handling %s failed\n", i, testfiles[i]);
			ret = B_ERROR;
		}
    }
    xmlCleanupParser();
    xmlMemoryDump();

	if (ret == B_OK)
		printf("testThread : BeOS : SUCCESS!\n");
	else
		printf("testThread : BeOS : FAILED!\n");

    return (0);
}
Exemplo n.º 3
0
int
main(void)
{
    unsigned int i, repeat;
    unsigned int num_threads = sizeof(testfiles) / sizeof(testfiles[0]);
    void *results[MAX_ARGC];
    int ret;

    xmlInitParser();
    for (repeat = 0;repeat < 500;repeat++) {
	xmlLoadCatalog(catalog);

	for (i = 0; i < num_threads; i++) {
	    results[i] = NULL;
	    tid[i] = (pthread_t) -1;
	}

	for (i = 0; i < num_threads; i++) {
	    ret = pthread_create(&tid[i], NULL, thread_specific_data,
				 (void *) testfiles[i]);
	    if (ret != 0) {
		perror("pthread_create");
		exit(1);
	    }
	}
	for (i = 0; i < num_threads; i++) {
	    ret = pthread_join(tid[i], &results[i]);
	    if (ret != 0) {
		perror("pthread_join");
		exit(1);
	    }
	}

	xmlCatalogCleanup();
	for (i = 0; i < num_threads; i++)
	    if (results[i] != (void *) Okay)
		printf("Thread %d handling %s failed\n", i, testfiles[i]);
    }
    xmlCleanupParser();
    xmlMemoryDump();
    return (0);
}
Exemplo n.º 4
0
/*
Global functions
----------------
*/

#if defined (WX_USER_INTERFACE)

bool wxCmguiApp::OnInit()
{
	return (true);
}

wxAppTraits * wxCmguiApp::CreateTraits()
{
	return new wxGUIAppTraits;
}

void wxCmguiApp::OnIdle(wxIdleEvent& event)
{
	if (event_dispatcher)
	{
		if (Event_dispatcher_process_idle_event(event_dispatcher))
		{
			event.RequestMore();
		}
	}
}

void wxCmguiApp::SetEventDispatcher(Event_dispatcher *event_dispatcher_in)
{
	event_dispatcher = event_dispatcher_in;
}

BEGIN_EVENT_TABLE(wxCmguiApp, wxApp)
	EVT_IDLE(wxCmguiApp::OnIdle)
END_EVENT_TABLE()

IMPLEMENT_APP_NO_MAIN(wxCmguiApp)

#endif /*defined (WX_USER_INTERFACE)*/

#if !defined (WIN32_USER_INTERFACE) && !defined (_MSC_VER)
int main(int argc,const char *argv[])
#else /* !defined (WIN32_USER_INTERFACE)  && !defined (_MSC_VER)*/
int WINAPI WinMain(HINSTANCE current_instance,HINSTANCE previous_instance,
	LPSTR command_line,int initial_main_window_state)
	/* using WinMain as the entry point tells Windows that it is a gui and to use
		the graphics device interface functions for I/O */
	/*???DB.  WINDOWS a zero return code if WinMain does get into the message
		loop.  Other application interfaces may expect something else.  Should this
		failure code be #define'd ? */
	/*???DB. Win32 SDK says that don't have to call it WinMain */
#endif /* !defined (WIN32_USER_INTERFACE)  && !defined (_MSC_VER)*/
/*******************************************************************************
LAST MODIFIED : 7 January 2003

DESCRIPTION :
Main program for the CMISS Graphical User Interface
==============================================================================*/
{
	int return_code = 0;
#if defined (WIN32_USER_INTERFACE) || defined (_MSC_VER)
	int argc = 1, i;
	const char **argv;
	char *p, *q;
#endif /* defined (WIN32_USER_INTERFACE) */
	struct Cmiss_context_app *context = NULL;
	struct User_interface_module *UI_module = NULL;
	struct Cmiss_command_data *command_data;

#if !defined (WIN32_USER_INTERFACE) && !defined (_MSC_VER)
	ENTER(main);
#else /* !defined (WIN32_USER_INTERFACE)  && !defined (_MSC_VER)*/
	ENTER(WinMain);

	//_CrtSetBreakAlloc(28336);
	for (p = command_line; p != NULL && *p != 0;)
	{
		p = strchr(p, ' ');
		if (p != NULL)
			p++;
		argc++;
	}

	argv = (const char **)malloc(sizeof(*argv) * argc);

	argv[0] = "cmgui";

	for (i = 1, p = command_line; p != NULL && *p != 0;)
	{
		q = strchr(p, ' ');
		if (q != NULL)
			*q++ = 0;
		if (p != NULL)
			argv[i++] = p;
		p = q;
	}
#endif /* !defined (WIN32_USER_INTERFACE)  && !defined (_MSC_VER)*/

	/* display the version */
	display_message(INFORMATION_MESSAGE, "%s version %s\n%s\n"
		"Build information: %s %s\n", CMISS_NAME_STRING, CMISS_VERSION_STRING,
		CMISS_COPYRIGHT_STRING, CMISS_BUILD_STRING,
		CMISS_SVN_REVISION_STRING);

#if defined (CARBON_USER_INTERFACE) || (defined (WX_USER_INTERFACE) && defined (DARWIN))
	ProcessSerialNumber PSN;
	GetCurrentProcess(&PSN);
	TransformProcessType(&PSN,kProcessTransformToForegroundApplication);
#endif
	context = Cmiss_context_app_create("default");
#if defined (WX_USER_INTERFACE)
	int wx_entry_started = 0;
#endif
	if (context)
	{
#if defined (WX_USER_INTERFACE) || (!defined (WIN32_USER_INTERFACE) && !defined (_MSC_VER))
		UI_module = Cmiss_context_create_user_interface(context, argc, argv, NULL);
#else /* !defined (WIN32_USER_INTERFACE)  && !defined (_MSC_VER)*/
		UI_module = Cmiss_context_create_user_interface(context, argc, argv, current_instance,
			previous_instance, command_line, initial_main_window_state, NULL);
#endif /* !defined (WIN32_USER_INTERFACE)  && !defined (_MSC_VER)*/
		if (UI_module)
		{
#if defined (WX_USER_INTERFACE)
			if (UI_module->user_interface)
			{
				char **temp_argv = NULL, **cleanup_argv = NULL;
				int temp_argc = argc, cleanup_argc = argc;
				if (cleanup_argc > 0)
				{
					ALLOCATE(temp_argv, char *, cleanup_argc);
					ALLOCATE(cleanup_argv, char *, cleanup_argc);
					for (int i = 0; i < cleanup_argc; i++)
					{
						cleanup_argv[i] = temp_argv[i] = duplicate_string(argv[i]);
					}
				}
				if (wxEntryStart(temp_argc, temp_argv))
				{
					wx_entry_started = 1;
					wxXmlResource::Get()->InitAllHandlers();
					wxCmguiApp &app = wxGetApp();
					if (&app)
					{
						app.SetEventDispatcher(UI_module->event_dispatcher);
					}
					else
					{
						display_message(ERROR_MESSAGE,
							"initialiseWxApp.  wxCmguiApp not initialised.");
					}
				}
				else
				{
					display_message(ERROR_MESSAGE,
						"initialiseWxApp.  Invalid arguments.");
				}
				if (cleanup_argv)
				{
					for (int i = 0; i < cleanup_argc; i++)
					{
						DEALLOCATE(cleanup_argv[i]);
					}
					DEALLOCATE(temp_argv);
					DEALLOCATE(cleanup_argv);
				}
			}
#endif
			Cmiss_graphics_module_id graphics_module = NULL;
			if (NULL != (graphics_module = Cmiss_context_get_default_graphics_module(Cmiss_context_app_get_core_context(context))))
			{
				Cmiss_graphics_module_define_standard_materials(graphics_module);
				Cmiss_graphics_module_destroy(&graphics_module);
			}
			if (NULL != (command_data = Cmiss_context_get_default_command_interpreter(context)))
			{
				Cmiss_command_data_set_cmgui_string(command_data, CMISS_NAME_STRING,
					CMISS_VERSION_STRING, "CMISS_DATE_STRING", CMISS_COPYRIGHT_STRING, CMISS_BUILD_STRING,
					CMISS_SVN_REVISION_STRING);
				Cmiss_command_data_main_loop(command_data);
				Cmiss_command_data_destroy(&command_data);
				return_code = 0;
			}
			else
			{
				return_code = 1;
			}
			User_interface_module_destroy(&UI_module);
		}
		else
		{
			return_code = 1;
		}
		Cmiss_context_app_destroy(&context);
		Context_internal_cleanup();
#if defined (WX_USER_INTERFACE)
		if (wx_entry_started)
			wxEntryCleanup();
#endif
		/* FieldML does not cleanup the global varaibles xmlParser, xmlSchematypes and
		 * xmlCatalog at this moment, so we clean it up here instead*/
		xmlCatalogCleanup();
		xmlSchemaCleanupTypes();
		xmlCleanupParser();
	}
	else
	{
		return_code = 1;
	}
#if defined (WIN32_USER_INTERFACE) || defined (_MSC_VER)
	free(argv)
#endif
	LEAVE;

	return (return_code);
} /* main */