*** empty log message ***

svn path=/trunk/boinc/; revision=4437
This commit is contained in:
David Anderson 2004-10-26 21:12:00 +00:00
parent d3a451be19
commit 53c86913b7
5 changed files with 36 additions and 20 deletions

View File

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

View File

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

View File

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

View File

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

View File

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