Changeset 3102 for branches


Ignore:
Timestamp:
Apr 15, 2007, 5:27:12 AM (18 years ago)
Author:
bird
Message:

workaround for lost signals / thread pokes. Fixes #152.

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

Legend:

Unmodified
Added
Removed
  • branches/libc-0.6/src/emx/include/InnoTekLIBC/backend.h

    r2439 r3102  
    816816int __libc_Back_signalTimer(int iWhich, const struct itimerval *pValue, struct itimerval *pOldValue);
    817817
     818/**
     819 * This is a hack to deal with potentially lost thread pokes.
     820 *
     821 * For some reason or another we loose the async signal in some situations. It's
     822 * been observed happening after/when opening files (fopen), but it's not known
     823 * whether this is really related or not.
     824 */
     825void __libc_Back_signalLostPoke(void);
    818826
    819827
  • branches/libc-0.6/src/emx/src/lib/libc.def

    r2896 r3102  
    19581958    "__std_nanf" @1956
    19591959    "__std_nanl" @1957
     1960    "___libc_Back_signalLostPoke" @1958
    19601961
     1962
  • branches/libc-0.6/src/emx/src/lib/process/fmutex.c

    r2282 r3102  
    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
     
    200201    FS_SAVE_LOAD();
    201202    DosEnterMustComplete(&ulNesting);
     203    if (ulNesting == 1) /* This is a hack to catch lost poke signals. */
     204    {
     205        __LIBC_PTHREAD pThrd = __libc_threadCurrentNoAuto();
     206        if (pThrd && pThrd->fSigBeingPoked)
     207        {
     208            DosExitMustComplete(&ulNesting);
     209            __libc_Back_signalLostPoke();
     210            DosEnterMustComplete(&ulNesting);
     211        }
     212    }
    202213    fs = __cxchg(&sem->fs, _FMS_OWNED_SIMPLE);
    203214    if (fs == _FMS_AVAILABLE)
     
    214225        if (rc)
    215226        {
     227            DosExitMustComplete(&ulNesting);
    216228            LIBC_ASSERTM_FAILED("Failed to create event semaphore for fmutex '%s', rc=%d. flags=%#x\n", sem->pszDesc, rc, sem->flags);
    217229            FS_RESTORE();
     
    332344    LIBCLOG_ENTER("sem=%p{.pszDesc=%s}\n", (void *)sem, sem->pszDesc);
    333345    ULONG ulNesting;
     346
     347    int rc = 0;
    334348    __atomic_xchg(&sem->Owner, 0);
    335349    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     }
     350    if (fs == _FMS_OWNED_HARD)
     351        rc = __fmutex_release_internal (sem);
     352
     353    FS_VAR_SAVE_LOAD();
     354    DosExitMustComplete(&ulNesting);
     355    FS_RESTORE();
     356
     357    /* This is a hack to catch lost poke signals. */
     358    if (!ulNesting)
     359    {
     360        __LIBC_PTHREAD pThrd = __libc_threadCurrentNoAuto();
     361        if (pThrd && pThrd->fSigBeingPoked)
     362            __libc_Back_signalLostPoke();
     363    }
     364
     365    LIBCLOG_RETURN_UINT(rc);
    351366}
    352367
  • branches/libc-0.6/src/emx/src/lib/sys/signals.c

    r2518 r3102  
    24782478    if (!pThrdPoke->fSigBeingPoked)
    24792479    {
     2480        DosSuspendThread(pThrdPoke->tid);
    24802481        __atomic_xchg(&pThrdPoke->fSigBeingPoked, 1);
    24812482        int rc = DosKillThread(pThrdPoke->tid);
     2483        DosResumeThread(pThrdPoke->tid);
    24822484        if (rc)
     2485        {
     2486            __atomic_xchg(&pThrdPoke->fSigBeingPoked, 0);
    24832487            LIBC_ASSERTM_FAILED("DosKillThread(%d) -> rc=%d\n", pThrdPoke->tid, rc);
     2488        }
    24842489    }
    24852490
     
    25322537
    25332538    return -EINVAL;
     2539}
     2540
     2541
     2542/**
     2543 * This is a hack to deal with potentially lost thread pokes.
     2544 *
     2545 * For some reason or another we loose the async signal in some situations. It's
     2546 * been observed happening after/when opening files (fopen), but it's not known
     2547 * whether this is really related or not.
     2548 */
     2549void        __libc_Back_signalLostPoke(void)
     2550{
     2551    LIBCLOG_ENTER("\n");
     2552    __LIBC_PTHREAD pThrd = __libc_threadCurrentNoAuto();
     2553    if (pThrd && pThrd->fSigBeingPoked)
     2554    {
     2555        ULONG ulSigLastTS = pThrd->ulSigLastTS;
     2556        DosSleep(0);
     2557        if (    pThrd->fSigBeingPoked
     2558            &&  pThrd->ulSigLastTS == ulSigLastTS)
     2559        {
     2560            DosSleep(0);
     2561            if (    pThrd->fSigBeingPoked
     2562                &&  pThrd->ulSigLastTS == ulSigLastTS)
     2563            {
     2564
     2565                int rc = __libc_back_signalSemRequest();
     2566                if (!rc)
     2567                {
     2568                    if (    pThrd->fSigBeingPoked
     2569                        &&  pThrd->ulSigLastTS == ulSigLastTS)
     2570                    {
     2571                        /*
     2572                         * Clear the indicator and deliver signals (releaseing the semaphore).
     2573                         */
     2574                        __atomic_xchg(&pThrd->fSigBeingPoked, 0);
     2575                        signalDeliver(pThrd, 0, NULL);
     2576                        LIBCLOG_RETURN_VOID();
     2577                        return;
     2578                    }
     2579                    __libc_back_signalSemRelease();
     2580                }
     2581            }
     2582        }
     2583    }
     2584    LIBCLOG_RETURN_VOID();
    25342585}
    25352586
Note: See TracChangeset for help on using the changeset viewer.