From 7b5c1426501f796cd7e86238db52735329d7ff1c Mon Sep 17 00:00:00 2001 From: David Anderson Date: Tue, 7 Jun 2011 05:16:12 +0000 Subject: [PATCH] - API: undo the above API checkin, and provide a cleaner and documented way of doing the same thing; see http://boinc.berkeley.edu/trac/wiki/AppCoprocessor svn path=/trunk/boinc/; revision=23649 --- api/boinc_api.cpp | 48 ++++++++++++++++++++++------------------------- api/boinc_api.h | 3 +++ checkin_notes | 8 ++++++++ 3 files changed, 33 insertions(+), 26 deletions(-) diff --git a/api/boinc_api.cpp b/api/boinc_api.cpp index 781092f99e..238d58542f 100644 --- a/api/boinc_api.cpp +++ b/api/boinc_api.cpp @@ -164,9 +164,6 @@ static HANDLE hSharedMem; HANDLE worker_thread_handle; // used to suspend worker thread, and to measure its CPU time DWORD timer_thread_id; -//Jason: New windows exit handling to play more nicely with cuda & MS-CRT -volatile bool worker_thread_exit_request = false; -volatile bool worker_thread_exit_ack = false; #else static volatile bool worker_thread_exit_flag = false; static volatile int worker_thread_exit_status; @@ -179,7 +176,7 @@ static struct rusage worker_thread_ru; #endif static BOINC_OPTIONS options; -static volatile BOINC_STATUS boinc_status; +volatile BOINC_STATUS boinc_status; // vars related to intermediate file upload struct UPLOAD_FILE_STATUS { @@ -546,6 +543,7 @@ int boinc_init_options_general(BOINC_OPTIONS& opt) { int boinc_get_status(BOINC_STATUS *s) { s->no_heartbeat = boinc_status.no_heartbeat; s->suspended = boinc_status.suspended; + s->suspend_request = boinc_status.suspend_request; s->quit_request = boinc_status.quit_request; s->reread_init_data_file = boinc_status.reread_init_data_file; s->abort_request = boinc_status.abort_request; @@ -658,21 +656,6 @@ void boinc_exit(int status) { fflush(NULL); #if defined(_WIN32) - //Jason: Windows exit handling to play nicer with cuda & MS-CRT - worker_thread_exit_request = true; - fprintf(stderr,"boinc_exit(): requesting safe worker shutdown ->\n"); - int exitcounter = 0; - while ( !worker_thread_exit_ack && exitcounter < 20 ) - { - Sleep(100); - exitcounter++; - } - if (worker_thread_exit_ack) - fprintf(stderr,"boinc_exit(): received safe worker shutdown acknowledge ->\n"); - else - fprintf(stderr,"boinc_exit(): worker didn't respond to exit request within 2 seconds, exiting anyway.\n"); - fflush(NULL); - // ... Continue original nasty exit code here // Halt all the threads and cleans up. TerminateProcess(GetCurrentProcess(), status); // note: the above CAN return! @@ -903,26 +886,39 @@ static void handle_process_control_msg() { ); #endif if (match_tag(buf, "")) { + if (in_critical_section) { + boinc_status.suspend_request = true; + } else { + boinc_status.suspended = true; + suspend_activities(); + } + } + + if (!in_critical_section && boinc_status.suspend_request) { boinc_status.suspended = true; + boinc_status.suspend_request = false; suspend_activities(); } if (match_tag(buf, "")) { - boinc_status.suspended = false; - resume_activities(); + if (boinc_status.suspended) { + boinc_status.suspended = false; + resume_activities(); + } + boinc_status.suspend_request = false; } - if (match_tag(buf, "")) { + if (boinc_status.quit_request || match_tag(buf, "")) { BOINCINFO("Received quit message"); boinc_status.quit_request = true; - if (options.direct_process_action) { + if (!in_critical_section && options.direct_process_action) { exit_from_timer_thread(0); } } - if (match_tag(buf, "")) { + if (boinc_status.abort_request || match_tag(buf, "")) { BOINCINFO("Received abort message"); boinc_status.abort_request = true; - if (options.direct_process_action) { + if (!in_critical_section && options.direct_process_action) { diagnostics_set_aborted_via_gui(); #if defined(_WIN32) // Cause a controlled assert and dump the callstacks. @@ -1086,7 +1082,7 @@ static void timer_handler() { if (options.handle_trickle_downs) { handle_trickle_down_msg(); } - if (in_critical_section==0 && options.handle_process_control) { + if (options.handle_process_control) { handle_process_control_msg(); } handle_graphics_messages(); diff --git a/api/boinc_api.h b/api/boinc_api.h index 989b43eca0..01187274f1 100644 --- a/api/boinc_api.h +++ b/api/boinc_api.h @@ -71,6 +71,7 @@ typedef struct BOINC_OPTIONS { typedef struct BOINC_STATUS { int no_heartbeat; int suspended; + int suspend_request; int quit_request; int reread_init_data_file; int abort_request; @@ -79,6 +80,8 @@ typedef struct BOINC_STATUS { int network_suspended; } BOINC_STATUS; +extern volatile BOINC_STATUS boinc_status; + typedef void (*FUNC_PTR)(); struct APP_INIT_DATA; diff --git a/checkin_notes b/checkin_notes index ce02d0c615..99e75e5afd 100644 --- a/checkin_notes +++ b/checkin_notes @@ -3374,3 +3374,11 @@ David 6 Jun 2011 boinc_db.cpp tools/ backend_lib.cpp + +David 6 Jun 2011 + - API: undo the above API checkin, and provide a cleaner and + documented way of doing the same thing; see + http://boinc.berkeley.edu/trac/wiki/AppCoprocessor + + api/ + boinc_api.cpp,h