From 62c59a93cde1913a4dbb37b2eea13bd8c22577f0 Mon Sep 17 00:00:00 2001 From: David Anderson Date: Mon, 11 Oct 2004 23:57:07 +0000 Subject: [PATCH] *** empty log message *** svn path=/trunk/boinc/; revision=4316 --- api/graphics_api.C | 75 +++++++++++++++++++++----------------------- api/graphics_api.h | 2 +- api/windows_opengl.C | 5 ++- checkin_notes | 25 +++++++++++++++ client/app_start.C | 18 ----------- lib/app_ipc.C | 28 ----------------- lib/app_ipc.h | 1 - lib/prefs.C | 4 --- 8 files changed, 63 insertions(+), 95 deletions(-) diff --git a/api/graphics_api.C b/api/graphics_api.C index e4cb5fd69f..9dcb466ae1 100755 --- a/api/graphics_api.C +++ b/api/graphics_api.C @@ -24,8 +24,8 @@ #ifdef _WIN32 #include "boinc_win.h" -extern DWORD WINAPI win_graphics_event_loop( LPVOID duff ); -HANDLE graphics_threadh=NULL; +extern void win_graphics_event_loop(); +HANDLE worker_threadh=NULL; #endif #ifdef __APPLE_CC__ @@ -58,29 +58,18 @@ double boinc_max_gfx_cpu_frac = 0.5; HANDLE hQuitEvent; #endif -GRAPHICS_INFO gi; bool graphics_inited = false; -int boinc_init_graphics() { - FILE* f; - int retval; - - f = boinc_fopen(GRAPHICS_DATA_FILE, "r"); - if (!f) { - fprintf(stderr, "boinc_init_graphics(): can't open graphics data file\n"); - fprintf(stderr, "boinc_init_graphics(): Using default graphics settings.\n"); - gi.refresh_period = 0.1; // 1/10th of a second - gi.xsize = 640; - gi.ysize = 480; - } else { - retval = parse_graphics_file(f, &gi); - if (retval) { - fprintf(stderr, "boinc_init_graphics(): can't parse graphics data file\n"); - return retval; - } - fclose(f); - } +#ifdef _WIN32 +// glue routine for Windows +DWORD WINAPI foobar(LPVOID foo) { + void (*w)() = (void (*)()) foo; + w(); + return 0; +} +#endif +int boinc_init_graphics(void (*worker_main)()) { #ifdef _WIN32 // Create the event object used to signal between the @@ -98,30 +87,33 @@ int boinc_init_graphics() { // Create the graphics thread, passing it the graphics info // TODO: is it better to use _beginthreadex here? // - graphics_threadh = CreateThread( - NULL, 0, win_graphics_event_loop, &gi, CREATE_SUSPENDED, &threadId + worker_threadh = CreateThread( + NULL, 0, foobar, worker_main, CREATE_SUSPENDED, &threadId ); - // lower priority of worker thread (i.e. current thread) + // raise priority of graphics thread (i.e. current thread) // HANDLE h = GetCurrentThread(); - SetThreadPriority(h, THREAD_PRIORITY_LOWEST); + SetThreadPriority(h, THREAD_PRIORITY_HIGHEST); - // Raise graphics thread priority + // lower worker thread priority // - SetThreadPriority(graphics_threadh, THREAD_PRIORITY_HIGHEST); + SetThreadPriority(worker_threadh, THREAD_PRIORITY_LOWEST); - // Start the graphics thread + // Start the worker thread // - ResumeThread(graphics_threadh); + ResumeThread(worker_threadh); + + graphics_inited = true; + win_graphics_event_loop(); #endif #ifdef __APPLE_CC__ OSErr theErr = noErr; - ThreadID graphicsThreadID = 0; + ThreadID workerThreadID = 0; ThreadEntryUPP entry_proc; - entry_proc = NewThreadEntryUPP( mac_graphics_event_loop ); + entry_proc = NewThreadEntryUPP( worker_main ); // Create the thread in a suspended state theErr = NewThread ( kCooperativeThread, entry_proc, @@ -132,23 +124,26 @@ int boinc_init_graphics() { // In theory we could do customized scheduling or install thread disposal routines here // Put the graphics event loop into the ready state - SetThreadState(graphicsThreadID, kReadyThreadState, kNoThreadID); + SetThreadState(workerThreadID, kReadyThreadState, kNoThreadID); YieldToAnyThread(); + mac_graphics_event_loop(); + graphics_inited = true; #endif #ifdef _PTHREAD_H - pthread_t graphics_thread; - pthread_attr_t graphics_thread_attr; + pthread_t worker_thread; + pthread_attr_t worker_thread_attr; - pthread_attr_init( &graphics_thread_attr ); - retval = pthread_create( &graphics_thread, &graphics_thread_attr, xwin_graphics_event_loop, &gi ); + pthread_attr_init( &worker_thread_attr ); + retval = pthread_create( &worker_thread, &worker_thread_attr, worker_main, &gi ); if (retval) return ERR_THREAD; - pthread_attr_destroy( &graphics_thread_attr ); + pthread_attr_destroy( &worker_thread_attr ); + graphics_inited = true; + xwin_graphics_event_loop(); #endif - graphics_inited = true; - + // normally we never get here return 0; } diff --git a/api/graphics_api.h b/api/graphics_api.h index 4cb903773f..cf5eb88bb3 100755 --- a/api/graphics_api.h +++ b/api/graphics_api.h @@ -4,7 +4,7 @@ // The API (functions called by the app) extern "C"{ -extern int boinc_init_graphics(); +extern int boinc_init_graphics(void (*worker)()); extern int boinc_finish_graphics(); } diff --git a/api/windows_opengl.C b/api/windows_opengl.C index 0ec72ef35b..42372cd19b 100755 --- a/api/windows_opengl.C +++ b/api/windows_opengl.C @@ -346,7 +346,7 @@ static VOID CALLBACK timer_handler(HWND, UINT, UINT, DWORD) { } } -DWORD WINAPI win_graphics_event_loop( LPVOID gi ) { +void win_graphics_event_loop() { MSG msg; // Windows Message Structure m_uEndSSMsg = RegisterWindowMessage(STOP_SS_MSG); @@ -372,8 +372,7 @@ DWORD WINAPI win_graphics_event_loop( LPVOID gi ) { unreg_win_class(); - SetEvent(hQuitEvent); // Signal to the worker thread that we're quitting - return (DWORD)msg.wParam; // Exit The thread + SetEvent(hQuitEvent); // Signal the worker thread that we're quitting } static inline bool osIsNT() diff --git a/checkin_notes b/checkin_notes index 8112837fe8..4bd33bb35a 100755 --- a/checkin_notes +++ b/checkin_notes @@ -18258,3 +18258,28 @@ David 10 Oct 2004 client/ client_types.C gui_rpc_server.C + +David 11 Oct 2004 + - changed the graphics API to support Mac OS/X + (in which only the original thread can do GUI stuff). + boinc_init_graphics() now takes a function-pointer arg + for the worker function; it runs this function in a new thread, + and the calling thread does the GUI event loop. + + Did this for Windows, and attempted to make the same changes + in the Mac and X11 code. May or may not work. + + - got rid of everything related to the GRAPHICS_INFO structure. + This wasn't being used. + + NOTE: this change doesn't affect the core/app interface. + No need to recompile existing apps. + + api/ + graphics_api.C,h + windows_opengl.C + client/ + app_start.C + lib/ + app_ipc.C,h + prefs.C diff --git a/client/app_start.C b/client/app_start.C index 5971a954f7..b6ae6b514a 100644 --- a/client/app_start.C +++ b/client/app_start.C @@ -233,8 +233,6 @@ int ACTIVE_TASK::start(bool first_time) { FILE_REF fref; FILE_INFO* fip; int retval; - char graphics_data_path[256]; - GRAPHICS_INFO gi; SCOPE_MSG_LOG scope_messages(log_messages, CLIENT_MSG_LOG::DEBUG_TASK); scope_messages.printf("ACTIVE_TASK::start(first_time=%d)\n", first_time); @@ -247,10 +245,6 @@ int ACTIVE_TASK::start(bool first_time) { cpu_time_at_last_sched = checkpoint_cpu_time; fraction_done = 0; - gi.xsize = 800; - gi.ysize = 600; - gi.refresh_period = 0.1; - if (!app_client_shm.shm) { retval = get_shmem_seg_name(); if (retval) { @@ -264,18 +258,6 @@ int ACTIVE_TASK::start(bool first_time) { retval = write_app_init_file(); if (retval) return retval; - sprintf(graphics_data_path, "%s%s%s", slot_dir, PATH_SEPARATOR, GRAPHICS_DATA_FILE); - FILE* gf = boinc_fopen(graphics_data_path, "w"); - if (!gf) { - msg_printf(wup->project, MSG_ERROR, - "Failed to open core-to-app graphics prefs file %s", - graphics_data_path - ); - return ERR_FOPEN; - } - retval = write_graphics_file(gf, &gi); - fclose(gf); - // set up applications files // for (i=0; iapp_files.size(); i++) { diff --git a/lib/app_ipc.C b/lib/app_ipc.C index 9849ba3343..3b0a116f56 100755 --- a/lib/app_ipc.C +++ b/lib/app_ipc.C @@ -203,34 +203,6 @@ void APP_CLIENT_SHM::reset_msgs() { memset(shm, 0, sizeof(SHARED_MEM)); } -int write_graphics_file(FILE* f, GRAPHICS_INFO* gi) { - fprintf(f, - "\n" - " %d\n" - " %d\n" - " %f\n" - "\n", - gi->xsize, - gi->ysize, - gi->refresh_period - ); - - return 0; -} - -int parse_graphics_file(FILE* f, GRAPHICS_INFO* gi) { - char buf[256]; - while (fgets(buf, 256, f)) { - if (match_tag(buf, "")) continue; - if (match_tag(buf, "")) return 0; - else if (parse_int(buf, "", gi->xsize)) continue; - else if (parse_int(buf, "", gi->ysize)) continue; - else if (parse_double(buf, "", gi->refresh_period)) continue; - else fprintf(stderr, "parse_graphics_file: unrecognized %s", buf); - } - return ERR_XML_PARSE; -} - // create a file (new_link) which contains an XML // reference to existing file. // diff --git a/lib/app_ipc.h b/lib/app_ipc.h index 420641f9b4..e1dbf236a0 100755 --- a/lib/app_ipc.h +++ b/lib/app_ipc.h @@ -193,7 +193,6 @@ int parse_graphics_file(FILE* f, GRAPHICS_INFO* gi); // filenames used in the slot directory // #define INIT_DATA_FILE "init_data.xml" -#define GRAPHICS_DATA_FILE "graphics.xml" #define BOINC_FINISH_CALLED_FILE "boinc_finish_called" #define TRICKLE_UP_FILENAME "trickle_up.xml" #define STDERR_FILE "stderr.txt" diff --git a/lib/prefs.C b/lib/prefs.C index 7ff5b6557e..ac12f3fe93 100644 --- a/lib/prefs.C +++ b/lib/prefs.C @@ -17,7 +17,6 @@ // Contributor(s): // -#include "cpp.h" #ifdef _WIN32 #include "boinc_win.h" @@ -32,9 +31,6 @@ #include "parse.h" #include "error_numbers.h" -#include "file_names.h" - -#include "client_state.h" #include "prefs.h" // The following values determine how the client behaves