Changeset 3643 for branches


Ignore:
Timestamp:
May 18, 2008, 2:46:41 PM (17 years ago)
Author:
bird
Message:

Rewrote the active wait.

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

Legend:

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

    r2538 r3643  
    652652
    653653
    654 
    655 
    656654/**
    657655 * Gets the current process.
     
    696694 */
    697695__LIBC_PSPMPROCESS __libc_spmCreateEmbryo(pid_t pidParent);
     696
     697/**
     698 * Wait for a embryo to become a live process and complete
     699 * inheriting (file handles / sockets issues).
     700 *
     701 * @returns non-zero if the process has started.
     702 * @param   pEmbryo         The embry process.
     703 */
     704int __libc_spmWaitForChildToBecomeAlive(__LIBC_PSPMPROCESS pEmbryo);
    698705
    699706/**
  • branches/libc-0.6/src/emx/src/lib/sys/__spawnve.c

    r3636 r3643  
    514514
    515515                /*
    516                  * Delay a tiny bit while the child is starting up and doing the inheriting.
    517                  * If we figure that it's a libc child, we can wait a good deal longer.
    518                  */
    519                 /** @todo add a SPM notification for when inherit is completed. */
    520                 __LIBC_SPMLOADAVG LoadAvg;
    521                 unsigned uLoadAvgTS;
    522                 int fDoneInherit;
    523                 ULONG ulStart = fibGetMsCount();
    524                 rc = 0;
    525                 while (     (fDoneInherit = pEmbryo->enmState >= __LIBC_PROCSTATE_ALIVE
    526                                          || (pEmbryo->pInherit == NULL && pEmbryo->pInheritLocked == NULL)
    527                             ) == 0
    528                        &&   fibGetMsCount() - ulStart <= 8)
    529                 {
    530                     DosSleep(rc++ > 4);
    531                     __libc_spmGetLoadAvg(&LoadAvg, &uLoadAvgTS); /* SMP HACK */
    532                 }
    533                 if (    !fDoneInherit
    534                     &&  pEmbryo->enmState == __LIBC_PROCSTATE_ALIVE)
    535                 {
    536                     LIBCLOG_MSG("libc child - wait some more (rc=%d)\n", rc);
    537                     rc = 0;
    538                     __libc_spmGetLoadAvg(&LoadAvg, &uLoadAvgTS); /* SMP HACK */
    539                     while (     (fDoneInherit = pEmbryo->enmState >= __LIBC_PROCSTATE_ALIVE
    540                                              || (pEmbryo->pInherit == NULL && pEmbryo->pInheritLocked == NULL)
    541                                 ) == 0
    542                            &&   fibGetMsCount() - ulStart <= 100)
    543                     {
    544                         DosSleep(rc++ > 4);
    545                         __libc_spmGetLoadAvg(&LoadAvg, &uLoadAvgTS); /* SMP HACK */
    546                     }
    547                 }
    548                 LIBCLOG_MSG("fDoneInherit=%d rc=%d enmState=%d inh=%p,%p - waited %d ms\n",
    549                             fDoneInherit, rc, pEmbryo->enmState, pEmbryo->pInherit, pEmbryo->pInheritLocked, fibGetMsCount() - ulStart);
     516                 * Wait for the child to become active and complete the inhertining.
     517                 */
     518                int fDoneInherit = __libc_spmWaitForChildToBecomeAlive(pEmbryo);
     519                LIBCLOG_MSG("fDoneInherit=%d enmState=%d inh=%p,%p\n",
     520                            fDoneInherit, pEmbryo->enmState, pEmbryo->pInherit, pEmbryo->pInheritLocked);
    550521
    551522                /*
     
    620591                        {
    621592                            LIBCLOG_MSG("waiting some more...\n");
    622                             do
    623                             {
    624                                 DosSleep(!(rc++ % 3));
    625                                 __libc_spmGetLoadAvg(&LoadAvg, &uLoadAvgTS); /* SMP HACK */
    626                                 fDoneInherit = pEmbryo->enmState > __LIBC_PROCSTATE_ALIVE
    627                                             || (pEmbryo->pInherit == NULL && pEmbryo->pInheritLocked == NULL);
    628                             } while (!fDoneInherit
    629                                   && fibGetMsCount() - ulStart <= 200);
    630                             LIBCLOG_MSG("fDoneInherit=%d rc=%d enmState=%d inh=%p,%p - waited %d ms\n",
    631                                         fDoneInherit, rc, pEmbryo->enmState, pEmbryo->pInherit, pEmbryo->pInheritLocked, fibGetMsCount() - ulStart);
     593                            fDoneInherit = __libc_spmWaitForChildToBecomeAlive(pEmbryo);
     594                            LIBCLOG_MSG("fDoneInherit=%d enmState=%d inh=%p,%p\n",
     595                                        fDoneInherit, pEmbryo->enmState, pEmbryo->pInherit, pEmbryo->pInheritLocked);
    632596                        }
    633597
  • branches/libc-0.6/src/emx/src/lib/sys/sharedpm.c

    r3373 r3643  
    395395            DosGetInfoBlocks(&pTib, &pPib);
    396396            pProcess = spmRegisterSelf(pPib->pib_ulpid, pPib->pib_ulppid, pLIS->sgCurrent);
     397            if (pProcess)
     398            {
     399                LIBCLOG_MSG("posting %#lx\n", gpSPMHdr->hevNotify);
     400                APIRET rc2 = DosPostEventSem(gpSPMHdr->hevNotify);
     401                LIBC_ASSERTM(!rc2, "rc2=%ld!\n", rc2); rc2 = rc2;
     402            }
    397403            FS_RESTORE();
    398404        }
     
    485491            LIBC_ASSERTM(!gpSPMSelf->pInheritLocked, "Trying to free a locked inherit struct!\n");
    486492
     493            LIBCLOG_MSG("posting %#lx\n", gpSPMHdr->hevNotify);
     494            APIRET rc2 = DosPostEventSem(gpSPMHdr->hevNotify);
    487495            spmReleaseMutex(&RegRec);
     496            LIBC_ASSERTM(!rc2, "rc2=%ld!\n", rc2); rc2 = rc2;
    488497        }
    489498    }
     
    620629
    621630/**
     631 * Wait for a embryo to become a live process and complete
     632 * inheriting (file handles / sockets issues).
     633 *
     634 * @returns non-zero if the process has started.
     635 * @param   pEmbryo         The embry process.
     636 */
     637int __libc_spmWaitForChildToBecomeAlive(__LIBC_PSPMPROCESS pEmbryo)
     638{
     639    LIBCLOG_ENTER("pEmbryo=%p\n", pEmbryo);
     640    int                     cLoops;
     641    __LIBC_SPMXCPTREGREC    RegRec;
     642    ULONG                   ulIgnored;
     643    int                     fAlive = 0;
     644    APIRET                  rc = 0;
     645    ULONG                   ulStart = 0;
     646    DosQuerySysInfo(QSV_MS_COUNT, QSV_MS_COUNT, &ulStart, sizeof(ulStart));
     647
     648    /*
     649     * Wait for the process to become ready, 8 ms max.
     650     * However, if it becomes alive in that period we know it's a libc
     651     * process and will wait a bit more (130 ms) for it to finishing
     652     * initialization and inheritance.
     653     */
     654    for (cLoops = 0; ; cLoops++)
     655    {
     656        /*
     657         * Reset the notification event sem.
     658         */
     659        spmRequestMutex(&RegRec);
     660        fAlive = pEmbryo->enmState > __LIBC_PROCSTATE_ALIVE
     661              || (   pEmbryo->pInherit == NULL
     662                  && pEmbryo->pInheritLocked == NULL
     663                  && pEmbryo->enmState == __LIBC_PROCSTATE_ALIVE);
     664        if (!fAlive)
     665            DosResetEventSem(gpSPMHdr->hevNotify, &ulIgnored);
     666        spmReleaseMutex(&RegRec);
     667        if (fAlive)
     668            break; /* done */
     669
     670        /*
     671         * Calc the time we should sleep.
     672         */
     673        ULONG ulNow = 0;
     674        DosQuerySysInfo(QSV_MS_COUNT, QSV_MS_COUNT, &ulNow, sizeof(ulNow));
     675        ULONG ulSleep = ulNow - ulStart;
     676        if (ulSleep < 8)
     677        {
     678            ulSleep = 8 - ulSleep;
     679            LIBCLOG_MSG("wait %lu ms (cLoops=%d rc=%ld)\n", ulSleep, cLoops, rc);
     680        }
     681        else if (pEmbryo->enmState != __LIBC_PROCSTATE_ALIVE)
     682            break; /* giving up */
     683        else if (ulSleep < 130)
     684        {
     685            ulSleep = 130 - ulSleep;
     686            if (ulSleep > 8)
     687                ulSleep = 8; /* reset race protection */
     688            LIBCLOG_MSG("libc child - wait %lu ms (cLoops=%d rc=%ld)\n", ulSleep, cLoops, rc);
     689        }
     690        else
     691            break; /* giving up */
     692
     693        /*
     694         * Recheck before going to sleep on the event sem.
     695         */
     696        fAlive = pEmbryo->enmState > __LIBC_PROCSTATE_ALIVE
     697              || (   pEmbryo->pInherit == NULL
     698                  && pEmbryo->pInheritLocked == NULL
     699                  && pEmbryo->enmState == __LIBC_PROCSTATE_ALIVE);
     700        if (fAlive)
     701            break; /* done */
     702
     703        if (    gpSPMHdr->hevNotify
     704            &&  (rc == NO_ERROR || rc == ERROR_TIMEOUT || rc == ERROR_SEM_TIMEOUT))
     705            rc = DosWaitEventSem(gpSPMHdr->hevNotify, ulSleep);
     706        else
     707        {
     708            /* fallback if the sem is busted or for old libc initializing spm. */
     709            DosSleep(cLoops > 8);
     710
     711            __LIBC_SPMLOADAVG LoadAvg; /* SPM hack */
     712            __libc_spmSetLoadAvg(&LoadAvg);
     713        }
     714    }
     715    LIBCLOG_RETURN_INT(fAlive);
     716}
     717
     718
     719/**
    622720 * Searches for a process given by pid.
    623721 *
     
    21212219
    21222220    /*
    2123      * Check if initatied.
     2221     * Check if initiated.
    21242222     */
    21252223    if (!ghmtxSPM || !gpSPMHdr)
     
    23122410            if (!gpSPMHdr->cSigMaxActive)
    23132411                gpSPMHdr->cSigMaxActive = 1024;
     2412            if (gpSPMHdr->hevNotify)
     2413                rc = DosOpenEventSem(NULL, &gpSPMHdr->hevNotify);
     2414            else
     2415                rc = DosCreateEventSem(NULL, &gpSPMHdr->hevNotify, DC_SEM_SHARED, FALSE);
    23142416        }
    23152417        else
     
    23732475        {
    23742476            /*
    2375              * Register the current process and increment open counter.
     2477             * Register the current process, increment open counter,
     2478             * and notify everyone that spm data has changed.
    23762479             */
    23772480            PLINFOSEG pLIS = GETLINFOSEG();
    23782481            spmRegisterSelf(pPib->pib_ulpid, pPib->pib_ulppid, pLIS->sgCurrent);
    23792482            if (gpSPMSelf)
     2483            {
    23802484                gpSPMSelf->cSPMOpens++;
     2485
     2486                LIBCLOG_MSG("posting %#lx\n", gpSPMHdr->hevNotify);
     2487                APIRET rc2 = DosPostEventSem(gpSPMHdr->hevNotify);
     2488                LIBC_ASSERTM(!rc2, "rc2=%ld!\n", rc2); rc2 = rc2;
     2489            }
    23812490
    23822491            /*
     
    25582667                    *pParent->ppChildNotifyTail = pTerm;
    25592668                    pParent->ppChildNotifyTail = &pTerm->pNext;
    2560                     DosPostEventSem(gpSPMHdr->hevNotify);
     2669                   
     2670                    LIBCLOG_MSG("posting %#lx\n", gpSPMHdr->hevNotify);
     2671                    APIRET rc2 = DosPostEventSem(gpSPMHdr->hevNotify);
     2672                    LIBC_ASSERTM(!rc2, "rc2=%ld!\n", rc2); rc2 = rc2;
    25612673                }
    25622674                else
     
    31803292
    31813293                /* post notification sem. */
    3182                 DosPostEventSem(gpSPMHdr->hevNotify);
     3294                LIBCLOG_MSG("posting %#lx\n", gpSPMHdr->hevNotify);
     3295                APIRET rc2 = DosPostEventSem(gpSPMHdr->hevNotify);
     3296                LIBC_ASSERTM(!rc2, "rc2=%ld!\n", rc2); rc2 = rc2;
    31833297            }
    31843298            else
     
    33823496                    spmFreeProcess(pProcess);
    33833497                    pProcess = pProcessNext;
     3498                   
     3499                    /* Wake up the embryo waiters (paranoia). */
     3500                    LIBCLOG_MSG("posting %#lx\n", gpSPMHdr->hevNotify);
     3501                    APIRET rc2 = DosPostEventSem(gpSPMHdr->hevNotify);
     3502                    LIBC_ASSERTM(!rc2, "rc2=%ld!\n", rc2); rc2 = rc2;
    33843503                    continue;
    33853504                }
     
    34733592                        spmFreeProcess(pProcess);
    34743593                        pProcess = pProcessNext;
     3594                       
     3595                        /* Wake up the embryo waiters (paranoia). */
     3596                        LIBCLOG_MSG("posting %#lx\n", gpSPMHdr->hevNotify);
     3597                        APIRET rc2 = DosPostEventSem(gpSPMHdr->hevNotify);
     3598                        LIBC_ASSERTM(!rc2, "rc2=%ld!\n", rc2); rc2 = rc2;
    34753599                        continue;
    34763600                    }
Note: See TracChangeset for help on using the changeset viewer.