Changeset 3198 for trunk/src/kWorker/kWorker.c
- Timestamp:
- Mar 28, 2018, 6:15:07 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/kWorker/kWorker.c
r3192 r3198 11168 11168 else 11169 11169 return kwErrPrintfRc(2, "--priority takes an argument!\n"); 11170 11170 } 11171 else if (strcmp(argv[i], "--group") == 0) 11172 { 11173 i++; 11174 if (i < argc) 11175 { 11176 char *pszEnd = NULL; 11177 unsigned long uValue = strtoul(argv[i], &pszEnd, 16); 11178 if ( *argv[i] 11179 && pszEnd != NULL 11180 && *pszEnd == '\0' 11181 && uValue == (WORD)uValue) 11182 { 11183 typedef BOOL (WINAPI *PFNSETTHREADGROUPAFFINITY)(HANDLE, const GROUP_AFFINITY*, GROUP_AFFINITY *); 11184 PFNSETTHREADGROUPAFFINITY pfnSetThreadGroupAffinity; 11185 pfnSetThreadGroupAffinity = (PFNSETTHREADGROUPAFFINITY)GetProcAddress(GetModuleHandleW(L"KERNEL32.DLL"), 11186 "SetThreadGroupAffinity"); 11187 if (pfnSetThreadGroupAffinity) 11188 { 11189 GROUP_AFFINITY NewAff = { ~(uintptr_t)0, (WORD)uValue, 0, 0, 0 }; 11190 GROUP_AFFINITY OldAff = { 0, 0, 0, 0, 0 }; 11191 if (!pfnSetThreadGroupAffinity(GetCurrentThread(), &NewAff, &OldAff)) 11192 kwErrPrintf("Failed to set processor group to %lu: %u\n", uValue, GetLastError()); 11193 } 11194 else 11195 kwErrPrintf("Cannot set processor group to %lu because SetThreadGroupAffinity was not found\n", uValue); 11196 } 11197 else 11198 return kwErrPrintfRc(2, "Invalid --priority argument: %s\n", argv[i]); 11199 } 11200 else 11201 return kwErrPrintfRc(2, "--priority takes an argument!\n"); 11171 11202 } 11172 11203 else if ( strcmp(argv[i], "--help") == 0 … … 11174 11205 || strcmp(argv[i], "-?") == 0) 11175 11206 { 11176 printf("usage: kWorker [--volatile dir] [--priority <1-5>] --pipe <pipe-handle>\n"11207 printf("usage: kWorker [--volatile dir] [--priority <1-5>] [--group <processor-grp>\n" 11177 11208 "usage: kWorker <--help|-h>\n" 11178 11209 "usage: kWorker <--version|-V>\n" … … 11189 11220 } 11190 11221 11222 /* 11223 * If no --pipe argument, then assume its standard input. 11224 * We need to carefully replace the CRT stdin with a handle to "nul". 11225 */ 11191 11226 if (hPipe == INVALID_HANDLE_VALUE) 11192 return kwErrPrintfRc(2, "Missing --pipe <pipe-handle> argument!\n"); 11227 { 11228 hPipe = GetStdHandle(STD_INPUT_HANDLE); 11229 if (GetFileType(hPipe) == FILE_TYPE_PIPE) 11230 { 11231 HANDLE hDuplicate = INVALID_HANDLE_VALUE; 11232 if (DuplicateHandle(GetCurrentProcess(), hPipe, GetCurrentProcess(), &hDuplicate, 0, FALSE, DUPLICATE_SAME_ACCESS)) 11233 { 11234 int fdNul = _wopen(L"nul", O_RDWR | O_BINARY); 11235 if (fdNul >= 0) 11236 { 11237 if (_dup2(fdNul, 0) >= 0) 11238 { 11239 close(fdNul); 11240 kHlpAssert(GetStdHandle(STD_INPUT_HANDLE) != hPipe); 11241 hPipe = hDuplicate; 11242 } 11243 else 11244 return kwErrPrintfRc(2, "DuplicateHandle pipe failed: %u\n", GetLastError()); 11245 } 11246 else 11247 return kwErrPrintfRc(2, "DuplicateHandle pipe failed: %u\n", GetLastError()); 11248 } 11249 else 11250 return kwErrPrintfRc(2, "DuplicateHandle pipe failed: %u\n", GetLastError()); 11251 } 11252 else 11253 return kwErrPrintfRc(2, "No --pipe <pipe-handle> argument and standard input is not a valid pipe handle (%#x, %u)\n", 11254 GetFileType(hPipe), GetLastError()); 11255 } 11256 else if (GetFileType(hPipe) != FILE_TYPE_PIPE) 11257 return kwErrPrintfRc(2, "The specified --pipe %p is not a pipe handle: type %#x (last err %u)!\n", 11258 GetFileType(hPipe), GetLastError()); 11193 11259 11194 11260 /*
Note:
See TracChangeset
for help on using the changeset viewer.