Changeset 2799 for trunk


Ignore:
Timestamp:
Aug 28, 2006, 4:01:58 AM (19 years ago)
Author:
bird
Message:

Lock the thread database before forking. Fixes #102. (from 0.6)

Location:
trunk/libc
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/libc/ChangeLog.LIBC

    r2797 r2799  
    552006-08-27: knut st. osmundsen <bird-gccos2-spam@anduin.net>
    66    - libc:
     7        o Lock the thread database before forking. Fixes #102. (from 0.6)
    78        o Fixed log problem in fork() child. Fixes #119. (from 0.6)
    89        o Corrected DosSetFHState mask. Fixes #118.
  • trunk/libc/src/libc/process/thread_internals.c

    r2739 r2799  
    6363/** Number of threads in the zombie thread database. (Protected gmtxThrdDB.) */
    6464static unsigned         gcThrdDBZombies;
     65/** Fork cleanup indicator. */
     66static unsigned         gfForkCleanupDone;
    6567
    6668/** Head of the thread termination callback list. */
     
    527529    LIBCLOG_RETURN_VOID();
    528530}
     531
     532
     533#undef  __LIBC_LOG_GROUP
     534#define __LIBC_LOG_GROUP    __LIBC_LOG_GRP_FORK
     535
     536
     537/**
     538 * Fork completion callback used to release the thread db lock.
     539 *
     540 * @param   pvArg   NULL.
     541 * @param   rc      The fork() result. Negative on failure.
     542 * @param   enmCtx  The calling context.
     543 */
     544static void threadForkCompletion(void *pvArg, int rc, __LIBC_FORKCTX enmCtx)
     545{
     546    LIBCLOG_ENTER("pvArg=%p rc=%d enmCtx=%d - gfForkCleanupDone=%d\n", pvArg, rc, enmCtx, gfForkCleanupDone);
     547
     548    if (!gfForkCleanupDone)
     549    {
     550        LIBCLOG_MSG("Unlocking the thread DB.\n");
     551        if (enmCtx == __LIBC_FORK_CTX_PARENT)
     552            _fmutex_release(&gmtxThrdDB);
     553        else
     554            _fmutex_release_fork(&gmtxThrdDB);
     555        gfForkCleanupDone = 1;
     556    }
     557    LIBCLOG_RETURN_VOID();
     558}
     559
     560
     561/**
     562 * Parent fork callback for locking down the thread db while forking.
     563 *
     564 * @returns 0 on success.
     565 * @returns -errno on failure.
     566 * @param   pForkHandle     Pointer to fork handle.
     567 * @param   enmOperation    Fork operation.
     568 */
     569static int threadForkParent1(__LIBC_PFORKHANDLE pForkHandle, __LIBC_FORKOP enmOperation)
     570{
     571    LIBCLOG_ENTER("pForkHandle=%p enmOperation=%d\n", (void *)pForkHandle, enmOperation);
     572
     573    if (enmOperation != __LIBC_FORK_OP_EXEC_PARENT)
     574        LIBCLOG_RETURN_INT(0);
     575
     576    /*
     577     * Lock the thread database before fork() and schedule an unlocking completion callback.
     578     */
     579    LIBCLOG_MSG("Locking the thead DB.\n");
     580    if (_fmutex_request(&gmtxThrdDB, 0))
     581        LIBCLOG_ERROR_RETURN_INT(-EDEADLK);
     582
     583    gfForkCleanupDone = 0;
     584    int rc = pForkHandle->pfnCompletionCallback(pForkHandle, threadForkCompletion, NULL, __LIBC_FORK_CTX_BOTH);
     585    if (rc >= 0)
     586        LIBCLOG_RETURN_INT(rc);
     587
     588    _fmutex_release(&gmtxThrdDB);
     589    LIBCLOG_ERROR_RETURN_INT(rc);
     590}
     591
     592
     593_FORK_PARENT1(0xffffff02, threadForkParent1)
     594
Note: See TracChangeset for help on using the changeset viewer.