diff options
| author | Jason Rumney | 2007-06-14 15:58:13 +0000 |
|---|---|---|
| committer | Jason Rumney | 2007-06-14 15:58:13 +0000 |
| commit | 74258518069d18525237fc0f3dcf33ffa3fd65e9 (patch) | |
| tree | 2da4ed4af277a95924ab50263dc5184aa31b6866 /src | |
| parent | 553d31640139f393e80dd411fe2b07509d47bd5b (diff) | |
| download | emacs-74258518069d18525237fc0f3dcf33ffa3fd65e9.tar.gz emacs-74258518069d18525237fc0f3dcf33ffa3fd65e9.zip | |
(get_process_times_fn): New function pointer.
(globals_of_w32): Intialize it if present in kernel32.dll.
(w32_get_internal_run_time): New function.
Diffstat (limited to 'src')
| -rw-r--r-- | src/w32.c | 54 |
1 files changed, 54 insertions, 0 deletions
| @@ -137,6 +137,15 @@ typedef BOOL (WINAPI * GetTokenInformation_Proc) ( | |||
| 137 | LPVOID TokenInformation, | 137 | LPVOID TokenInformation, |
| 138 | DWORD TokenInformationLength, | 138 | DWORD TokenInformationLength, |
| 139 | PDWORD ReturnLength); | 139 | PDWORD ReturnLength); |
| 140 | typedef BOOL (WINAPI * GetProcessTimes_Proc) ( | ||
| 141 | HANDLE process_handle, | ||
| 142 | LPFILETIME creation_time, | ||
| 143 | LPFILETIME exit_time, | ||
| 144 | LPFILETIME kernel_time, | ||
| 145 | LPFILETIME user_time); | ||
| 146 | |||
| 147 | GetProcessTimes_Proc get_process_times_fn = NULL; | ||
| 148 | |||
| 140 | #ifdef _UNICODE | 149 | #ifdef _UNICODE |
| 141 | const char * const LookupAccountSid_Name = "LookupAccountSidW"; | 150 | const char * const LookupAccountSid_Name = "LookupAccountSidW"; |
| 142 | #else | 151 | #else |
| @@ -172,6 +181,46 @@ is_windows_9x () | |||
| 172 | return s_b_ret; | 181 | return s_b_ret; |
| 173 | } | 182 | } |
| 174 | 183 | ||
| 184 | /* Get total user and system times for get-internal-run-time. | ||
| 185 | Returns a list of three integers if the times are provided by the OS | ||
| 186 | (NT derivatives), otherwise it returns the result of current-time. */ | ||
| 187 | Lisp_Object | ||
| 188 | w32_get_internal_run_time () | ||
| 189 | { | ||
| 190 | if (get_process_times_fn) | ||
| 191 | { | ||
| 192 | FILETIME create, exit, kernel, user; | ||
| 193 | HANDLE proc = GetCurrentProcess(); | ||
| 194 | if ((*get_process_times_fn) (proc, &create, &exit, &kernel, &user)) | ||
| 195 | { | ||
| 196 | LARGE_INTEGER user_int, kernel_int, total; | ||
| 197 | int microseconds; | ||
| 198 | user_int.LowPart = user.dwLowDateTime; | ||
| 199 | user_int.HighPart = user.dwHighDateTime; | ||
| 200 | kernel_int.LowPart = kernel.dwLowDateTime; | ||
| 201 | kernel_int.HighPart = kernel.dwHighDateTime; | ||
| 202 | total.QuadPart = user_int.QuadPart + kernel_int.QuadPart; | ||
| 203 | /* FILETIME is 100 nanosecond increments, Emacs only wants | ||
| 204 | microsecond resolution. */ | ||
| 205 | total.QuadPart /= 10; | ||
| 206 | microseconds = total.QuadPart % 1000000; | ||
| 207 | total.QuadPart /= 1000000; | ||
| 208 | |||
| 209 | /* Sanity check to make sure we can represent the result. */ | ||
| 210 | if (total.HighPart == 0) | ||
| 211 | { | ||
| 212 | int secs = total.LowPart; | ||
| 213 | |||
| 214 | return list3 (make_number ((secs >> 16) & 0xffff), | ||
| 215 | make_number (secs & 0xffff), | ||
| 216 | make_number (microseconds)); | ||
| 217 | } | ||
| 218 | } | ||
| 219 | } | ||
| 220 | |||
| 221 | return Fcurrent_time (); | ||
| 222 | } | ||
| 223 | |||
| 175 | /* ** The wrapper functions ** */ | 224 | /* ** The wrapper functions ** */ |
| 176 | 225 | ||
| 177 | BOOL WINAPI open_process_token ( | 226 | BOOL WINAPI open_process_token ( |
| @@ -4144,6 +4193,11 @@ BOOL WINAPI shutdown_handler(DWORD type) | |||
| 4144 | void | 4193 | void |
| 4145 | globals_of_w32 () | 4194 | globals_of_w32 () |
| 4146 | { | 4195 | { |
| 4196 | HMODULE kernel32 = GetModuleHandle ("kernel32.dll"); | ||
| 4197 | |||
| 4198 | get_process_times_fn = (GetProcessTimes_Proc) | ||
| 4199 | GetProcAddress (kernel32, "GetProcessTimes"); | ||
| 4200 | |||
| 4147 | g_b_init_is_windows_9x = 0; | 4201 | g_b_init_is_windows_9x = 0; |
| 4148 | g_b_init_open_process_token = 0; | 4202 | g_b_init_open_process_token = 0; |
| 4149 | g_b_init_get_token_information = 0; | 4203 | g_b_init_get_token_information = 0; |