Changeset 1631


Ignore:
Timestamp:
Nov 14, 2004, 8:03:24 PM (21 years ago)
Author:
bird
Message:

Bugfixing signals and stuff.

Location:
trunk/src/emx
Files:
12 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/emx/include/InnoTekLIBC/sharedpm.h

    • Property cvs2svn:cvs-rev changed from 1.17 to 1.18
    r1630 r1631  
    675675
    676676/**
     677
     678
     679
     680
     681
     682
     683
     684
     685
     686
     687
     688
    677689 * Identificators which can be obtained using __libc_spmGetId().
    678690 */
  • trunk/src/emx/src/lib/process/beginthr.c

    • Property cvs2svn:cvs-rev changed from 1.12 to 1.13
    r1630 r1631  
    101101    int rc = __libc_back_threadCreate(pfnStart, cbStack, pvArg, 0);
    102102    if (rc >= 0)
    103         LIBCLOG_RETURN_INT(-1);
     103        LIBCLOG_RETURN_INT();
    104104    errno = -rc;
    105105    LIBCLOG_RETURN_INT(-1);
  • trunk/src/emx/src/lib/process/waitpid.c

    • Property cvs2svn:cvs-rev changed from 1.5 to 1.6
    r1630 r1631  
    8484    /* do the call */
    8585    siginfo_t SigInfo = {0};
    86     int rc = waitid(P_ALL, 0, &SigInfo, WEXITED);
     86    int rc = waitid(P_ALL, 0, &SigInfo, WEXITED);
    8787    if (!rc)
    8888    {
     
    108108                           SigInfo.si_pid, SigInfo.si_pid, iStatus);
    109109    }
    110     errno = -rc;
    111     LIBCLOG_RETURN_INT(-1);
     110    LIBCLOG_RETURN_INT(rc);
    112111}
    113112
  • trunk/src/emx/src/lib/sys/__select.c

    • Property cvs2svn:cvs-rev changed from 1.6 to 1.7
    r1630 r1631  
    2727#include "libc-alias.h"
    2828#define INCL_FSMACROS
    29 #define INCL_DOSPROCESS
     29#define INCL_DOSSEMAPHORES
     30#define INCL_ERRORS
    3031#include <os2emx.h>
    3132#include <stdlib.h>
     
    3738#include <emx/syscalls.h>
    3839#include "syscalls.h"
     40
    3941
    4042
     
    4850    int rc;
    4951    if (!tv)
    50         rc = DosSleep(~0);
     52        rc = Dos);
    5153    else
    5254    {
     
    5456        if (!cMillies && tv->tv_usec)
    5557            cMillies = 1;
    56         rc = DosSleep(cMillies);
     58        rc = DoscMillies);
    5759    }
    5860    FS_RESTORE();
     
    6163     * Return.
    6264     */
    63     if (!rc)
     65    if (!rc)
    6466        return 0;
    6567    errno = __libc_native2errno(rc);
     
    174176        rc = pfnSelect(nfds, readfds, writefds, exceptfds, tv, &rc2);
    175177    }
    176     else if (tv)
    177     {
    178         FS_VAR();
    179         /* wait for the given amount of time. */
    180         rc2 = rc = 0;
    181         FS_SAVE_LOAD();
    182         DosSleep(tv->tv_sec * 1000 + tv->tv_usec / 1000);
    183         FS_RESTORE();
    184     }
    185178    else
    186179    {
  • trunk/src/emx/src/lib/sys/__spawnve.c

    • Property cvs2svn:cvs-rev changed from 1.12 to 1.13
    r1630 r1631  
    275275
    276276            /*
    277              * Notify the process waiter system.
    278              */
    279             __libc_back_processWaitNotifyExec();
    280 
    281             /*
    282277             * Create the process.
    283278             */
     
    290285                __atomic_cmpxchg32((volatile uint32_t *)(void *)&pEmbryo->pid, (uint32_t)resc.codeTerminate, 0);
    291286                LIBCLOG_MSG("Spawned pid=%04lx (%ld)\n", resc.codeTerminate, resc.codeTerminate);
     287
    292288
    293289                /* cleanup embryo and other stuff. */
  • trunk/src/emx/src/lib/sys/b_process.h

    • Property cvs2svn:cvs-rev changed from 1.1 to 1.2
    r1630 r1631  
    3737
    3838void __libc_back_processWaitNotifyTerm(void);
    39 void __libc_back_processWaitNotifyExec(void);
     39void __libc_back_processWaitNotifyExec(id);
    4040void __libc_back_processWaitNotifyChild(siginfo_t *pSigInfo);
    4141void __libc_back_processWaitNotifyNoWait(int fNoWaitStatus);
  • trunk/src/emx/src/lib/sys/b_processWait.c

    • Property cvs2svn:cvs-rev changed from 1.3 to 1.4
    r1630 r1631  
    8484
    8585
     86
     87
     88
     89
     90
     91
     92
     93
     94
     95
     96
     97
     98
    8699
    87100/*******************************************************************************
     
    102115/** Index into the preallocated nodes. */
    103116static volatile unsigned    giWaitPreAlloced;
     117
     118
     119
     120
     121
     122
     123
     124
    104125
    105126/** If this flag is set we don't care for wait status info.
     
    110131/** The event semaphore the callers are sleeping on. */
    111132static volatile HEV         ghevWait;
     133
     134
    112135
    113136/** Thread ID of the wait thread. */
    114137static volatile TID         gtidThread;
    115138/** Termination indicator. Used to help the wait thread terminate fast. */
    116 static volatile int         gfTerminate;
     139static volatile     gfTerminate;
    117140
    118141
     
    146169        if (rc)
    147170            abort();
     171
     172
     173
     174
    148175
    149176        /* done */
     
    164191    {
    165192        /* kill the thread */
    166         gfTerminate = TRUE;
     193        __atomic_xchg(&gfTerminate, 1);
     194        DosKillThread(gtidThread);
    167195        gtidThread = 0;
    168         DosKillThread(gtidThread);
    169 
    170         /* destroy the event semaphore. */
    171         HEV hev = ghevWait;
    172         ghevWait = NULLHANDLE;
    173         if (hev)
    174             DosPostEventSem(hev);
     196    }
     197
     198    /* destroy the birth event semaphore. */
     199    HEV hev = ghevBirth;
     200    ghevBirth = NULLHANDLE;
     201    if (hev)
     202    {
     203        DosPostEventSem(hev);
     204        DosCloseEventSem(hev);
     205    }
     206
     207    /* destroy the wait event semaphore. */
     208    hev = ghevWait;
     209    ghevWait = NULLHANDLE;
     210    if (hev)
     211    {
     212        DosPostEventSem(hev);
     213        DosCloseEventSem(hev);
    175214    }
    176215}
     
    218257    pWait->pNext = NULL;
    219258    pWait->pPrev = gpWaitTail;
    220     if (!pWait->pPrev)
     259    if (pWait->pPrev)
     260        pWait->pPrev->pNext = pWait;
     261    else
    221262        gpWaitHead = pWait;
    222263    gpWaitTail = pWait;
     
    233274    PTIB        pTib;
    234275    DosGetInfoBlocks(&pTib, &pPib);
     276
    235277
    236278    /*
     
    240282    for (;!gfTerminate;)
    241283    {
    242         for (;!gfTerminate;)
    243         {
     284        /*
     285         * Check for exit condition.
     286         */
     287        fInternalTerm = gfTerminate;
     288        if (pPib->pib_flstatus & (0x40/*dying*/ | 0x04/*exiting all*/ | 0x02/*Exiting Thread 1*/ | 0x01/*ExitList */))
     289        {
     290            LIBCLOG_MSG("Terminating thread, exit conditions detected. pib_flstatus=%#lx\n",  pPib->pib_flstatus);
     291            fInternalTerm = 1;
     292        }
     293
     294        /*
     295         * Wait for children.
     296         */
     297        WAITINFO Wait;
     298        int rc = waitChild(&Wait, fInternalTerm, 0 /* any child */);
     299        if (!rc)
     300        {
     301            /* enter semaphore protection. */
     302            rc = waitSemRequest(1);
     303
    244304            /*
    245              * Check for exit condition.
     305             *
    246306             */
    247             fInternalTerm = gfTerminate;
    248             if (pPib->pib_flstatus & (0x40/*dying*/ | 0x04/*exiting all*/ | 0x02/*Exiting Thread 1*/ | 0x01/*ExitList */))
     307            if (!gfNoWaitStatus)
     308                waitAllocInsert(&Wait);
     309
     310            /*
     311             * Increment death number and decrement number of (known) children.
     312             */
     313            __atomic_increment(&gcDeaths);
     314
     315            /*
     316             * Remove the child from the list.
     317             */
     318            PWAITCHILD pPrev = NULL;
     319            PWAITCHILD pChild = gpChildrenHead;
     320            while (pChild)
    249321            {
    250                 LIBCLOG_MSG("Terminating thread, exit conditions detected. pib_flstatus=%#lx\n",  pPib->pib_flstatus);
    251                 fInternalTerm = TRUE;
     322                if (pChild->pid == Wait.pid)
     323                {
     324                    if (pPrev)
     325                        pPrev->pNext = pChild->pNext;
     326                    else
     327                        gpChildrenHead = pChild->pNext;
     328                    __atomic_decrement_min(&gcChildren, 0);
     329                    break;
     330                }
     331
     332                /* next */
     333                pPrev = pChild;
     334                pChild = pChild->pNext;
    252335            }
    253336
    254337            /*
    255              * Wait for children.
     338             * Wa.
    256339             */
    257             WAITINFO Wait;
    258             int rc = waitChild(&Wait, fInternalTerm, 0 /* any child */);
     340            if (DosPostEventSem(ghevWait) == ERROR_INVALID_HANDLE)
     341                fInternalTerm = 1;
     342
     343            /*
     344             * Leave semaphore protection and wait again unless someone's hinting it's time to quit...
     345             */
    259346            if (!rc)
    260             {
    261                 /*
    262                  * Need we bother inserting it?
    263                  */
    264                 rc = waitSemRequest(1);
    265                 if (!rc && !gfNoWaitStatus)
    266                     rc = waitAllocInsert(&Wait);
    267 
    268                 /*
    269                  * Wake up any waiters.
    270                  */
    271                 int rcOS2 = DosPostEventSem(ghevWait);
    272                 if (!rc)
    273                     waitSemRelease();
    274                 if (rc || (rcOS2 && rcOS2 != ERROR_TOO_MANY_POSTS && rcOS2 != ERROR_ALREADY_POSTED))
    275                     fInternalTerm = 1;
    276                 rc = 0;
    277             }
    278             if (rc || fInternalTerm)
     347                waitSemRelease();
     348            if (fInternalTerm)
    279349                break;
    280         }
    281 
    282         /*
    283          * Check if we're encouraged to quit.
    284          */
    285         if (fInternalTerm || gfTerminate)
    286             break;
     350            continue;
     351        }
    287352
    288353        /*
     
    293358         * using the nowait option on the API call.
    294359         */
     360
     361
    295362        if (pPib->pib_flstatus & (0x40/*dying*/ | 0x04/*exiting all*/ | 0x02/*Exiting Thread 1*/ | 0x01/*ExitList */))
    296363        {
    297364            LIBCLOG_MSG("Terminating thread, exit conditions detected. pib_flstatus=%#lx\n",  pPib->pib_flstatus);
    298             fInternalTerm = TRUE;
     365            fInternalTerm = ;
    299366            continue;
    300367        }
    301368
    302         DosWaitEventSem(ghevWait, 30*1000);
     369        if (rc == ERROR_WAIT_NO_CHILDREN)
     370        {
     371            DosWaitEventSem(ghevBirth, 5*1000);
     372            ULONG cIgnore;
     373            if (DosResetEventSem(ghevBirth, &cIgnore) == ERROR_INVALID_HANDLE)
     374                fInternalTerm = 1;
     375        }
     376        else
     377            LIBC_ASSERTM_FAILED("waitChild -> rc=%d expected ERROR_WAIT_NO_CHILDREN!\n", rc);
    303378    }
    304379
     
    485560 * it's time to start collect child status codes.
    486561 */
    487 void __libc_back_processWaitNotifyExec(void)
    488 {
    489     if (gtidThread)
    490         return;
    491 
     562void __libc_back_processWaitNotifyExec(pid_t pid)
     563{
     564    PWAITCHILD pChild = _hmalloc(sizeof(*pChild));
    492565    waitSemRequest(0);
     566
     567
     568
     569
     570
     571
     572
     573
     574
     575
     576
     577
     578
     579
     580
     581
     582
     583
     584
    493585    if (!gtidThread)
    494586    {
     
    500592        {
    501593            gtidThread = tid;
    502             LIBCLOG_MSG2("Create waitThread! tid=%#x (%d)\n", tid, tid);
     594            LIBCLOG_MSG2("Create waitThread! tid=%#x (%d)\n", tid, tid);
    503595        }
    504596        else
     
    509601        }
    510602    }
     603
    511604    waitSemRelease();
    512605}
     
    530623    __atomic_xchg(&gfNoWaitStatus, fNoWaitStatus);
    531624}
     625
    532626
    533627/**
     
    571665            /* insert it */
    572666            waitInsertFIFO(pWait);
     667
    573668        }
    574669        else
     
    619714
    620715    /*
    621      * Make sure there is a worker around.
    622      */
    623     if (!gtidThread)
    624         __libc_back_processWaitNotifyExec();
    625 
    626     /*
    627716     * Validate options.
    628717     */
     
    676765        LIBCLOG_RETURN_MSG(rc, "%d mutex\n", rc);
    677766    unsigned    cIterations = 0;
     767
    678768    for (;; cIterations++)
    679769    {
     
    682772         */
    683773        WAITINFO    Wait;
     774
     775
     776
    684777        PWAITINFO   pInfo = gpWaitHead;
    685778        while (pInfo)