From 623379907115be0c6fee0ad9de163a704e375be6 Mon Sep 17 00:00:00 2001 From: Eric Heien Date: Thu, 6 Jun 2002 18:42:01 +0000 Subject: [PATCH] Changes made to files to for Windows port. svn path=/trunk/boinc/; revision=90 --- client/accounts.C | 2 ++ client/app.C | 78 +++++++++++++++++++++++++++++++++++++++---- client/app.h | 14 +++++++- client/client_state.C | 2 ++ client/client_types.C | 2 ++ client/client_types.h | 2 ++ client/cs_apps.C | 2 ++ client/cs_files.C | 7 ++++ client/file_names.C | 27 +++++++++++++++ client/file_xfer.C | 2 ++ client/filesys.C | 5 ++- 11 files changed, 135 insertions(+), 8 deletions(-) diff --git a/client/accounts.C b/client/accounts.C index e9998a837d..2e235f03bb 100644 --- a/client/accounts.C +++ b/client/accounts.C @@ -17,6 +17,8 @@ // Contributor(s): // +#include "windows_cpp.h" + #include #include "error_numbers.h" diff --git a/client/app.C b/client/app.C index 977792852b..61bc9743ab 100644 --- a/client/app.C +++ b/client/app.C @@ -21,14 +21,20 @@ // connected to I/O files in various ways. // Shouldn't depend on CLIENT_STATE. +#include "windows_cpp.h" + +#ifdef _WIN32 +#else #include -#include #include #include #include +#endif +#include #include #include #include +#include #include "client_types.h" #include "client_state.h" @@ -210,6 +216,7 @@ int ACTIVE_TASK::start(bool first_time) { #endif #ifdef _WIN32 + //CreateProcess #endif #ifdef macintosh @@ -233,14 +240,53 @@ int ACTIVE_TASK_SET::insert(ACTIVE_TASK* atp) { // check for child process exit // bool ACTIVE_TASK_SET::poll() { - int pid; int stat; ACTIVE_TASK* atp; - struct rusage rs; char path[256]; int n; +#ifdef _WIN32 + unsigned long exit_code; + int i; + FILETIME creation_time, exit_time, kernel_time, user_time; + ULARGE_INTEGER tKernel, tUser; + LONGLONG totTime; + + for (i=0; ipid_handle,&exit_code ) ) { + // Get the elapsed CPU time + // Factor this into the equivalent of a S@H etime function? + if( GetProcessTimes( atp->pid_handle, &creation_time, &exit_time, &kernel_time, &user_time ) ) { + tKernel.LowPart = kernel_time.dwLowDateTime; + tKernel.HighPart = kernel_time.dwHighDateTime; + + tUser.LowPart = user_time.dwLowDateTime; + tUser.HighPart = user_time.dwHighDateTime; + + // Runtimes in 100-nanosecond units + totTime = tKernel.QuadPart + tUser.QuadPart; + + atp->result->cpu_time = (totTime / 10000000.0); + } else { + atp->result->cpu_time = ((double)clock())/CLOCKS_PER_SEC; + } + if( exit_code != STILL_ACTIVE ) { + // Not sure how to incorporate the other states (WAS_SIGNALED, etc) + atp->state = PROCESS_EXITED; + atp->exit_status = exit_code; + atp->result->exit_status = atp->exit_status; + } + } else { + // Not sure what to do here + } + } +#endif + #ifdef unix + struct rusage rs; + int pid; + pid = wait3(&stat, WNOHANG, &rs); if (pid <= 0) return false; if (log_flags.task_debug) printf("got signal for process %d\n", pid); @@ -262,6 +308,7 @@ bool ACTIVE_TASK_SET::poll() { atp->state = PROCESS_EXIT_UNKNOWN; atp->result->exit_status = -1; } +#endif // check for the stderr file, copy to result record // @@ -274,7 +321,6 @@ bool ACTIVE_TASK_SET::poll() { } clean_out_dir(atp->dirname); -#endif return true; } @@ -295,7 +341,7 @@ void ACTIVE_TASK_SET::suspend_all() { ACTIVE_TASK* atp; for (i=0; ipid, SIGSTOP); + atp->suspend(); } } @@ -304,10 +350,30 @@ void ACTIVE_TASK_SET::unsuspend_all() { ACTIVE_TASK* atp; for (i=0; ipid, SIGCONT); + atp->unsuspend(); } } +#ifdef _WIN32 +void ACTIVE_TASK::suspend() { + // figure out a way to do this + //kill(atp->pid, SIGSTOP); +} + +void ACTIVE_TASK::unsuspend() { + // figure out a way to do this + //kill(atp->pid, SIGCONT); +} +#else +void ACTIVE_TASK::suspend() { + kill(this->pid, SIGSTOP); +} + +void ACTIVE_TASK::unsuspend() { + kill(this->pid, SIGCONT); +} +#endif + int ACTIVE_TASK_SET::remove(ACTIVE_TASK* atp) { vector::iterator iter; diff --git a/client/app.h b/client/app.h index 913dd989ac..f4d66e750f 100644 --- a/client/app.h +++ b/client/app.h @@ -26,11 +26,17 @@ #define PROCESS_EXIT_UNKNOWN 4 #ifdef macintosh - typedef ProcessSerialNumber PROCESS_ID; + typedef int PROCESS_ID; + //typedef ProcessSerialNumber PROCESS_ID; #else typedef int PROCESS_ID; #endif +#include "windows_cpp.h" +#ifdef _WIN32 +#include +#endif + #include #include @@ -42,6 +48,9 @@ class CLIENT_STATE; // class ACTIVE_TASK { public: +#ifdef _WIN32 + HANDLE pid_handle; +#endif RESULT* result; WORKUNIT* wup; APP_VERSION* app_version; @@ -61,6 +70,9 @@ public: void request_pause(int x); // request a task to pause. If not paused after x secs, kill + void suspend(); + void unsuspend(); + int write(FILE*); int parse(FILE*, CLIENT_STATE*); }; diff --git a/client/client_state.C b/client/client_state.C index d9ebf9dbbd..64cfaee11a 100644 --- a/client/client_state.C +++ b/client/client_state.C @@ -17,6 +17,8 @@ // Contributor(s): // +#include "windows_cpp.h" + #include #include "error_numbers.h" diff --git a/client/client_types.C b/client/client_types.C index 5b699ae489..dd7996791b 100644 --- a/client/client_types.C +++ b/client/client_types.C @@ -17,6 +17,8 @@ // Contributor(s): // +#include "windows_cpp.h" + #include "error_numbers.h" #include "file_names.h" #include "filesys.h" diff --git a/client/client_types.h b/client/client_types.h index a8a181298e..e64cf54856 100644 --- a/client/client_types.h +++ b/client/client_types.h @@ -22,6 +22,8 @@ // client_state.C (to cross-link objects) // +#include "windows_cpp.h" + #ifndef _TYPES_ #define _TYPES_ diff --git a/client/cs_apps.C b/client/cs_apps.C index 1f47c5e700..28330e3283 100644 --- a/client/cs_apps.C +++ b/client/cs_apps.C @@ -17,6 +17,8 @@ // Contributor(s): // +#include "windows_cpp.h" + #include "md5_file.h" #include "log_flags.h" #include "file_names.h" diff --git a/client/cs_files.C b/client/cs_files.C index 6e9ae9fc8f..5a043dc54a 100644 --- a/client/cs_files.C +++ b/client/cs_files.C @@ -20,7 +20,14 @@ // functions relating to file transfer // +#include "windows_cpp.h" + +#ifdef _WIN32 +#include +#endif + #include +#include #include "md5_file.h" #include "file_xfer.h" diff --git a/client/file_names.C b/client/file_names.C index 36688151ba..36d7b73690 100644 --- a/client/file_names.C +++ b/client/file_names.C @@ -17,6 +17,12 @@ // Contributor(s): // +#include "windows_cpp.h" + +#ifdef _WIN32 +#include +#endif + #include #include @@ -31,6 +37,25 @@ void get_slot_dir(int slot, char* path) { sprintf(path, "slots/%d", slot); } +#ifdef _WIN32 + +// Double check permissions for CreateDirectory + +int make_project_dir(PROJECT& p) { + CreateDirectory(p.domain, NULL); + return 0; +} + +int make_slot_dir(int slot) { + char buf[256]; + CreateDirectory("slots", NULL); + get_slot_dir(slot, buf); + CreateDirectory(buf, NULL); + return 0; +} + +#else + int make_project_dir(PROJECT& p) { mkdir(p.domain, 0777); return 0; @@ -43,3 +68,5 @@ int make_slot_dir(int slot) { mkdir(buf, 0777); return 0; } + +#endif \ No newline at end of file diff --git a/client/file_xfer.C b/client/file_xfer.C index 5e9cad08fd..f9f7819e1c 100644 --- a/client/file_xfer.C +++ b/client/file_xfer.C @@ -17,6 +17,8 @@ // Contributor(s): // +#include "windows_cpp.h" + #include "util.h" #include "log_flags.h" #include "file_xfer.h" diff --git a/client/filesys.C b/client/filesys.C index 841b680955..2118a87d25 100644 --- a/client/filesys.C +++ b/client/filesys.C @@ -17,6 +17,8 @@ // Contributor(s): // +#include "windows_cpp.h" + #include #include @@ -47,6 +49,7 @@ #include #endif +#include "util.h" #include "error_numbers.h" #include "filesys.h" @@ -157,7 +160,7 @@ int file_delete(char* path) { retval = remove(path); #endif if (!retval) break; - if (i==0) sleep(3); + if (i==0) boinc_sleep(3); } if (retval) { strcpy(failed_file, path);