*** empty log message ***

svn path=/trunk/boinc/; revision=4316
This commit is contained in:
David Anderson 2004-10-11 23:57:07 +00:00
parent 2fe4b50060
commit 62c59a93cd
8 changed files with 63 additions and 95 deletions

View File

@ -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;
}

View File

@ -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();
}

View File

@ -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()

View File

@ -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

View File

@ -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; i<app_version->app_files.size(); i++) {

View File

@ -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,
"<graphics_info>\n"
" <graphics_xsize>%d</graphics_xsize>\n"
" <graphics_ysize>%d</graphics_ysize>\n"
" <graphics_refresh_period>%f</graphics_refresh_period>\n"
"</graphics_info>\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, "<graphics_info>")) continue;
if (match_tag(buf, "</graphics_info>")) return 0;
else if (parse_int(buf, "<graphics_xsize>", gi->xsize)) continue;
else if (parse_int(buf, "<graphics_ysize>", gi->ysize)) continue;
else if (parse_double(buf, "<graphics_refresh_period>", 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.
//

View File

@ -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"

View File

@ -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