- Timestamp:
- Oct 25, 2021 2:27:59 PM (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/src-all/VirtualBoxTranslator.cpp
r91718 r92039 37 37 RTCRITSECTRW VirtualBoxTranslator::s_instanceRwLock; 38 38 VirtualBoxTranslator *VirtualBoxTranslator::s_pInstance = NULL; 39 static RTONCE g_tlsOnce = RTONCE_INITIALIZER; 39 40 static RTTLS g_idxTls = NIL_RTTLS; 40 41 … … 61 62 delete pCache; 62 63 } 64 } 65 66 67 /** 68 * @callback_method_impl{FNRTONCECLEANUP, Destroys TLS index during the process termination.} 69 */ 70 DECLCALLBACK(void) uninitTls(void *pvUser, bool fLazyCleanUpOk) 71 { 72 RT_NOREF(pvUser); 73 if (fLazyCleanUpOk && g_idxTls != NIL_RTTLS) 74 { 75 RTTlsFree(g_idxTls); 76 g_idxTls = NIL_RTTLS; 77 } 78 } 79 80 81 /** 82 * @callback_method_impl{FNRTONCE} 83 */ 84 static DECLCALLBACK(int32_t) initTls(void *pvUser) 85 { 86 RT_NOREF(pvUser); 87 RTTlsAllocEx(&g_idxTls, &freeThreadCache); 88 return VINF_SUCCESS; 63 89 } 64 90 … … 71 97 , m_hStrCache(NIL_RTSTRCACHE) 72 98 { 73 RTTlsAllocEx(&g_idxTls, &freeThreadCache);74 99 int rc = RTStrCacheCreate(&m_hStrCache, "API Translation"); 75 100 m_rcCache = rc; … … 90 115 RTTlsSet(g_idxTls, NULL); 91 116 } 92 RTTlsFree(g_idxTls);93 g_idxTls = NIL_RTTLS;94 117 } 95 118 … … 446 469 static LastTranslation *getTlsEntry() RT_NOEXCEPT 447 470 { 448 if (RT_LIKELY(g_idxTls != NIL_RTTLS)) 471 int rc = RTOnceEx(&g_tlsOnce, initTls, uninitTls, NULL); 472 if (RT_SUCCESS(rc) && RT_LIKELY(g_idxTls != NIL_RTTLS)) 449 473 { 450 474 LastTranslation *pEntry = (LastTranslation *)RTTlsGet(g_idxTls); … … 457 481 pEntry = new LastTranslation(); 458 482 pEntry->first = pEntry->second = ""; 459 intrc = RTTlsSet(g_idxTls, pEntry);483 rc = RTTlsSet(g_idxTls, pEntry); 460 484 if (RT_SUCCESS(rc)) 461 485 return pEntry;
Note:
See TracChangeset
for help on using the changeset viewer.