Changeset 5501 in vbox for trunk/src/VBox/Main/glue
- Timestamp:
- Oct 25, 2007 10:37:58 AM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/glue/initterm.cpp
r4862 r5501 23 23 #include <stdlib.h> 24 24 25 /* XPCOM_GLUE is defined when the client uses the standalone glue 26 * (i.e. dynamically picks up the existing XPCOM shared library installation). 27 * This is not the case for VirtualBox XPCOM clients (they are always 28 * distrubuted with the self-built XPCOM library, and therefore have a binary 29 * dependency on it) but left here for clarity. 30 */ 31 #if defined (XPCOM_GLUE) 25 32 #include <nsXPCOMGlue.h> 33 #endif 34 26 35 #include <nsIComponentRegistrar.h> 27 36 #include <nsIServiceManager.h> … … 40 49 #include <iprt/string.h> 41 50 #include <iprt/env.h> 51 #include <iprt/asm.h> 42 52 43 53 #include <VBox/err.h> … … 164 174 } 165 175 176 /** 177 * Global XPCOM initialization flag (we maintain it ourselves since XPCOM 178 * doesn't provide such functionality) 179 */ 180 static bool gIsXPCOMInitialized = false; 181 182 /** 183 * Number of Initialize() calls on the main thread. 184 */ 185 static unsigned int gXPCOMInitCount = 0; 186 166 187 #endif /* defined (VBOX_WITH_XPCOM) */ 188 167 189 168 190 HRESULT Initialize() … … 253 275 #else /* !defined (VBOX_WITH_XPCOM) */ 254 276 277 if (ASMAtomicXchgBool (&gIsXPCOMInitialized, true) == true) 278 { 279 /* XPCOM is already initialized on the main thread, no special 280 * initialization is necessary on additional threads. Just increase 281 * the init counter if it's a main thread again (to correctly support 282 * nested calls to Initialize()/Shutdown() for compatibility with 283 * Win32). */ 284 285 nsCOMPtr <nsIEventQueue> eventQ; 286 rc = NS_GetMainEventQ (getter_AddRefs (eventQ)); 287 288 if (NS_SUCCEEDED (rc)) 289 { 290 PRBool isOnMainThread = PR_FALSE; 291 rc = eventQ->IsOnCurrentThread (&isOnMainThread); 292 if (NS_SUCCEEDED (rc) && isOnMainThread) 293 ++ gXPCOMInitCount; 294 } 295 296 AssertComRC (rc); 297 return rc; 298 } 299 300 /* this is the first initialization */ 301 gXPCOMInitCount = 1; 302 255 303 /* Set VBOX_XPCOM_HOME if not present */ 256 304 if (!RTEnvExist ("VBOX_XPCOM_HOME")) … … 272 320 } 273 321 274 nsCOMPtr <nsIEventQueue> eventQ; 275 rc = NS_GetMainEventQ (getter_AddRefs (eventQ)); 276 if (rc == NS_ERROR_NOT_INITIALIZED) 277 { 278 XPCOMGlueStartup (nsnull); 279 280 nsCOMPtr <DirectoryServiceProvider> dsProv; 281 282 /* prepare paths for registry files */ 283 char homeDir [RTPATH_MAX]; 284 char privateArchDir [RTPATH_MAX]; 285 int vrc = GetVBoxUserHomeDirectory (homeDir, sizeof (homeDir)); 286 if (RT_SUCCESS (vrc)) 287 vrc = RTPathAppPrivateArch (privateArchDir, sizeof (privateArchDir)); 288 if (RT_SUCCESS (vrc)) 289 { 290 char compReg [RTPATH_MAX]; 291 char xptiDat [RTPATH_MAX]; 292 char compDir [RTPATH_MAX]; 293 294 RTStrPrintf (compReg, sizeof (compReg), "%s%c%s", 295 homeDir, RTPATH_DELIMITER, "compreg.dat"); 296 RTStrPrintf (xptiDat, sizeof (xptiDat), "%s%c%s", 297 homeDir, RTPATH_DELIMITER, "xpti.dat"); 298 RTStrPrintf (compDir, sizeof (compDir), "%s%c/components", 299 privateArchDir, RTPATH_DELIMITER); 300 301 dsProv = new DirectoryServiceProvider(); 302 if (dsProv) 303 rc = dsProv->init (compReg, xptiDat, compDir, privateArchDir); 304 else 305 rc = NS_ERROR_OUT_OF_MEMORY; 306 } 322 #if defined (XPCOM_GLUE) 323 XPCOMGlueStartup (nsnull); 324 #endif 325 326 nsCOMPtr <DirectoryServiceProvider> dsProv; 327 328 /* prepare paths for registry files */ 329 char homeDir [RTPATH_MAX]; 330 char privateArchDir [RTPATH_MAX]; 331 int vrc = GetVBoxUserHomeDirectory (homeDir, sizeof (homeDir)); 332 if (RT_SUCCESS (vrc)) 333 vrc = RTPathAppPrivateArch (privateArchDir, sizeof (privateArchDir)); 334 if (RT_SUCCESS (vrc)) 335 { 336 char compReg [RTPATH_MAX]; 337 char xptiDat [RTPATH_MAX]; 338 char compDir [RTPATH_MAX]; 339 340 RTStrPrintf (compReg, sizeof (compReg), "%s%c%s", 341 homeDir, RTPATH_DELIMITER, "compreg.dat"); 342 RTStrPrintf (xptiDat, sizeof (xptiDat), "%s%c%s", 343 homeDir, RTPATH_DELIMITER, "xpti.dat"); 344 RTStrPrintf (compDir, sizeof (compDir), "%s%c/components", 345 privateArchDir, RTPATH_DELIMITER); 346 347 LogFlowFunc (("component registry : \"%s\"\n", compReg)); 348 LogFlowFunc (("XPTI data file : \"%s\"\n", xptiDat)); 349 LogFlowFunc (("component directory : \"%s\"\n", compDir)); 350 351 dsProv = new DirectoryServiceProvider(); 352 if (dsProv) 353 rc = dsProv->init (compReg, xptiDat, compDir, privateArchDir); 307 354 else 308 rc = NS_ERROR_FAILURE; 309 355 rc = NS_ERROR_OUT_OF_MEMORY; 356 } 357 else 358 rc = NS_ERROR_FAILURE; 359 360 if (NS_SUCCEEDED (rc)) 361 { 310 362 /* get the path to the executable */ 311 363 nsCOMPtr <nsIFile> appDir; … … 395 447 * StopAcceptingEvents() on the main event queue). */ 396 448 397 BOOL isOnMainThread =FALSE;449 PRBool isOnMainThread = PR_FALSE; 398 450 if (NS_SUCCEEDED (rc)) 399 451 { 400 452 rc = eventQ->IsOnCurrentThread (&isOnMainThread); 401 eventQ = nsnull; /* early release */453 eventQ = nsnull; /* early release before shutdown */ 402 454 } 403 455 else 404 456 { 405 isOnMainThread = TRUE;457 isOnMainThread = PR_TRUE; 406 458 rc = NS_OK; 407 459 } … … 409 461 if (NS_SUCCEEDED (rc) && isOnMainThread) 410 462 { 411 /* only the main thread needs to uninitialize XPCOM */ 412 rc = NS_ShutdownXPCOM (nsnull); 413 XPCOMGlueShutdown(); 463 /* only the main thread needs to uninitialize XPCOM and only if 464 * init counter drops to zero */ 465 if (-- gXPCOMInitCount == 0) 466 { 467 rc = NS_ShutdownXPCOM (nsnull); 468 469 /* This is a thread initialized XPCOM and set gIsXPCOMInitialized to 470 * true. Reset it back to false. */ 471 bool wasInited = ASMAtomicXchgBool (&gIsXPCOMInitialized, false); 472 Assert (wasInited == true); 473 NOREF (wasInited); 474 475 #if defined (XPCOM_GLUE) 476 XPCOMGlueShutdown(); 477 #endif 478 } 414 479 } 415 480 }
Note:
See TracChangeset
for help on using the changeset viewer.