From 7c0456340ae67b2ca5968b03536d1b9a6946b92c Mon Sep 17 00:00:00 2001 From: David Anderson Date: Fri, 28 Jan 2005 01:58:11 +0000 Subject: [PATCH] *** empty log message *** svn path=/trunk/boinc/; revision=5232 --- api/boinc_api.C | 52 ++++++++++++++--------------------------- api/boinc_api.h | 5 ---- api/boinc_api_fortran.C | 21 ++++++----------- api/graphics_impl.C | 10 +------- checkin_notes | 13 +++++++++++ 5 files changed, 39 insertions(+), 62 deletions(-) diff --git a/api/boinc_api.C b/api/boinc_api.C index 106e146dc2..c888431791 100644 --- a/api/boinc_api.C +++ b/api/boinc_api.C @@ -99,6 +99,7 @@ static int nrunning_ticks = 0; //HANDLE hResumeRequest; static HANDLE hSharedMem; HANDLE worker_thread_handle; + // used to suspend worker thread, and to measure its CPU time static MMRESULT timer_id; #endif @@ -111,14 +112,6 @@ static BOINC_STATUS boinc_status; // int boinc_init() { boinc_options_defaults(options); - - // adjust the thread priority so we don't eat cycles from - // other programs - // -#ifdef _WIN32 - boinc_adjust_worker_thread_priority(GetCurrentThread()); -#endif - return boinc_init_options(options); } @@ -153,18 +146,6 @@ int boinc_init_options_general(BOINC_OPTIONS& opt) { } } -#ifdef _WIN32 - DuplicateHandle( - GetCurrentProcess(), - GetCurrentThread(), - GetCurrentProcess(), - &worker_thread_handle, - 0, - FALSE, - DUPLICATE_SAME_ACCESS - ); -#endif - retval = boinc_parse_init_data_file(); if (retval) { standalone = true; @@ -201,20 +182,6 @@ int boinc_init_options_general(BOINC_OPTIONS& opt) { return 0; } -// adjust the worker thread priority to the lowest thread priority -// available -#ifdef _WIN32 -int boinc_adjust_worker_thread_priority(HANDLE thread_handle) { - if (!SetThreadPriority(thread_handle, THREAD_PRIORITY_LOWEST)) - return ERR_THREAD; - return 0; -} -#else -int boinc_adjust_worker_thread_priority(pthread_t thread_handle) { - return 0; -} -#endif - int boinc_get_status(BOINC_STATUS& s) { s = boinc_status; return 0; @@ -563,9 +530,22 @@ static void worker_timer(int a) { } +// set up a periodic timer interrupt for the worker thread. +// This is called only and always by the worker thread +// int set_worker_timer() { int retval=0; + #ifdef _WIN32 + DuplicateHandle( + GetCurrentProcess(), + GetCurrentThread(), + GetCurrentProcess(), + &worker_thread_handle, + 0, + FALSE, + DUPLICATE_SAME_ACCESS + ); // Use Windows multimedia timer, since it is more accurate // than SetTimer and doesn't require an associated event loop @@ -577,6 +557,10 @@ int set_worker_timer() { NULL, // dwUser TIME_PERIODIC // fuEvent ); + + // lower our priority here + // + SetThreadPriority(worker_thread_handle, THREAD_PRIORITY_LOWEST); #else struct sigaction sa; itimerval value; diff --git a/api/boinc_api.h b/api/boinc_api.h index a8c4e0c436..1028d1ae5b 100755 --- a/api/boinc_api.h +++ b/api/boinc_api.h @@ -97,11 +97,6 @@ extern int boinc_get_status(BOINC_STATUS&); extern int boinc_resolve_filename_s(const char*, std::string&); extern int boinc_get_init_data(APP_INIT_DATA&); extern int boinc_wu_cpu_time(double&); -#ifdef _WIN32 -extern int boinc_adjust_worker_thread_priority(HANDLE thread_handle); -#else -extern int boinc_adjust_worker_thread_priority(pthread_t thread_handle); -#endif /////////// API ENDS HERE diff --git a/api/boinc_api_fortran.C b/api/boinc_api_fortran.C index 6c615b3c0d..77bdfdca38 100644 --- a/api/boinc_api_fortran.C +++ b/api/boinc_api_fortran.C @@ -59,23 +59,21 @@ extern "C" { *result = boinc_is_standalone(); } - void boinc_resolve_filename_(const char* s, char* t, int* length, int s_len, int t_len) - { + void boinc_resolve_filename_( + const char* s, char* t, int* length, int s_len, int t_len + ) { boinc_resolve_filename(StringFromFortran(s, s_len), t, *length); } - void boincrf_(const char* s, char* t, int s_len, int t_len) - { + void boincrf_(const char* s, char* t, int s_len, int t_len) { boinc_resolve_filename(StringFromFortran(s, s_len), t, t_len); } - void boinc_parse_init_data_file_() - { + void boinc_parse_init_data_file_() { boinc_parse_init_data_file(); } - void boinc_write_init_data_file_() - { + void boinc_write_init_data_file_() { boinc_write_init_data_file_(); } @@ -108,15 +106,10 @@ extern "C" { boinc_wu_cpu_time(*d_out); } - void boinc_calling_thread_cpu_time_(double* d1_out, double* d2_out) - { + void boinc_calling_thread_cpu_time_(double* d1_out, double* d2_out) { boinc_calling_thread_cpu_time(*d1_out, *d2_out); } - void boinc_sixtrack_progress_(int* n,int* total) - { - boinc_fraction_done(*n / *total); - } } diff --git a/api/graphics_impl.C b/api/graphics_impl.C index 06332bcb78..95c9bd9335 100755 --- a/api/graphics_impl.C +++ b/api/graphics_impl.C @@ -100,19 +100,11 @@ int start_worker_thread(WORKER_FUNC_PTR _worker_main) { DWORD threadId; - // Create the graphics thread, passing it the graphics info - // TODO: is it better to use _beginthreadex here? + // Create and start worker thread // worker_thread_handle = CreateThread( NULL, 0, foobar, 0, CREATE_SUSPENDED, &threadId ); - - // lower worker thread priority - // - boinc_adjust_worker_thread_priority(worker_thread_handle); - - // Start the worker thread - // ResumeThread(worker_thread_handle); #else diff --git a/checkin_notes b/checkin_notes index eee092872d..5d05752b9b 100755 --- a/checkin_notes +++ b/checkin_notes @@ -23342,3 +23342,16 @@ David 27 Jan 2005 tools/ kill_wu.C poll_wu.C + +David 27 Jan 2005 + - API: move code to get worker thread handle, + and set its priority, to set_worker_timer(). + This function is guaranteed to be always called + by the worker thread, and only by the worker thread. + Got rid of boinc_adjust_worker_thread_priority(). + - removed LHC@home-specific function from boinc_api_fortran.C + + api/ + boinc_api.C + boinc_api_fortran.C + graphics_impl.C