- Timestamp:
- May 18, 2008, 2:46:41 PM (17 years ago)
- 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 652 652 653 653 654 655 656 654 /** 657 655 * Gets the current process. … … 696 694 */ 697 695 __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 */ 704 int __libc_spmWaitForChildToBecomeAlive(__LIBC_PSPMPROCESS pEmbryo); 698 705 699 706 /** -
branches/libc-0.6/src/emx/src/lib/sys/__spawnve.c
r3636 r3643 514 514 515 515 /* 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); 550 521 551 522 /* … … 620 591 { 621 592 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); 632 596 } 633 597 -
branches/libc-0.6/src/emx/src/lib/sys/sharedpm.c
r3373 r3643 395 395 DosGetInfoBlocks(&pTib, &pPib); 396 396 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 } 397 403 FS_RESTORE(); 398 404 } … … 485 491 LIBC_ASSERTM(!gpSPMSelf->pInheritLocked, "Trying to free a locked inherit struct!\n"); 486 492 493 LIBCLOG_MSG("posting %#lx\n", gpSPMHdr->hevNotify); 494 APIRET rc2 = DosPostEventSem(gpSPMHdr->hevNotify); 487 495 spmReleaseMutex(&RegRec); 496 LIBC_ASSERTM(!rc2, "rc2=%ld!\n", rc2); rc2 = rc2; 488 497 } 489 498 } … … 620 629 621 630 /** 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 */ 637 int __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 /** 622 720 * Searches for a process given by pid. 623 721 * … … 2121 2219 2122 2220 /* 2123 * Check if init atied.2221 * Check if initiated. 2124 2222 */ 2125 2223 if (!ghmtxSPM || !gpSPMHdr) … … 2312 2410 if (!gpSPMHdr->cSigMaxActive) 2313 2411 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); 2314 2416 } 2315 2417 else … … 2373 2475 { 2374 2476 /* 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. 2376 2479 */ 2377 2480 PLINFOSEG pLIS = GETLINFOSEG(); 2378 2481 spmRegisterSelf(pPib->pib_ulpid, pPib->pib_ulppid, pLIS->sgCurrent); 2379 2482 if (gpSPMSelf) 2483 { 2380 2484 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 } 2381 2490 2382 2491 /* … … 2558 2667 *pParent->ppChildNotifyTail = pTerm; 2559 2668 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; 2561 2673 } 2562 2674 else … … 3180 3292 3181 3293 /* 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; 3183 3297 } 3184 3298 else … … 3382 3496 spmFreeProcess(pProcess); 3383 3497 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; 3384 3503 continue; 3385 3504 } … … 3473 3592 spmFreeProcess(pProcess); 3474 3593 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; 3475 3599 continue; 3476 3600 }
Note:
See TracChangeset
for help on using the changeset viewer.