- Timestamp:
- Sep 16, 2020, 2:06:12 AM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/kash/shfile.c
r3469 r3471 295 295 unsigned idx_next; 296 296 unsigned idx_read; 297 unsigned num_pending = 0; 298 unsigned num_threads = 0; 297 299 shmtxtmp tmp; 298 300 shmtx_enter(&g_shfile_async_close.mtx, &tmp); … … 304 306 if (idx_next != idx_read) 305 307 { 306 unsigned num_pending, num_threads;307 308 308 /* Write the handle to the ring buffer: */ 309 309 assert(g_shfile_async_close.handles[idx] == NULL); … … 322 322 if (num_pending > num_threads && num_threads < K_ELEMENTS(g_shfile_async_close.threads)) 323 323 { 324 int const savederrno = errno; 324 325 unsigned tid = 0; 325 326 intptr_t hThread = _beginthreadex(NULL /*security*/, 0 /*stack_size*/, shfile_async_close_handle_thread, … … 329 330 { 330 331 g_shfile_async_close.threads[num_threads] = (HANDLE)hThread; 331 g_shfile_async_close.num_threads = num_threads + 1;332 g_shfile_async_close.num_threads = ++num_threads; 332 333 } 333 else if (num_threads == 0) 334 ret = K_FALSE; 334 else 335 { 336 TRACE2((NULL, "shfile_async_close_submit: _beginthreadex failed: %d\n", errno)); 337 if (num_threads == 0) 338 ret = K_FALSE; 339 } 340 errno = savederrno; 335 341 } 336 342 } 343 else 344 TRACE2((NULL, "shfile_async_close_submit: SetEvent(%p) failed: %u\n", g_shfile_async_close.evt_workers, GetLastError())); 337 345 338 346 /* cleanup on failure. */ … … 350 358 351 359 shmtx_leave(&g_shfile_async_close.mtx, &tmp); 360 TRACE2((NULL, "shfile_async_close_submit: toclose=%p idx=%d #pending=%u #thread=%u -> %d\n", 361 toclose, idx, num_pending, num_threads, ret)); 352 362 return ret; 353 363 } … … 376 386 shmtx_leave(&g_shfile_async_close.mtx, &tmp); 377 387 388 TRACE2((NULL, "shfile_async_close_sync: Calling WaitForSingleObject...\n")); 378 389 dwRet = WaitForSingleObject(g_shfile_async_close.evt_sync, 10000 /*ms*/); 379 390 assert(dwRet == WAIT_OBJECT_0); 380 391 assert(g_shfile_async_close.num_pending == 0); 392 TRACE2((NULL, "shfile_async_close_sync: WaitForSingleObject returned %u...\n", dwRet)); 381 393 } 382 394 else … … 405 417 * So, detect problematic handles and do CloseHandle asynchronously. When 406 418 * executing a child process, we probably will have to make sure the CloseHandle 407 * operation has completed before we let do ResumeThread on the child to make 408 * 100% sure we can't have any sharing conflicts. Sharing conflicts are not a 409 * problem for builtin commands. 419 * operation has completed before we do ResumeThread on the child to make 100% 420 * sure we can't have any sharing conflicts or end up with incorrect CRT stat() 421 * results. Sharing conflicts are not a problem for builtin commands, and for 422 * stat we do not use the CRT code but ntstat.c/h and it seems to work fine 423 * (might be a tiny bit slower, so (TODO) might be worth reducing what we ask for). 410 424 * 411 425 * If child processes are spawned using handle inheritance and the handle in
Note:
See TracChangeset
for help on using the changeset viewer.