From 53c86913b72c70fa65c0912beacc8e1fe82a8331 Mon Sep 17 00:00:00 2001 From: David Anderson Date: Tue, 26 Oct 2004 21:12:00 +0000 Subject: [PATCH] *** empty log message *** svn path=/trunk/boinc/; revision=4437 --- api/boinc_api.C | 20 +++++++++++--------- api/boinc_api.h | 6 ++++-- api/graphics_api.C | 14 ++++++++++++-- api/graphics_api.h | 5 +++++ checkin_notes | 11 ++++------- 5 files changed, 36 insertions(+), 20 deletions(-) diff --git a/api/boinc_api.C b/api/boinc_api.C index c6ed9edda7..4ecff8e5ca 100644 --- a/api/boinc_api.C +++ b/api/boinc_api.C @@ -53,7 +53,7 @@ using namespace std; #include "filesys.h" #include "error_numbers.h" #include "app_ipc.h" -#include "graphics_api.h" + #include "boinc_api.h" // The BOINC API communicates CPU time and fraction done to the core client. @@ -109,7 +109,7 @@ static int mem_usage(unsigned long& vm_kb, unsigned long& rs_kb); static BOINC_OPTIONS options; static BOINC_STATUS boinc_status; -int boinc_init(void (*worker)()) { +void BOINC_OPTIONS::defaults() { options.main_program = true; options.check_heartbeat = true; options.handle_trickle_ups = true; @@ -117,10 +117,16 @@ int boinc_init(void (*worker)()) { options.handle_process_control = true; options.send_status_msgs = true; options.direct_process_action = true; - return boinc_init_options(options, worker); } -int boinc_init_options(BOINC_OPTIONS& opt, void (*worker)()) { +// this is called ONLY by the worker thread +// +int boinc_init() { + options.defaults(); + return boinc_init_options(options); +} + +int boinc_init_options(BOINC_OPTIONS& opt) { int retval; options = opt; @@ -187,11 +193,7 @@ int boinc_init_options(BOINC_OPTIONS& opt, void (*worker)()) { heartbeat_active = !standalone; heartbeat_giveup_time = dtime() + HEARTBEAT_GIVEUP_PERIOD; - if (worker) { - boinc_init_graphics(worker); - } else { - set_worker_timer(); - } + set_worker_timer(); return 0; } diff --git a/api/boinc_api.h b/api/boinc_api.h index 7b47879740..925a0d132d 100755 --- a/api/boinc_api.h +++ b/api/boinc_api.h @@ -45,6 +45,8 @@ struct BOINC_OPTIONS { // if heartbeat fail, or get process control msg, take // direction action (exit, suspend, resume). // Otherwise just set flag in BOINC status + + void defaults(); }; struct BOINC_STATUS { @@ -54,8 +56,8 @@ struct BOINC_STATUS { }; extern "C" { - extern int boinc_init(void (*worker)()=0); - extern int boinc_init_options(BOINC_OPTIONS&, void (*worker)()=0); + extern int boinc_init(); + extern int boinc_init_options(BOINC_OPTIONS&); extern int boinc_finish(int status); extern int boinc_get_status(BOINC_STATUS&); extern bool boinc_is_standalone(); diff --git a/api/graphics_api.C b/api/graphics_api.C index 103a4582e5..9bbfb9ebcb 100755 --- a/api/graphics_api.C +++ b/api/graphics_api.C @@ -62,22 +62,32 @@ bool graphics_inited = false; static void (*worker_main)(); +static BOINC_OPTIONS goptions; + #ifdef _WIN32 // glue routine for Windows DWORD WINAPI foobar(LPVOID) { + boinc_init_options(goptions); worker_main(); return 0; } #endif #ifdef _PTHREAD_H void* foobar(void*) { - set_timer(); + boinc_init_options(goptions); worker_main(); return 0; } #endif -int boinc_init_graphics(void (*_worker_main)()) { +int boinc_init_graphics(void (*worker)()) { + BOINC_OPTIONS opt; + opt.defaults(); + boinc_init_options_graphics(opt, worker); +} + +int boinc_init_graphics_options(BOINC_OPTIONS& opt, void (*_worker_main)()) { + goptions = opt; worker_main = _worker_main; #ifdef _WIN32 diff --git a/api/graphics_api.h b/api/graphics_api.h index 9ab19780bb..160f62fc8f 100755 --- a/api/graphics_api.h +++ b/api/graphics_api.h @@ -1,6 +1,11 @@ #ifndef BOINC_GRAPHICS_API_H #define BOINC_GRAPHICS_API_H +extern "C" { + extern int boinc_init_graphics(void (*worker)()); + extern int boinc_init_options_graphics(BOINC_OPTIONS&, void (*worker)()); +} + // Functions that must be supplied by the app // application needs to define mouse, keyboard handlers // diff --git a/checkin_notes b/checkin_notes index 91f4ba7d67..6b112abe91 100755 --- a/checkin_notes +++ b/checkin_notes @@ -18887,13 +18887,10 @@ David 26 Oct 2004 - there doesn't seem to be a way for one thread to get the CPU time of another thread Solution: (unfortunately requires a change to the API): - - got rid of boinc_init_graphics() - - boinc_init() and boinc_init_options() take an - optional void(*worker)() argument. - This is nonzero only if the app does graphics. - This way boinc_init() can set up the timer itself - (in the non-graphics case) or wait for the worker - thread to do it (in the graphics case) + apps that use graphics now call either + boinc_init_graphics() or + boinc_init_options_graphics() + and DON'T call boinc_init() api/ boinc_api.C,h