Changeset 34174 in vbox for trunk/src/VBox/Runtime
- Timestamp:
- Nov 18, 2010 2:52:35 PM (14 years ago)
- 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 58 58 #ifndef IN_GUEST 59 59 /** The signal we're using for RTThreadPoke. */ 60 # define RTTHREAD_POSIX_ POKE_SIGSIGUSR260 # define RTTHREAD_POSIX_WITH_POKE SIGUSR2 61 61 #endif 62 62 … … 67 67 /** The pthread key in which we store the pointer to our own PRTTHREAD structure. */ 68 68 static 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. */ 72 static int g_iSigPokeThread = -1; 72 73 #endif 73 74 … … 91 92 return VERR_NO_TLS_FOR_SELF; 92 93 93 #ifdef RTTHREAD_POSIX_ POKE_SIG94 #ifdef RTTHREAD_POSIX_WITH_POKE 94 95 /* 95 96 * 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)) 103 115 { 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) 114 118 { 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 } 115 131 AssertMsgFailed(("rc=%Rrc errno=%d\n", RTErrConvertFromErrno(errno), errno)); 116 pthread_key_delete(g_SelfKey);117 g_SelfKey = 0;118 132 } 119 133 } 120 }121 else122 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 */ 124 138 return rc; 125 139 } … … 145 159 146 160 147 #ifdef RTTHREAD_POSIX_ POKE_SIG161 #ifdef RTTHREAD_POSIX_WITH_POKE 148 162 /** 149 163 * Dummy signal handler for the poke signal. … … 153 167 static void rtThreadPosixPokeSignal(int iSignal) 154 168 { 155 Assert(iSignal == RTTHREAD_POSIX_POKE_SIG);169 Assert(iSignal == g_iSigPokeThread); 156 170 NOREF(iSignal); 157 171 } … … 176 190 sigaddset(&SigSet, SIGALRM); 177 191 sigprocmask(SIG_BLOCK, &SigSet, NULL); 178 #ifdef RTTHREAD_POSIX_ POKE_SIG179 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); 181 195 #endif 182 196 … … 212 226 sigaddset(&SigSet, SIGALRM); 213 227 sigprocmask(SIG_BLOCK, &SigSet, NULL); 214 #ifdef RTTHREAD_POSIX_ POKE_SIG215 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); 217 231 #endif 218 232 … … 367 381 368 382 369 #ifdef RTTHREAD_POSIX_ POKE_SIG383 #ifdef RTTHREAD_POSIX_WITH_POKE 370 384 RTDECL(int) RTThreadPoke(RTTHREAD hThread) 371 385 { … … 373 387 PRTTHREADINT pThread = rtThreadGet(hThread); 374 388 AssertReturn(pThread, VERR_INVALID_HANDLE); 389 375 390 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); 379 394 rc = RTErrConvertFromErrno(rc); 380 395 } -
trunk/src/VBox/Runtime/testcase/Makefile.kmk
r34045 r34174 109 109 tstTermCallbacks \ 110 110 tstThread-1 \ 111 tstRTThreadPoke \ 111 112 tstTime \ 112 113 tstTime-2 \ … … 461 462 tstThread-1_SOURCES = tstThread-1.cpp 462 463 464 tstRTThreadPoke_TEMPLATE = VBOXR3TSTEXE 465 tstRTThreadPoke_SOURCES = tstRTThreadPoke.cpp 466 463 467 tstTime_SOURCES = tstTime.cpp 464 468
Note:
See TracChangeset
for help on using the changeset viewer.