Changeset 3849


Ignore:
Timestamp:
Mar 16, 2014, 10:17:54 PM (11 years ago)
Author:
bird
Message:

fmutex: Don't panic on process exit (exit lists etc), also don't wait too long on mutexes during process exit since the owner might be dead. Fixes #256.

Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/libc-0.6/src/emx/src/lib/process/fmutex.c

    r3102 r3849  
    148148        for (;;)
    149149        {
    150             rc = DosWaitEventSem(sem->hev, sem->flags & _FMC_SHARED ? SEM_INDEFINITE_WAIT : 3000);
     150            ULONG cMsWait = sem->flags & _FMC_SHARED ? SEM_INDEFINITE_WAIT : 3000;
     151            if (fibIsInExit())
     152                cMsWait = 250;
     153            rc = DosWaitEventSem(sem->hev, cMsWait);
    151154            if (rc == ERROR_INTERRUPT)
    152155            {
     
    165168            if (rc != ERROR_TIMEOUT)
    166169                break;
     170
    167171            /*
    168172             * Deadlock detection - check if owner is around.
     
    179183            }
    180184        }
     185
    181186        FS_RESTORE();
    182187        if (rc != 0)
     
    284289        for (;;)
    285290        {
    286             DosExitMustComplete(&ulNesting);
    287             rc = DosWaitEventSem(sem->hev, sem->flags & _FMC_SHARED ? SEM_INDEFINITE_WAIT : 3000);
     291            ULONG cMsWait = sem->flags & _FMC_SHARED ? SEM_INDEFINITE_WAIT : 3000;
     292            if (fibIsInExit())
     293                cMsWait = 250;
     294            DosExitMustComplete(&ulNesting);
     295            rc = DosWaitEventSem(sem->hev, cMsWait);
    288296            DosEnterMustComplete(&ulNesting);
    289297            if (rc == ERROR_INTERRUPT)
     
    303311            if (rc != ERROR_TIMEOUT)
    304312                break;
     313
    305314            /*
    306315             * Deadlock detection - check if owner is around.
     
    319328            }
    320329        }
     330
    321331        FS_RESTORE();
    322332        if (rc != 0)
     
    331341static void __fmutex_deadlock(_fmutex *pSem, const char *pszMsg)
    332342{
    333     __libc_Back_panic(0, NULL,
    334                       "fmutex deadlock: %s\n"
    335                       "%x: Owner=%x Self=%x fs=%x flags=%x hev=%x\n"
    336                       "            Desc=\"%s\"\n",
    337                       pszMsg,
    338                       pSem, pSem->Owner, fibGetTidPid(), pSem->fs, pSem->flags, pSem->hev,
    339                       pSem->pszDesc);
     343    if (!fibIsInExit())
     344        __libc_Back_panic(0, NULL,
     345                          "fmutex deadlock: %s\n"
     346                          "%x: Owner=%x Self=%x fs=%x flags=%x hev=%x\n"
     347                          "            Desc=\"%s\"\n",
     348                          pszMsg,
     349                          pSem, pSem->Owner, fibGetTidPid(), pSem->fs, pSem->flags, pSem->hev,
     350                          pSem->pszDesc);
    340351}
    341352
     
    377388    {
    378389        FS_RESTORE();
    379         LIBCLOG_RETURN_UINT(rc);
     390        LIBCLOG_ERROR_RETURN_UINT(rc);
    380391    }
    381392
  • trunk/libc/src/libc/process/os2/fmutex-os2.c

    r2726 r3849  
    1717#define __LIBC_LOG_GROUP __LIBC_LOG_GRP_MUTEX
    1818#include <InnoTekLIBC/logstrict.h>
     19#include <InnoTekLIBC/thread.h>
    1920#include <InnoTekLIBC/backend.h>
    2021
     
    147148        for (;;)
    148149        {
    149             rc = DosWaitEventSem(sem->hev, sem->flags & _FMC_SHARED ? SEM_INDEFINITE_WAIT : 3000);
     150            ULONG cMsWait = sem->flags & _FMC_SHARED ? SEM_INDEFINITE_WAIT : 3000;
     151            if (fibIsInExit())
     152                cMsWait = 250;
     153            rc = DosWaitEventSem(sem->hev, cMsWait);
    150154            if (rc == ERROR_INTERRUPT)
    151155            {
     
    164168            if (rc != ERROR_TIMEOUT)
    165169                break;
     170
    166171            /*
    167172             * Deadlock detection - check if owner is around.
     
    178183            }
    179184        }
     185
    180186        FS_RESTORE();
    181187        if (rc != 0)
     
    200206    FS_SAVE_LOAD();
    201207    DosEnterMustComplete(&ulNesting);
     208#if 0 /** @todo lost signal / kernel boundrary */
     209    if (ulNesting == 1) /* This is a hack to catch lost poke signals. */
     210    {
     211        __LIBC_PTHREAD pThrd = __libc_threadCurrentNoAuto();
     212        if (pThrd && pThrd->fSigBeingPoked)
     213        {
     214            DosExitMustComplete(&ulNesting);
     215            __libc_Back_signalLostPoke();
     216            DosEnterMustComplete(&ulNesting);
     217        }
     218    }
     219#endif
    202220    fs = __cxchg(&sem->fs, _FMS_OWNED_SIMPLE);
    203221    if (fs == _FMS_AVAILABLE)
     
    214232        if (rc)
    215233        {
     234            DosExitMustComplete(&ulNesting);
    216235            LIBC_ASSERTM_FAILED("Failed to create event semaphore for fmutex '%s', rc=%d. flags=%#x\n", sem->pszDesc, rc, sem->flags);
    217236            FS_RESTORE();
     
    272291        for (;;)
    273292        {
    274             DosExitMustComplete(&ulNesting);
    275             rc = DosWaitEventSem(sem->hev, sem->flags & _FMC_SHARED ? SEM_INDEFINITE_WAIT : 3000);
     293            ULONG cMsWait = sem->flags & _FMC_SHARED ? SEM_INDEFINITE_WAIT : 3000;
     294            if (fibIsInExit())
     295                cMsWait = 250;
     296            DosExitMustComplete(&ulNesting);
     297            rc = DosWaitEventSem(sem->hev, cMsWait);
    276298            DosEnterMustComplete(&ulNesting);
    277299            if (rc == ERROR_INTERRUPT)
     
    291313            if (rc != ERROR_TIMEOUT)
    292314                break;
     315
    293316            /*
    294317             * Deadlock detection - check if owner is around.
     
    307330            }
    308331        }
     332
    309333        FS_RESTORE();
    310334        if (rc != 0)
     
    319343static void __fmutex_deadlock(_fmutex *pSem, const char *pszMsg)
    320344{
    321     __libc_Back_panic(0, NULL,
    322                       "fmutex deadlock: %s\n"
    323                       "%x: Owner=%x Self=%x fs=%x flags=%x hev=%x\n"
    324                       "            Desc=\"%s\"\n",
    325                       pszMsg,
    326                       pSem, pSem->Owner, fibGetTidPid(), pSem->fs, pSem->flags, pSem->hev,
    327                       pSem->pszDesc);
     345    if (!fibIsInExit())
     346        __libc_Back_panic(0, NULL,
     347                          "fmutex deadlock: %s\n"
     348                          "%x: Owner=%x Self=%x fs=%x flags=%x hev=%x\n"
     349                          "            Desc=\"%s\"\n",
     350                          pszMsg,
     351                          pSem, pSem->Owner, fibGetTidPid(), pSem->fs, pSem->flags, pSem->hev,
     352                          pSem->pszDesc);
    328353}
    329354
     
    332357    LIBCLOG_ENTER("sem=%p{.pszDesc=%s}\n", (void *)sem, sem->pszDesc);
    333358    ULONG ulNesting;
     359    int rc = 0;
    334360    __atomic_xchg(&sem->Owner, 0);
    335361    signed char fs = __cxchg(&sem->fs, _FMS_AVAILABLE);
    336     if (fs != _FMS_OWNED_HARD)
    337     {
    338         FS_VAR_SAVE_LOAD();
    339         DosExitMustComplete(&ulNesting);
    340         FS_RESTORE();
    341         LIBCLOG_RETURN_UINT(0);
    342     }
    343     else
    344     {
    345         int rc = __fmutex_release_internal (sem);
    346         FS_VAR_SAVE_LOAD();
    347         DosExitMustComplete(&ulNesting);
    348         FS_RESTORE();
    349         LIBCLOG_RETURN_UINT(rc);
    350     }
     362    if (fs == _FMS_OWNED_HARD)
     363        rc = __fmutex_release_internal (sem);
     364
     365    FS_VAR_SAVE_LOAD();
     366    DosExitMustComplete(&ulNesting);
     367    FS_RESTORE();
     368
     369    /* This is a hack to catch lost poke signals. */
     370#if 0 /** @todo lost signal / kernel boundrary */
     371    if (!ulNesting)
     372    {
     373        __LIBC_PTHREAD pThrd = __libc_threadCurrentNoAuto();
     374        if (pThrd && pThrd->fSigBeingPoked)
     375            __libc_Back_signalLostPoke();
     376    }
     377#endif
     378
     379    LIBCLOG_RETURN_UINT(rc);
    351380}
    352381
Note: See TracChangeset for help on using the changeset viewer.