Changeset 3471 for trunk/src


Ignore:
Timestamp:
Sep 16, 2020, 2:06:12 AM (5 years ago)
Author:
bird
Message:

kash: Added comment about async close and stat. Some more logging in that area.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/kash/shfile.c

    r3469 r3471  
    295295    unsigned idx_next;
    296296    unsigned idx_read;
     297    unsigned num_pending = 0;
     298    unsigned num_threads = 0;
    297299    shmtxtmp tmp;
    298300    shmtx_enter(&g_shfile_async_close.mtx, &tmp);
     
    304306    if (idx_next != idx_read)
    305307    {
    306         unsigned num_pending, num_threads;
    307 
    308308        /* Write the handle to the ring buffer: */
    309309        assert(g_shfile_async_close.handles[idx] == NULL);
     
    322322            if (num_pending > num_threads && num_threads < K_ELEMENTS(g_shfile_async_close.threads))
    323323            {
     324                int const savederrno = errno;
    324325                unsigned tid = 0;
    325326                intptr_t hThread = _beginthreadex(NULL /*security*/, 0 /*stack_size*/, shfile_async_close_handle_thread,
     
    329330                {
    330331                    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;
    332333                }
    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;
    335341            }
    336342        }
     343        else
     344            TRACE2((NULL, "shfile_async_close_submit: SetEvent(%p) failed: %u\n", g_shfile_async_close.evt_workers, GetLastError()));
    337345
    338346        /* cleanup on failure. */
     
    350358
    351359    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));
    352362    return ret;
    353363}
     
    376386        shmtx_leave(&g_shfile_async_close.mtx, &tmp);
    377387
     388        TRACE2((NULL, "shfile_async_close_sync: Calling WaitForSingleObject...\n"));
    378389        dwRet = WaitForSingleObject(g_shfile_async_close.evt_sync, 10000 /*ms*/);
    379390        assert(dwRet == WAIT_OBJECT_0);
    380391        assert(g_shfile_async_close.num_pending == 0);
     392        TRACE2((NULL, "shfile_async_close_sync: WaitForSingleObject returned %u...\n", dwRet));
    381393    }
    382394    else
     
    405417     * So, detect problematic handles and do CloseHandle asynchronously.   When
    406418     * 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).
    410424     *
    411425     * If child processes are spawned using handle inheritance and the handle in
Note: See TracChangeset for help on using the changeset viewer.