VirtualBox

Changeset 34174 in vbox for trunk/src/VBox/Runtime


Ignore:
Timestamp:
Nov 18, 2010 2:52:35 PM (14 years ago)
Author:
vboxsync
Message:

IPRT: Use prefer real-time signal over SIGUSR2 for RTThreadPoke. Try several ones before giving up.

Location:
trunk/src/VBox/Runtime
Files:
1 added
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/r3/posix/thread-posix.cpp

    r32914 r34174  
    5858#ifndef IN_GUEST
    5959/** The signal we're using for RTThreadPoke. */
    60 # define RTTHREAD_POSIX_POKE_SIG    SIGUSR2
     60# define RTTHREAD_POSIX_WITH_POKE    SIGUSR2
    6161#endif
    6262
     
    6767/** The pthread key in which we store the pointer to our own PRTTHREAD structure. */
    6868static pthread_key_t    g_SelfKey;
    69 #ifdef RTTHREAD_POSIX_POKE_SIG
    70 /** Set if we can poke a thread, clear if we cannot. */
    71 static bool             g_fCanPokeThread;
     69#ifdef RTTHREAD_POSIX_WITH_POKE
     70/** The signal we use for poking threads.
     71 * This is set to -1 if no available signal was found. */
     72static int              g_iSigPokeThread = -1;
    7273#endif
    7374
     
    9192        return VERR_NO_TLS_FOR_SELF;
    9293
    93 #ifdef RTTHREAD_POSIX_POKE_SIG
     94#ifdef RTTHREAD_POSIX_WITH_POKE
    9495    /*
    9596     * Try register the dummy signal handler for RTThreadPoke.
    96      */
    97     g_fCanPokeThread = false;
    98     struct sigaction SigActOld;
    99     if (!sigaction(RTTHREAD_POSIX_POKE_SIG, NULL, &SigActOld))
    100     {
    101         if (   SigActOld.sa_handler == SIG_DFL
    102             || SigActOld.sa_handler == rtThreadPosixPokeSignal)
     97     * Avoid SIGRTMIN thru SIGRTMIN+2 because of LinuxThreads.
     98     */
     99    static const int s_aiSigCandidates[] =
     100    {
     101# ifdef SIGRTMAX
     102        SIGRTMAX-3,
     103        SIGRTMAX-2,
     104        SIGRTMAX-1,
     105# endif
     106        SIGUSR2,
     107        SIGWINCH
     108    };
     109
     110    g_iSigPokeThread = -1;
     111    for (unsigned iSig = 0; iSig < RT_ELEMENTS(s_aiSigCandidates); iSig++)
     112    {
     113        struct sigaction SigActOld;
     114        if (!sigaction(s_aiSigCandidates[iSig], NULL, &SigActOld))
    103115        {
    104             struct sigaction SigAct;
    105             memset(&SigAct, '\0', sizeof(SigAct));
    106             SigAct.sa_handler = rtThreadPosixPokeSignal;
    107             sigfillset(&SigAct.sa_mask);
    108             SigAct.sa_flags = 0;
    109 
    110             /* ASSUMES no sigaction race... (lazy bird) */
    111             if (!sigaction(RTTHREAD_POSIX_POKE_SIG, &SigAct, NULL))
    112                 g_fCanPokeThread = true;
    113             else
     116            if (   SigActOld.sa_handler == SIG_DFL
     117                || SigActOld.sa_handler == rtThreadPosixPokeSignal)
    114118            {
     119                struct sigaction SigAct;
     120                RT_ZERO(SigAct);
     121                SigAct.sa_handler = rtThreadPosixPokeSignal;
     122                SigAct.sa_flags   = 0;
     123                sigfillset(&SigAct.sa_mask);
     124
     125                /* ASSUMES no sigaction race... (lazy bird) */
     126                if (!sigaction(s_aiSigCandidates[iSig], &SigAct, NULL))
     127                {
     128                    g_iSigPokeThread = s_aiSigCandidates[iSig];
     129                    break;
     130                }
    115131                AssertMsgFailed(("rc=%Rrc errno=%d\n", RTErrConvertFromErrno(errno), errno));
    116                 pthread_key_delete(g_SelfKey);
    117                 g_SelfKey = 0;
    118132            }
    119133        }
    120     }
    121     else
    122         AssertMsgFailed(("rc=%Rrc errno=%d\n", RTErrConvertFromErrno(errno), errno));
    123 #endif /* RTTHREAD_POSIX_POKE_SIG */
     134        else
     135            AssertMsgFailed(("rc=%Rrc errno=%d\n", RTErrConvertFromErrno(errno), errno));
     136    }
     137#endif /* RTTHREAD_POSIX_WITH_POKE */
    124138    return rc;
    125139}
     
    145159
    146160
    147 #ifdef RTTHREAD_POSIX_POKE_SIG
     161#ifdef RTTHREAD_POSIX_WITH_POKE
    148162/**
    149163 * Dummy signal handler for the poke signal.
     
    153167static void rtThreadPosixPokeSignal(int iSignal)
    154168{
    155     Assert(iSignal == RTTHREAD_POSIX_POKE_SIG);
     169    Assert(iSignal == g_iSigPokeThread);
    156170    NOREF(iSignal);
    157171}
     
    176190    sigaddset(&SigSet, SIGALRM);
    177191    sigprocmask(SIG_BLOCK, &SigSet, NULL);
    178 #ifdef RTTHREAD_POSIX_POKE_SIG
    179     if (g_fCanPokeThread)
    180         siginterrupt(RTTHREAD_POSIX_POKE_SIG, 1);
     192#ifdef RTTHREAD_POSIX_WITH_POKE
     193    if (g_iSigPokeThread != -1)
     194        siginterrupt(g_iSigPokeThread, 1);
    181195#endif
    182196
     
    212226    sigaddset(&SigSet, SIGALRM);
    213227    sigprocmask(SIG_BLOCK, &SigSet, NULL);
    214 #ifdef RTTHREAD_POSIX_POKE_SIG
    215     if (g_fCanPokeThread)
    216         siginterrupt(RTTHREAD_POSIX_POKE_SIG, 1);
     228#ifdef RTTHREAD_POSIX_WITH_POKE
     229    if (g_iSigPokeThread != -1)
     230        siginterrupt(g_iSigPokeThread, 1);
    217231#endif
    218232
     
    367381
    368382
    369 #ifdef RTTHREAD_POSIX_POKE_SIG
     383#ifdef RTTHREAD_POSIX_WITH_POKE
    370384RTDECL(int) RTThreadPoke(RTTHREAD hThread)
    371385{
     
    373387    PRTTHREADINT pThread = rtThreadGet(hThread);
    374388    AssertReturn(pThread, VERR_INVALID_HANDLE);
     389
    375390    int rc;
    376     if (g_fCanPokeThread)
    377     {
    378         rc = pthread_kill((pthread_t)(uintptr_t)pThread->Core.Key, RTTHREAD_POSIX_POKE_SIG);
     391    if (g_iSigPokeThread != -1)
     392    {
     393        rc = pthread_kill((pthread_t)(uintptr_t)pThread->Core.Key, g_iSigPokeThread);
    379394        rc = RTErrConvertFromErrno(rc);
    380395    }
  • trunk/src/VBox/Runtime/testcase/Makefile.kmk

    r34045 r34174  
    109109        tstTermCallbacks \
    110110        tstThread-1 \
     111        tstRTThreadPoke \
    111112        tstTime \
    112113        tstTime-2 \
     
    461462tstThread-1_SOURCES = tstThread-1.cpp
    462463
     464tstRTThreadPoke_TEMPLATE = VBOXR3TSTEXE
     465tstRTThreadPoke_SOURCES = tstRTThreadPoke.cpp
     466
    463467tstTime_SOURCES = tstTime.cpp
    464468
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette