Changeset 2798


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

Lock the thread database before forking. Fixes #102.

Location:
branches/libc-0.6/src/emx
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • TabularUnified branches/libc-0.6/src/emx/ChangeLog.LIBC

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

    r2254 r2798  
    2828*   Header Files                                                               *
    2929*******************************************************************************/
     30#define __LIBC_LOG_GROUP __LIBC_LOG_GRP_THREAD
    3031#include "libc-alias.h"
    3132#undef NDEBUG
    32 #include <386/builtin.h>
     33#include <sys/builtin.h>
    3334#include <assert.h>
    3435#include <string.h>
     
    6364/** Number of threads in the zombie thread database. (Protected gmtxThrdDB.) */
    6465static unsigned         gcThrdDBZombies;
     66/** Fork cleanup indicator. */
     67static unsigned         gfForkCleanupDone;
    6568
    6669/** Head of the thread termination callback list. */
     
    510513    LIBCLOG_RETURN_VOID();
    511514}
     515
     516
     517#undef  __LIBC_LOG_GROUP
     518#define __LIBC_LOG_GROUP    __LIBC_LOG_GRP_FORK
     519
     520
     521/**
     522 * Fork completion callback used to release the thread db lock.
     523 *
     524 * @param   pvArg   NULL.
     525 * @param   rc      The fork() result. Negative on failure.
     526 * @param   enmCtx  The calling context.
     527 */
     528static void threadForkCompletion(void *pvArg, int rc, __LIBC_FORKCTX enmCtx)
     529{
     530    LIBCLOG_ENTER("pvArg=%p rc=%d enmCtx=%d - gfForkCleanupDone=%d\n", pvArg, rc, enmCtx, gfForkCleanupDone);
     531
     532    if (!gfForkCleanupDone)
     533    {
     534        LIBCLOG_MSG("Unlocking the thread DB.\n");
     535        if (enmCtx == __LIBC_FORK_CTX_PARENT)
     536            _fmutex_release(&gmtxThrdDB);
     537        else
     538            _fmutex_release_fork(&gmtxThrdDB);
     539        gfForkCleanupDone = 1;
     540    }
     541    LIBCLOG_RETURN_VOID();
     542}
     543
     544
     545/**
     546 * Parent fork callback for locking down the thread db while forking.
     547 *
     548 * @returns 0 on success.
     549 * @returns -errno on failure.
     550 * @param   pForkHandle     Pointer to fork handle.
     551 * @param   enmOperation    Fork operation.
     552 */
     553static int threadForkParent1(__LIBC_PFORKHANDLE pForkHandle, __LIBC_FORKOP enmOperation)
     554{
     555    LIBCLOG_ENTER("pForkHandle=%p enmOperation=%d\n", (void *)pForkHandle, enmOperation);
     556
     557    if (enmOperation != __LIBC_FORK_OP_EXEC_PARENT)
     558        LIBCLOG_RETURN_INT(0);
     559
     560    /*
     561     * Lock the thread database before fork() and schedule an unlocking completion callback.
     562     */
     563    LIBCLOG_MSG("Locking the thead DB.\n");
     564    if (_fmutex_request(&gmtxThrdDB, 0))
     565        LIBCLOG_ERROR_RETURN_INT(-EDEADLK);
     566
     567    gfForkCleanupDone = 0;
     568    int rc = pForkHandle->pfnCompletionCallback(pForkHandle, threadForkCompletion, NULL, __LIBC_FORK_CTX_BOTH);
     569    if (rc >= 0)
     570        LIBCLOG_RETURN_INT(rc);
     571
     572    _fmutex_release(&gmtxThrdDB);
     573    LIBCLOG_ERROR_RETURN_INT(rc);
     574}
     575
     576
     577_FORK_PARENT1(0xffffff02, threadForkParent1)
     578
Note: See TracChangeset for help on using the changeset viewer.