Changeset 51941 in vbox
- Timestamp:
- Jul 8, 2014 5:50:10 PM (10 years ago)
- Location:
- trunk/src/VBox
- Files:
-
- 3 edited
-
HostDrivers/Support/win/SUPDrv-win.cpp (modified) (2 diffs)
-
Runtime/common/misc/once.cpp (modified) (11 diffs)
-
Runtime/common/rand/rand.cpp (modified) (9 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/HostDrivers/Support/win/SUPDrv-win.cpp
r51918 r51941 577 577 #endif 578 578 } 579 RTTermRunCallbacks(RTTERMREASON_UNLOAD, 0); 579 580 RTR0Term(); 580 581 } … … 614 615 supdrvNtProtectTerm(); 615 616 #endif 617 RTTermRunCallbacks(RTTERMREASON_UNLOAD, 0); 616 618 RTR0Term(); 617 619 vboxdrvNtDestroyDevices(); -
trunk/src/VBox/Runtime/common/misc/once.cpp
r48807 r51941 34 34 #include <iprt/asm.h> 35 35 #include <iprt/assert.h> 36 #include <iprt/critsect.h> 36 #ifdef IN_RING3 37 # include <iprt/critsect.h> 38 # define RTONCE_USE_CRITSECT_FOR_TERM 39 #elif defined(IN_RING0) 40 # include <iprt/spinlock.h> 41 # define RTONCE_USE_SPINLOCK_FOR_TERM 42 #else 43 # define RTONCE_NO_TERM 44 #endif 37 45 #include <iprt/err.h> 38 46 #include <iprt/initterm.h> … … 44 52 * Global Variables * 45 53 *******************************************************************************/ 46 #ifdef IN_RING3 47 54 #ifndef RTONCE_NO_TERM 48 55 /** For initializing the clean-up list code. */ 49 56 static RTONCE g_OnceCleanUp = RTONCE_INITIALIZER; 50 /** Critical section protecting the clean-up list. */ 57 /** Lock protecting the clean-up list. */ 58 #ifdef RTONCE_USE_CRITSECT_FOR_TERM 51 59 static RTCRITSECT g_CleanUpCritSect; 60 #else 61 static RTSEMFASTMUTEX g_hCleanUpLock; 62 #endif 52 63 /** The clean-up list. */ 53 64 static RTLISTANCHOR g_CleanUpList; 65 66 /** Locks the clean-up list. */ 67 #ifdef RTONCE_USE_CRITSECT_FOR_TERM 68 # define RTONCE_CLEANUP_LOCK() RTCritSectEnter(&g_CleanUpCritSect) 69 #else 70 # define RTONCE_CLEANUP_LOCK() RTSemFastMutexRequest(g_hCleanUpLock); 71 #endif 72 73 /** Unlocks the clean-up list. */ 74 #ifdef RTONCE_USE_CRITSECT_FOR_TERM 75 # define RTONCE_CLEANUP_UNLOCK() RTCritSectLeave(&g_CleanUpCritSect); 76 #else 77 # define RTONCE_CLEANUP_UNLOCK() RTSemFastMutexRelease(g_hCleanUpLock); 78 #endif 79 54 80 55 81 … … 58 84 { 59 85 bool const fLazyCleanUpOk = RTTERMREASON_IS_LAZY_CLEANUP_OK(enmReason); 60 RT CritSectEnter(&g_CleanUpCritSect);/* Potentially dangerous. */86 RTONCE_CLEANUP_LOCK(); /* Potentially dangerous. */ 61 87 62 88 PRTONCE pCur, pPrev; … … 87 113 } 88 114 89 RTCritSectLeave(&g_CleanUpCritSect); 90 NOREF(pvUser); NOREF(enmReason); NOREF(iStatus); 115 RTONCE_CLEANUP_UNLOCK(); 116 117 /* 118 * Reset our own structure and the critsect / mutex. 119 */ 120 if (!fLazyCleanUpOk) 121 { 122 # ifdef RTONCE_USE_CRITSECT_FOR_TERM 123 RTCritSectDelete(&g_CleanUpCritSect); 124 # else 125 RTSemFastMutexDestroy(g_hCleanUpLock); 126 g_hCleanUpLock = NIL_RTSEMFASTMUTEX; 127 # endif 128 129 ASMAtomicWriteS32(&g_OnceCleanUp.rc, VERR_INTERNAL_ERROR); 130 ASMAtomicWriteS32(&g_OnceCleanUp.iState, RTONCESTATE_UNINITIALIZED); 131 } 132 133 NOREF(pvUser); NOREF(iStatus); 91 134 } 92 135 … … 103 146 NOREF(pvUser); 104 147 RTListInit(&g_CleanUpList); 148 # ifdef RTONCE_USE_CRITSECT_FOR_TERM 105 149 int rc = RTCritSectInit(&g_CleanUpCritSect); 150 # else 151 int rc = RTSemFastMutexCreate(&g_hCleanUpLock); 152 # endif 106 153 if (RT_SUCCESS(rc)) 107 154 { … … 110 157 return rc; 111 158 159 # ifdef RTONCE_USE_CRITSECT_FOR_TERM 112 160 RTCritSectDelete(&g_CleanUpCritSect); 161 # else 162 RTSemFastMutexDestroy(g_hCleanUpLock); 163 g_hCleanUpLock = NIL_RTSEMFASTMUTEX; 164 # endif 113 165 } 114 166 return rc; 115 167 } 116 168 117 #endif /* IN_RING3 */ 118 119 169 #endif /* !RTONCE_NO_TERM */ 120 170 121 171 /** … … 262 312 , VERR_INTERNAL_ERROR); 263 313 264 #if ndef IN_RING3314 #ifdef RTONCE_NO_TERM 265 315 AssertReturn(!pfnCleanUp, VERR_NOT_SUPPORTED); 266 #else /* IN_RING3*/316 #else /* !RTONCE_NO_TERM */ 267 317 268 318 /* … … 275 325 return rc; 276 326 } 277 #endif /* IN_RING3*/327 #endif /* !RTONCE_NO_TERM */ 278 328 279 329 /* … … 290 340 ASMAtomicWriteS32(&pOnce->rc, rcOnce); 291 341 292 #if def IN_RING3342 #ifndef RTONCE_NO_TERM 293 343 /* 294 344 * Register clean-up if requested and we were successful. … … 296 346 if (pfnCleanUp && RT_SUCCESS(rcOnce)) 297 347 { 298 RTCritSectEnter(&g_CleanUpCritSect); 348 RTONCE_CLEANUP_LOCK(); 349 299 350 pOnce->pfnCleanUp = pfnCleanUp; 300 351 pOnce->pvUser = pvUser; 301 352 RTListAppend(&g_CleanUpList, &pOnce->CleanUpNode); 302 RTCritSectLeave(&g_CleanUpCritSect); 353 354 RTONCE_CLEANUP_UNLOCK(); 303 355 } 304 #endif 356 #endif /* !RTONCE_NO_TERM */ 305 357 306 358 /* … … 367 419 NOREF(iState); 368 420 369 #if def IN_RING3421 #ifndef RTONCE_NO_TERM 370 422 /* Unregister clean-up. */ 371 423 if (pOnce->pfnCleanUp) 372 424 { 373 RTCritSectEnter(&g_CleanUpCritSect); 425 RTONCE_CLEANUP_LOCK(); 426 374 427 RTListNodeRemove(&pOnce->CleanUpNode); 375 428 pOnce->pfnCleanUp = NULL; 376 429 pOnce->pvUser = NULL; 377 RTCritSectLeave(&g_CleanUpCritSect); 378 } 379 #endif /* IN_RING3 */ 430 431 RTONCE_CLEANUP_UNLOCK(); 432 } 433 #endif /* !RTONCE_NO_TERM */ 380 434 381 435 /* Do the same as RTONCE_INITIALIZER does. */ -
trunk/src/VBox/Runtime/common/rand/rand.cpp
r48935 r51941 81 81 82 82 83 /** 84 * Termination counterpart to rtRandInitOnce. 85 * 86 * @returns IPRT status code. 87 * @param pvUser Ignored. 88 * @param fLazyCleanUpOk Set if we're terminating the process. 89 */ 90 static DECLCALLBACK(void) rtRandTermOnce(void *pvUser, bool fLazyCleanUpOk) 91 { 92 if (!fLazyCleanUpOk) 93 { 94 RTRAND hRand = g_hRand; 95 g_hRand = NIL_RTRAND; 96 if (hRand != NIL_RTRAND) 97 { 98 int rc = RTRandAdvDestroy(hRand); 99 AssertRC(rc); 100 } 101 } 102 NOREF(pvUser); 103 } 104 105 83 106 RTDECL(void) RTRandBytes(void *pv, size_t cb) RT_NO_THROW 84 107 { 85 RTOnce (&g_rtRandOnce, rtRandInitOnce, NULL);108 RTOnceEx(&g_rtRandOnce, rtRandInitOnce, rtRandTermOnce, NULL); 86 109 RTRandAdvBytes(g_hRand, pv, cb); 87 110 } … … 91 114 RTDECL(uint32_t) RTRandU32Ex(uint32_t u32First, uint32_t u32Last) RT_NO_THROW 92 115 { 93 RTOnce (&g_rtRandOnce, rtRandInitOnce, NULL);116 RTOnceEx(&g_rtRandOnce, rtRandInitOnce, rtRandTermOnce, NULL); 94 117 return RTRandAdvU32Ex(g_hRand, u32First, u32Last); 95 118 } … … 99 122 RTDECL(uint32_t) RTRandU32(void) RT_NO_THROW 100 123 { 101 RTOnce (&g_rtRandOnce, rtRandInitOnce, NULL);124 RTOnceEx(&g_rtRandOnce, rtRandInitOnce, rtRandTermOnce, NULL); 102 125 return RTRandAdvU32(g_hRand); 103 126 } … … 107 130 RTDECL(int32_t) RTRandS32Ex(int32_t i32First, int32_t i32Last) RT_NO_THROW 108 131 { 109 RTOnce (&g_rtRandOnce, rtRandInitOnce, NULL);132 RTOnceEx(&g_rtRandOnce, rtRandInitOnce, rtRandTermOnce, NULL); 110 133 return RTRandAdvS32Ex(g_hRand, i32First, i32Last); 111 134 } … … 115 138 RTDECL(int32_t) RTRandS32(void) RT_NO_THROW 116 139 { 117 RTOnce (&g_rtRandOnce, rtRandInitOnce, NULL);140 RTOnceEx(&g_rtRandOnce, rtRandInitOnce, rtRandTermOnce, NULL); 118 141 return RTRandAdvS32(g_hRand); 119 142 } … … 123 146 RTDECL(uint64_t) RTRandU64Ex(uint64_t u64First, uint64_t u64Last) RT_NO_THROW 124 147 { 125 RTOnce (&g_rtRandOnce, rtRandInitOnce, NULL);148 RTOnceEx(&g_rtRandOnce, rtRandInitOnce, rtRandTermOnce, NULL); 126 149 return RTRandAdvU64Ex(g_hRand, u64First, u64Last); 127 150 } … … 131 154 RTDECL(uint64_t) RTRandU64(void) RT_NO_THROW 132 155 { 133 RTOnce (&g_rtRandOnce, rtRandInitOnce, NULL);156 RTOnceEx(&g_rtRandOnce, rtRandInitOnce, rtRandTermOnce, NULL); 134 157 return RTRandAdvU64(g_hRand); 135 158 } … … 139 162 RTDECL(int64_t) RTRandS64Ex(int64_t i64First, int64_t i64Last) RT_NO_THROW 140 163 { 141 RTOnce (&g_rtRandOnce, rtRandInitOnce, NULL);164 RTOnceEx(&g_rtRandOnce, rtRandInitOnce, rtRandTermOnce, NULL); 142 165 return RTRandAdvS64Ex(g_hRand, i64First, i64Last); 143 166 } … … 147 170 RTDECL(int64_t) RTRandS64(void) RT_NO_THROW 148 171 { 149 RTOnce (&g_rtRandOnce, rtRandInitOnce, NULL);172 RTOnceEx(&g_rtRandOnce, rtRandInitOnce, rtRandTermOnce, NULL); 150 173 return RTRandAdvS32(g_hRand); 151 174 }
Note:
See TracChangeset
for help on using the changeset viewer.

