API, Unix: call getrusage() from inside boinc_worker_thread_cpu_time() and make worker_thread_ru a local stack variable to avoid potential problems with thread preemption.

svn path=/trunk/boinc/; revision=13880
This commit is contained in:
Charlie Fenton 2007-10-17 19:53:51 +00:00
parent c70f01b64d
commit 2ed89c4c65
2 changed files with 11 additions and 3 deletions

View File

@ -140,7 +140,6 @@ HANDLE worker_thread_handle;
// used to suspend worker thread, and to measure its CPU time // used to suspend worker thread, and to measure its CPU time
#else #else
static pthread_t timer_thread_handle; static pthread_t timer_thread_handle;
static struct rusage worker_thread_ru;
#endif #endif
static BOINC_OPTIONS options; static BOINC_OPTIONS options;
@ -206,6 +205,9 @@ double boinc_worker_thread_cpu_time() {
cpu = nrunning_ticks * TIMER_PERIOD; // for Win9x cpu = nrunning_ticks * TIMER_PERIOD; // for Win9x
} }
#else #else
struct rusage worker_thread_ru;
getrusage(RUSAGE_SELF, &worker_thread_ru);
cpu = (double)worker_thread_ru.ru_utime.tv_sec cpu = (double)worker_thread_ru.ru_utime.tv_sec
+ (((double)worker_thread_ru.ru_utime.tv_usec)/1000000.0); + (((double)worker_thread_ru.ru_utime.tv_usec)/1000000.0);
cpu += (double)worker_thread_ru.ru_stime.tv_sec cpu += (double)worker_thread_ru.ru_stime.tv_sec
@ -931,7 +933,6 @@ void* timer_thread(void*) {
block_sigalrm(); block_sigalrm();
while(1) { while(1) {
boinc_sleep(TIMER_PERIOD); boinc_sleep(TIMER_PERIOD);
getrusage(RUSAGE_SELF, &worker_thread_ru);
timer_handler(); timer_handler();
} }
return 0; return 0;

View File

@ -9607,4 +9607,11 @@ Charlie 16 Oct 2007
setupForBOINC.sh setupForBOINC.sh
boinc.xcodeproj/ boinc.xcodeproj/
project.pbxproj project.pbxproj
Charlie 16 Oct 2007
- API, Unix: call getrusage() from inside boinc_worker_thread_cpu_time()
and make worker_thread_ru a local stack variable to avoid potential
problems with thread preemption.
api/
boinc_api.C