VirtualBox

Changeset 13660 in vbox


Ignore:
Timestamp:
Oct 29, 2008 3:46:17 PM (16 years ago)
Author:
vboxsync
Message:

IPRT: RTThreadPoke update - don't use signal but sigaction (more well defined interface), make sure SIGUSR2 isn't masked on the threads and that it's interruptable (i.e. can interrupt sys calls).

File:
1 edited

Legend:

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

    r13653 r13660  
    4646#include <iprt/asm.h>
    4747#include <iprt/err.h>
     48#include <iprt/string.h>
    4849#include "internal/thread.h"
     50
     51
     52/*******************************************************************************
     53*   Defined Constants And Macros                                               *
     54*******************************************************************************/
     55/** The signal we're using for RTThreadPoke. */
     56#define RTTHREAD_POSIX_POKE_SIG  SIGUSR2
    4957
    5058
     
    7583    /*
    7684     * Register the dummy signal handler for RTThreadPoke.
    77      */
    78     void (*pfnOld)(int);
    79     pfnOld = signal(SIGUSR2, rtThreadPosixPokeSignal);
    80     Assert(pfnOld == SIG_DFL);
     85     * (Assert may explode here, but at least we'll notice.)
     86     */
     87    struct sigaction SigAct;
     88    memset(&SigAct, '\0', sizeof(SigAct));
     89    SigAct.sa_handler = rtThreadPosixPokeSignal;
     90    sigfillset(&SigAct.sa_mask);
     91    SigAct.sa_flags = 0;
     92
     93    struct sigaction SigActOld;
     94    if (!sigaction(RTTHREAD_POSIX_POKE_SIG, &SigAct, &SigActOld))
     95        Assert(SigActOld.sa_handler == SIG_DFL);
     96    else
     97    {
     98        rc = RTErrConvertFromErrno(errno);
     99        AssertMsgFailed(("rc=%Rrc errno=%d\n", rc, errno));
     100        pthread_key_delete(g_SelfKey);
     101        g_SelfKey = 0;
     102    }
    81103    return rc;
    82104}
     
    109131static void rtThreadPosixPokeSignal(int iSignal)
    110132{
    111     Assert(iSignal == SIGUSR2);
     133    Assert(iSignal == RTTHREAD_POSIX_POKE_SIG);
    112134    NOREF(iSignal);
    113135}
     
    130152    sigemptyset(&SigSet);
    131153    sigaddset(&SigSet, SIGALRM);
     154    sigdelset(&SigSet, RTTHREAD_POSIX_POKE_SIG);
    132155    sigprocmask(SIG_BLOCK, &SigSet, NULL);
     156    siginterrupt(RTTHREAD_POSIX_POKE_SIG, 1);
    133157
    134158    int rc = pthread_setspecific(g_SelfKey, pThread);
     
    154178    sigemptyset(&SigSet);
    155179    sigaddset(&SigSet, SIGALRM);
     180    sigdelset(&SigSet, RTTHREAD_POSIX_POKE_SIG);
    156181    sigprocmask(SIG_BLOCK, &SigSet, NULL);
     182    siginterrupt(RTTHREAD_POSIX_POKE_SIG, 1);
    157183
    158184    int rc = pthread_setspecific(g_SelfKey, pThread);
     
    302328    AssertReturn(pThread, VERR_INVALID_HANDLE);
    303329
    304     int rc = pthread_kill((pthread_t)(uintptr_t)pThread->Core.Key, SIGUSR2);
     330    int rc = pthread_kill((pthread_t)(uintptr_t)pThread->Core.Key, RTTHREAD_POSIX_POKE_SIG);
    305331
    306332    rtThreadRelease(pThread);
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