mirror of https://github.com/BOINC/boinc.git
cleaned up suspend code
svn path=/trunk/boinc/; revision=986
This commit is contained in:
parent
b1b4e82594
commit
cb0efeade7
|
@ -88,14 +88,14 @@ GRAPHICS_INFO gi;
|
|||
static double timer_period = 1.0/50.0; // 50 Hz timer
|
||||
static double time_until_checkpoint;
|
||||
static double time_until_fraction_done_update;
|
||||
static double time_until_suspend_check;
|
||||
static double time_until_quit_check;
|
||||
static double fraction_done;
|
||||
static double last_checkpoint_cpu_time;
|
||||
static bool ready_to_checkpoint = false;
|
||||
static bool check_susp_quit = false;
|
||||
static bool check_quit = false;
|
||||
static bool write_frac_done = false;
|
||||
static bool this_process_active;
|
||||
static bool time_to_suspend = false,time_to_quit = false;
|
||||
static bool time_to_quit = false;
|
||||
bool using_opengl = false;
|
||||
|
||||
// read the INIT_DATA and FD_INIT files
|
||||
|
@ -161,7 +161,7 @@ int boinc_init() {
|
|||
#endif
|
||||
time_until_checkpoint = aid.checkpoint_period;
|
||||
time_until_fraction_done_update = aid.fraction_done_update_period;
|
||||
time_until_suspend_check = 1; // check every 1 second for suspend request from core client
|
||||
time_until_quit_check = 1; // check every 1 second for quit request from core client
|
||||
this_process_active = true;
|
||||
|
||||
boinc_install_signal_handlers();
|
||||
|
@ -306,14 +306,14 @@ int boinc_resolve_filename(char *virtual_name, char *physical_name, int len) {
|
|||
}
|
||||
|
||||
bool boinc_time_to_checkpoint() {
|
||||
if (check_susp_quit) {
|
||||
FILE* f = fopen(SUSPEND_QUIT_FILE, "r");
|
||||
if (check_quit) {
|
||||
FILE* f = fopen(QUIT_FILE, "r");
|
||||
if(f) {
|
||||
parse_suspend_quit_file(f,time_to_suspend,time_to_quit);
|
||||
parse_quit_file(f,time_to_quit);
|
||||
fclose(f);
|
||||
}
|
||||
time_until_suspend_check = 1; // reset to 1 second
|
||||
check_susp_quit = false;
|
||||
time_until_quit_check = 1; // reset to 1 second
|
||||
check_quit = false;
|
||||
}
|
||||
|
||||
if (write_frac_done) {
|
||||
|
@ -322,9 +322,9 @@ bool boinc_time_to_checkpoint() {
|
|||
write_frac_done = false;
|
||||
}
|
||||
|
||||
// If the application has received a quit or suspend request
|
||||
// it should checkpoint
|
||||
if (time_to_quit || time_to_suspend) {
|
||||
// If the application has received a quit request it should checkpoint
|
||||
//
|
||||
if (time_to_quit) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -341,20 +341,6 @@ int boinc_checkpoint_completed() {
|
|||
if (time_to_quit) {
|
||||
boinc_finish(ERR_QUIT_REQUEST);
|
||||
}
|
||||
// If we're in a suspended state, sleep until instructed otherwise
|
||||
while (time_to_suspend) {
|
||||
if (time_to_quit) {
|
||||
boinc_finish(ERR_QUIT_REQUEST);
|
||||
}
|
||||
boinc_sleep(1); // Should this be a smaller value?
|
||||
FILE* f = fopen(SUSPEND_QUIT_FILE, "r");
|
||||
if(f) {
|
||||
parse_suspend_quit_file(f,time_to_suspend,time_to_quit);
|
||||
fclose(f);
|
||||
} else {
|
||||
time_to_suspend = time_to_quit = false;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -449,10 +435,10 @@ void on_timer(int a) {
|
|||
}
|
||||
}
|
||||
|
||||
if (!check_susp_quit) {
|
||||
time_until_suspend_check -= timer_period;
|
||||
if (time_until_suspend_check <= 0) {
|
||||
check_susp_quit = true;
|
||||
if (!check_quit) {
|
||||
time_until_quit_check -= timer_period;
|
||||
if (time_until_quit_check <= 0) {
|
||||
check_quit = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -575,8 +561,7 @@ int parse_init_data_file(FILE* f, APP_INIT_DATA& ai) {
|
|||
int write_fraction_done_file(double pct, double cpu, double checkpoint_cpu) {
|
||||
FILE* f = fopen(FRACTION_DONE_TEMP_FILE, "w");
|
||||
|
||||
if (!f)
|
||||
return -1;
|
||||
if (!f) return -1;
|
||||
|
||||
fprintf(f,
|
||||
"<fraction_done>%f</fraction_done>\n"
|
||||
|
@ -607,23 +592,17 @@ int parse_fraction_done_file(FILE* f, double& pct, double& cpu, double& checkpoi
|
|||
return 0;
|
||||
}
|
||||
|
||||
int write_suspend_quit_file(FILE* f, bool suspend, bool quit) {
|
||||
if (suspend) {
|
||||
fprintf(f, "<suspend/>\n");
|
||||
}
|
||||
if (quit) {
|
||||
fprintf(f, "<quit/>\n");
|
||||
}
|
||||
int write_quit_file(FILE* f) {
|
||||
fprintf(f, "<quit/>\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
int parse_suspend_quit_file(FILE* f, bool& suspend, bool& quit) {
|
||||
int parse_quit_file(FILE* f, bool& quit) {
|
||||
char buf[256];
|
||||
|
||||
while (fgets(buf, 256, f)) {
|
||||
if (match_tag(buf, "<suspend/>")) suspend = true;
|
||||
else if (match_tag(buf, "<quit/>")) quit = true;
|
||||
else fprintf(stderr, "parse_suspend_quit_file: unrecognized %s", buf);
|
||||
if (match_tag(buf, "<quit/>")) quit = true;
|
||||
else fprintf(stderr, "parse_quit_file: unrecognized %s", buf);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -84,15 +84,15 @@ int write_fd_init_file(FILE*, char*, int, int);
|
|||
int parse_fd_init_file(FILE*);
|
||||
int write_fraction_done_file(double, double, double);
|
||||
int parse_fraction_done_file(FILE*, double&, double&, double&);
|
||||
int write_suspend_quit_file(FILE* f, bool suspend, bool quit);
|
||||
int parse_suspend_quit_file(FILE* f, bool& suspend, bool& quit);
|
||||
int write_quit_file(FILE* f);
|
||||
int parse_quit_file(FILE* f, bool& quit);
|
||||
|
||||
#define INIT_DATA_FILE "init_data.xml"
|
||||
#define GRAPHICS_DATA_FILE "graphics.xml"
|
||||
#define FD_INIT_FILE "fd_init.xml"
|
||||
#define FRACTION_DONE_FILE "fraction_done.xml"
|
||||
#define FRACTION_DONE_TEMP_FILE "fraction_done.tmp"
|
||||
#define SUSPEND_QUIT_FILE "suspend.xml"
|
||||
#define QUIT_FILE "quit.xml"
|
||||
#define STDERR_FILE "stderr.txt"
|
||||
|
||||
int set_timer(double period);
|
||||
|
|
14
client/app.C
14
client/app.C
|
@ -262,7 +262,7 @@ int ACTIVE_TASK::start(bool first_time) {
|
|||
|
||||
fclose(f);
|
||||
|
||||
sprintf(temp, "%s%s%s", slot_dir, PATH_SEPARATOR, SUSPEND_QUIT_FILE);
|
||||
sprintf(temp, "%s%s%s", slot_dir, PATH_SEPARATOR, QUIT_FILE);
|
||||
file_delete(temp);
|
||||
|
||||
#ifdef _WIN32
|
||||
|
@ -356,13 +356,13 @@ int ACTIVE_TASK::start(bool first_time) {
|
|||
// If it doesn't exit within a set time (seconds), the process is terminated
|
||||
//
|
||||
int ACTIVE_TASK::request_exit() {
|
||||
char susp_file[256];
|
||||
char quit_file[256];
|
||||
|
||||
get_slot_dir(slot, slot_dir);
|
||||
sprintf(susp_file, "%s%s%s", slot_dir, PATH_SEPARATOR, SUSPEND_QUIT_FILE);
|
||||
FILE *fp = fopen(susp_file, "w");
|
||||
sprintf(quit_file, "%s%s%s", slot_dir, PATH_SEPARATOR, QUIT_FILE);
|
||||
FILE *fp = fopen(quit_file, "w");
|
||||
if (!fp) return ERR_FOPEN;
|
||||
write_suspend_quit_file(fp, false, true);
|
||||
write_quit_file(fp);
|
||||
fclose(fp);
|
||||
return 0;
|
||||
}
|
||||
|
@ -561,7 +561,7 @@ void ACTIVE_TASK_SET::suspend_all() {
|
|||
for (i=0; i<active_tasks.size(); i++) {
|
||||
atp = active_tasks[i];
|
||||
if(atp->suspend()) {
|
||||
fprintf(stderr, "ACTIVE_TASK_SET::exit_tasks(): could not suspend active_task\n");
|
||||
fprintf(stderr, "ACTIVE_TASK_SET::suspend_all(): could not suspend active_task\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -574,7 +574,7 @@ void ACTIVE_TASK_SET::unsuspend_all() {
|
|||
for (i=0; i<active_tasks.size(); i++) {
|
||||
atp = active_tasks[i];
|
||||
if(atp->unsuspend()) {
|
||||
fprintf(stderr, "ACTIVE_TASK_SET::exit_tasks(): could not unsuspend active_task\n");
|
||||
fprintf(stderr, "ACTIVE_TASK_SET::unsuspend_all(): could not unsuspend active_task\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue