Changeset 1646


Ignore:
Timestamp:
Nov 17, 2004, 10:12:37 AM (21 years ago)
Author:
bird
Message:

timers.

Location:
trunk/src/emx/src/lib
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/emx/src/lib/libc.def

    • Property cvs2svn:cvs-rev changed from 1.79 to 1.80
    r1645 r1646  
    12671267    "__std_wait4" @1289
    12681268    "__std_getopt_long_only" @1290
     1269    "___libc_Back_signalTimer" @1291
     1270    "__std_getitimer" @1292
     1271    "__std_setitimer" @1293
  • trunk/src/emx/src/lib/process/getitimer.c

    • Property cvs2svn:cvs-rev changed from 1.1 to 1.2
    r1645 r1646  
    4646 * @param   pValue  Where to store the value.
    4747 */
    48 int getitimer(int iWhich, struct itimerval *pValue)
     48int _STD(getitimer)(int iWhich, struct itimerval *pValue)
    4949{
    5050    LIBCLOG_ENTER("iWhich=%d pValue=%p\n", iWhich, (void *)pValue);
  • trunk/src/emx/src/lib/sys/b_signal.h

    • Property cvs2svn:cvs-rev changed from 1.2 to 1.3
    r1645 r1646  
    6161int         __libc_back_signalInheritPack(__LIBC_PSPMINHSIG *ppSig, size_t *pcbSig);
    6262void        __libc_back_signalTimerNotifyTerm(void);
     63int         __libc_back_signalRaiseInternal(__LIBC_PTHREAD pThrd, int iSignalNo, const siginfo_t *pSigInfo, void *pvQueued, unsigned fFlags);
    6364
    6465
  • trunk/src/emx/src/lib/sys/b_signalTimer.c

    • Property cvs2svn:cvs-rev changed from 1.1 to 1.2
    r1645 r1646  
    3232#define INCL_BASE
    3333#define INCL_FSMACROS
     34#define INCL_DOSINFOSEG
    3435#define INCL_ERRORS
    3536#include <os2emx.h>
     
    8283
    8384    /*
     85     * Gather stuff we need.
     86     */
     87    __LIBC_PTHREAD pThrd = __libc_threadCurrent();
     88    LIBC_ASSERT(pThrd && pThrd->fInternalThread);
     89    GINFOSEG volatile *pGIS = GETGINFOSEG();
     90    LIBC_ASSERT(pGIS && pGIS->uchMajorVersion);
     91    PPIB pPib = NULL;
     92    PTIB pTib = NULL;
     93    int rc = DosGetInfoBlocks(&pTib, &pPib);
     94    LIBC_ASSERTM(rc == 0 && pPib && pPib->pib_ulpid && pTib && pTib->tib_ptib2->tib2_ultid, "DosGetInfoBlocks -> %d\n", rc);
     95
     96    /*
    8497     * Change the priority to TC to make the timer more accurate.
    8598     */
    86     int rc = DosSetPriority(PRTYS_THREAD, PRTYC_TIMECRITICAL, 0, 0);
     99    rc = DosSetPriority(PRTYS_THREAD, PRTYC_TIMECRITICAL, 0, 0);
    87100    LIBC_ASSERTM(rc == 0, "DosSetPriority(PRTYS_THREAD, PRTYC_TIMECRITICAL, 0, 0) -> %d\n", rc);
    88101
     
    104117            break;
    105118        }
     119        if (pPib->pib_flstatus & (0x40/*dying*/ | 0x04/*exiting all*/ | 0x02/*Exiting Thread 1*/ | 0x01/*ExitList */))
     120        {
     121            LIBCLOG_MSG("Timer worker stopping: pPib->pib_flstatus=%#02lx\n", pPib->pib_flstatus);
     122            break;
     123        }
    106124
    107125        /*
    108126         * Calc next.
    109127         */
    110         if (guInterval)
    111             __atomic_xchg(&guNext, signalTimerClock() + guInterval);
    112 
    113         /*
    114          * Re-arm timer.
    115          */
    116         int fArmed = gfArmed;
    117         if (gfOneShot)
    118         {
    119             __libc_back_signalSemRequest();
    120             if (gfOneShot && gfArmed)
     128        unsigned uTime = pGIS->msecs;
     129
     130        /*
     131         * Take the semaphore.
     132         * Recheck for termination afterwards.
     133         */
     134        int rc = __libc_back_signalSemRequest();
     135        if (rc)
     136        {
     137            LIBCLOG_MSG("Timer worker stopping: __libc_back_signalSemRequest() -> %d\n", rc);
     138            break;
     139        }
     140        if (gfTerminate)
     141        {
     142            __libc_back_signalSemRelease();
     143            LIBCLOG_MSG("Timer worker stopping: gfTerminate=%d\n", gfTerminate);
     144            break;
     145        }
     146        if (pPib->pib_flstatus & (0x40/*dying*/ | 0x04/*exiting all*/ | 0x02/*Exiting Thread 1*/ | 0x01/*ExitList */))
     147        {
     148            __libc_back_signalSemRelease();
     149            LIBCLOG_MSG("Timer worker stopping: pPib->pib_flstatus=%#02lx\n", pPib->pib_flstatus);
     150            break;
     151        }
     152
     153
     154        /*
     155         * Update guNext and if needed rearm the timer.
     156         */
     157        if (gfArmed)
     158        {
     159            if (!gfOneShot)
     160                __atomic_xchg(&guNext, uTime + guInterval);
     161            else
    121162            {
    122163                __atomic_xchg(&gfOneShot, 0);
     
    124165                if (guInterval)
    125166                {
    126                     __atomic_xchg(&guNext, signalTimerClock() + guInterval + 1);
     167                    /*
     168                     * Start a new timer.
     169                     * Note that we've not compensated for any delays, thus the 2nd SIGALRM may
     170                     * be a little bit later than the others. Should matter that much I hope...
     171                     */
     172                    __atomic_xchg(&guNext, pGIS->msecs + guInterval + 1);
    127173                    rc = DosStartTimer(guInterval, (HSEM)ghevTimer, (PHTIMER)&ghTimer);
    128174                    if (rc)
     175                    {
     176                        LIBC_ASSERTM_FAILED("DosStartTimer(%d,,) -> rc=%d\n", guInterval, rc);
    129177                        __atomic_xchg(&gfArmed, 0);
     178                    }
    130179                }
     180                /*
     181                 * It was a one shot setup, we're done.
     182                 */
    131183                else
    132184                    __atomic_xchg(&gfArmed, 0);
    133185            }
    134186
    135             __libc_back_signalSemRelease();
    136         }
    137 
    138         /*
    139          * Raise a SIGALRM.
    140          */
    141         if (fArmed)
    142         {
    143             rc = __libc_Back_signalRaise(SIGALRM, &SigInfo, NULL, 0);
     187            /*
     188             * Raise SIGALRM.
     189             */
     190            rc = __libc_back_signalRaiseInternal(pThrd, SIGALRM, &SigInfo, NULL, 0);
    144191            if (rc < 0)
    145                 LIBCLOG_MSG("__libc_Back_signalRaise -> %d\n", rc);
    146         }
     192                LIBCLOG_MSG("__libc_back_signalRaiseInternal -> %d\n", rc);
     193        }
     194
     195        /*
     196         * Done with the semaphore.
     197         */
     198        __libc_back_signalSemRelease();
    147199
    148200        /*
     
    158210        if (cCount > 1)
    159211            LIBCLOG_MSG("cCount=%ld missed=%ld shots!\n", cCount, cCount - 1);
    160     }
     212    } /* loop forever */
    161213
    162214    /*
  • trunk/src/emx/src/lib/sys/signals.c

    • Property cvs2svn:cvs-rev changed from 1.14 to 1.15
    r1645 r1646  
    961961    {
    962962        LIBC_ASSERTM_FAILED("Invalid signal %d\n", iSignalNo);
    963         return -EINVAL;
     963        LIBCLOG_RETURN_INT(-EINVAL);
    964964    }
    965965
     
    974974        {
    975975            LIBC_ASSERTM_FAILED("No thread structure and we cannot safely create one!\n");
    976             return __LIBC_BSRR_PASSITON | (__SIGSET_ISSET(&__libc_gSignalRestartMask, iSignalNo) ? __LIBC_BSRR_RESTART : __LIBC_BSRR_INTERRUPT);
     976            int rc = __LIBC_BSRR_PASSITON | (__SIGSET_ISSET(&__libc_gSignalRestartMask, iSignalNo) ? __LIBC_BSRR_RESTART : __LIBC_BSRR_INTERRUPT);
     977            LIBCLOG_RETURN_INT(rc);
    977978        }
    978979        pThrd = __libc_threadCurrent();
     
    980981        {
    981982            LIBC_ASSERTM_FAILED("Failed to get thread structure!\n");
    982             return -ENOMEM;
     983            LIBCLOG_RETURN_INT(-ENOMEM);
    983984        }
    984985    }
     
    10371038    return rc;
    10381039}
     1040
     1041
     1042/**
     1043 * Schedules a signal generated by an internal worker thread.
     1044 *
     1045 * @returns 0 on success.
     1046 * @returns On failure a negative error code (errno.h) is returned.
     1047 * @param   pThrd               The current thread.
     1048 * @param   iSignalNo           Signal to raise.
     1049 * @param   pSigInfo            Pointer to signal info for this signal.
     1050 *                              NULL is allowed.
     1051 * @param   pvQueued            If __LIBC_BSRF_QUEUED is set, can optionally point to
     1052 *                              locally malloced SIGQUEUED node.
     1053 * @param   fFlags              Flags of the #defines __LIBC_BSRF_* describing how to
     1054 *                              deliver the signal.
     1055 */
     1056int __libc_back_signalRaiseInternal(__LIBC_PTHREAD pThrd, int iSignalNo, const siginfo_t *pSigInfo, void *pvQueued, unsigned fFlags)
     1057{
     1058    LIBCLOG_ENTER("pThrd=%p{.tid=%#x} iSignalNo=%d pSigInfo=%p{.si_signo=%d, .si_errno=%d, .si_code=%#x, .si_timestamp=%#x, .si_flags=%#x .si_pid=%#x, .si_pgrp=%#x, .si_tid=%#x, .si_uid=%d, .si_status=%d, .si_addr=%p, .si_value=%p, .si_band=%ld, .si_fd=%d} pvQueued=%p fFlags=%#x\n",
     1059                  (void *)pThrd, pThrd->tid,
     1060                  iSignalNo, (void *)pSigInfo,
     1061                  pSigInfo ? pSigInfo->si_signo : 0,
     1062                  pSigInfo ? pSigInfo->si_errno : 0,
     1063                  pSigInfo ? pSigInfo->si_code : 0,
     1064                  pSigInfo ? pSigInfo->si_timestamp : 0,
     1065                  pSigInfo ? pSigInfo->si_flags : 0,
     1066                  pSigInfo ? pSigInfo->si_pid : 0,
     1067                  pSigInfo ? pSigInfo->si_pgrp : 0,
     1068                  pSigInfo ? pSigInfo->si_tid : 0,
     1069                  pSigInfo ? pSigInfo->si_uid : 0,
     1070                  pSigInfo ? pSigInfo->si_status : 0,
     1071                  pSigInfo ? pSigInfo->si_addr : 0,
     1072                  pSigInfo ? pSigInfo->si_value.sigval_ptr : 0,
     1073                  pSigInfo ? pSigInfo->si_band : 0,
     1074                  pSigInfo ? pSigInfo->si_fd : 0,
     1075                  (void *)pvQueued, fFlags);
     1076
     1077    /*
     1078     * Can't be to careful!
     1079     */
     1080    LIBC_ASSERT(__libc_back_signalSemIsOwner());
     1081    LIBC_ASSERT(pThrd->fInternalThread);
     1082    if (!__SIGSET_SIG_VALID(iSignalNo) || iSignalNo == 0)
     1083    {
     1084        LIBC_ASSERTM_FAILED("Invalid signal %d\n", iSignalNo);
     1085        LIBCLOG_RETURN_INT(-EINVAL);
     1086    }
     1087
     1088    /*
     1089     * Copy the siginfo structure and fill in the rest of
     1090     * the SigInfo packet (if we've got one).
     1091     */
     1092    siginfo_t SigInfo;
     1093    SigInfo = *pSigInfo;
     1094    if (!SigInfo.si_timestamp)
     1095        SigInfo.si_timestamp = signalTimestamp();
     1096    if (fFlags & __LIBC_BSRF_QUEUED)
     1097        SigInfo.si_flags |= __LIBC_SI_QUEUED;
     1098    if (!SigInfo.si_pid)
     1099        SigInfo.si_pid = _sys_pid;
     1100    if (!SigInfo.si_tid)
     1101        SigInfo.si_tid = pThrd->tid;
     1102
     1103    /*
     1104     * Schedule the signal.
     1105     */
     1106    int rc = signalSchedule(pThrd, iSignalNo, &SigInfo, fFlags, fFlags & __LIBC_BSRF_QUEUED ? pvQueued : NULL);
     1107
     1108    LIBCLOG_RETURN_INT(rc);
     1109}
     1110
    10391111
    10401112
Note: See TracChangeset for help on using the changeset viewer.