Changeset 4863 in vbox for trunk/src/libs/xpcom18a4/ipc/ipcd/extensions
- Timestamp:
- Sep 17, 2007 6:05:36 PM (17 years ago)
- Location:
- trunk/src/libs/xpcom18a4/ipc/ipcd/extensions/dconnect/src
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/libs/xpcom18a4/ipc/ipcd/extensions/dconnect/src/ipcDConnectService.cpp
r3821 r4863 991 991 DConnectStub *mCachedISupports; 992 992 993 // stack of reference counter values returned by AddRef made in CreateStub994 // (access must be protected using the ipcDConnectService::stubLock())993 // stack of reference counter values (protected by 994 // ipcDConnectService::StubLock()) 995 995 nsDeque mRefCntLevels; 996 996 }; … … 1005 1005 // time it passes an object over IPC. 1006 1006 1007 // NOTE: this function is to be called from DConnectInstance::CreateStub only! 1008 1007 1009 nsRefPtr <ipcDConnectService> dConnect (ipcDConnectService::GetInstance()); 1008 1010 NS_ASSERTION(dConnect, "no ipcDConnectService (uninitialized?)"); 1009 1011 if (!dConnect) 1010 1012 return 0; 1011 1012 nsAutoLock stubLock (dConnect->StubLock()); 1013 1013 1014 // dConnect->StubLock() must be already locked here by 1015 // DConnectInstance::CreateStub 1016 1014 1017 nsrefcnt count = AddRef(); 1015 1018 mRefCntLevels.Push((void *) count); … … 1031 1034 1032 1035 if (mDisconnected) 1033 return NS_ERROR_NOT_INITIALIZED; 1036 return NS_ERROR_NOT_INITIALIZED; 1037 1038 // we also need the stub lock which protects DConnectStub::mRefCntLevels and 1039 // ipcDConnectService::mStubs 1040 nsAutoLock stubLock (mStubLock); 1034 1041 1035 1042 DConnectStub *stub = nsnull; … … 1624 1631 #endif 1625 1632 1626 nsRefPtr <ipcDConnectService> dConnect (ipcDConnectService::GetInstance());1627 if (dConnect)1628 {1629 #ifdef NS_DEBUG1630 {1631 nsAutoLock stubLock (dConnect->StubLock());1632 NS_ASSERTION(mRefCntLevels.GetSize() == 0, "refcnt levels are still left");1633 }1634 #endif1635 dConnect->DeleteStub(this);1636 }1637 1638 1633 // release the cached nsISupports instance if it's not the same object 1639 1634 if (mCachedISupports != 0 && mCachedISupports != this) … … 1653 1648 DConnectStub::Release() 1654 1649 { 1655 nsrefcnt count = PR_AtomicDecrement((PRInt32 *)&mRefCnt); 1656 NS_LOG_RELEASE(this, count, "DConnectStub"); 1650 nsrefcnt count; 1657 1651 1658 1652 nsRefPtr <ipcDConnectService> dConnect (ipcDConnectService::GetInstance()); 1659 1653 if (dConnect) 1660 1654 { 1655 // lock the stub lock on every release to make sure that once the counter 1656 // drops to zero, we delete the stub from the set of stubs before a new 1657 // request to create a stub on other thread tries to find the existing 1658 // stub in the set (wchich could otherwise AddRef the object after it had 1659 // Released to zero and pass it to the client right before its 1660 // destruction). 1661 1661 nsAutoLock stubLock (dConnect->StubLock()); 1662 1662 1663 count = PR_AtomicDecrement((PRInt32 *)&mRefCnt); 1664 NS_LOG_RELEASE(this, count, "DConnectStub"); 1665 1663 1666 // mRefCntLevels may already be empty here (due to the "stabilize" trick below) 1664 1667 if (mRefCntLevels.GetSize() > 0) … … 1675 1678 mRefCntLevels.Pop(); 1676 1679 1680 if (0 == count) 1681 { 1682 // this is the last reference, remove from the set before we leave 1683 // the lock, to provide atomicity of these two operations 1684 dConnect->DeleteStub (this); 1685 1686 NS_ASSERTION(mRefCntLevels.GetSize() == 0, "refcnt levels are still left"); 1687 } 1688 1689 // leave the lock before sending a message 1677 1690 stubLock.unlock(); 1678 1691 … … 1692 1705 } 1693 1706 } 1707 } 1708 else 1709 { 1710 count = PR_AtomicDecrement((PRInt32 *)&mRefCnt); 1711 NS_LOG_RELEASE(this, count, "DConnectStub"); 1694 1712 } 1695 1713 … … 2322 2340 ipcDConnectService::ipcDConnectService() 2323 2341 : mLock(NULL) 2342 , mStubLock(NULL) 2324 2343 , mDisconnected(PR_TRUE) 2325 , mStubLock(NULL)2326 2344 , mStubQILock(NULL) 2327 2345 { … … 2383 2401 return NS_ERROR_OUT_OF_MEMORY; 2384 2402 2403 mStubLock = PR_NewLock(); 2404 if (!mStubLock) 2405 return NS_ERROR_OUT_OF_MEMORY; 2406 2385 2407 if (!mStubs.Init()) 2386 2408 return NS_ERROR_OUT_OF_MEMORY; … … 2389 2411 if (NS_FAILED(rv)) 2390 2412 return rv; 2391 2392 mStubLock = PR_NewLock();2393 if (!mStubLock)2394 return NS_ERROR_OUT_OF_MEMORY;2395 2413 2396 2414 mStubQILock = PR_NewLock(); … … 2621 2639 #endif 2622 2640 2623 nsAutoLock lock (mLock); 2624 2625 // this method is intended to be called only from DConnectStub destructor. 2641 // this method is intended to be called only from DConnectStub::Release(). 2626 2642 // the stub object is not deleted when removed from the table, because 2627 2643 // DConnectStub pointers are not owned by mStubs. … … 2629 2645 } 2630 2646 2647 // not currently used 2648 #if 0 2631 2649 PRBool 2632 2650 ipcDConnectService::FindStubAndAddRef(PRUint32 peer, const DConAddr instance, 2633 2651 DConnectStub **stub) 2634 2652 { 2635 nsAutoLock lock (mLock);2653 nsAutoLock stubLock (mStubLock); 2636 2654 2637 2655 PRBool result = mStubs.Get(DConnectStubKey::Key(peer, instance), stub); … … 2640 2658 return result; 2641 2659 } 2660 #endif 2642 2661 2643 2662 NS_IMPL_THREADSAFE_ISUPPORTS3(ipcDConnectService, ipcIDConnectService, -
trunk/src/libs/xpcom18a4/ipc/ipcd/extensions/dconnect/src/ipcDConnectService.h
r3821 r4863 228 228 229 229 NS_HIDDEN_(nsresult) CreateStub(const nsID &, PRUint32, DConAddr, DConnectStub **); 230 #if 0 230 231 NS_HIDDEN_(PRBool) FindStubAndAddRef(PRUint32, const DConAddr, DConnectStub **); 232 #endif 231 233 // public only for DConnectStub::~DConnectStub() 232 234 NS_HIDDEN_(void) DeleteStub(DConnectStub *); … … 269 271 nsCOMPtr<nsIInterfaceInfoManager> mIIM; 270 272 271 // lock to protect access to instance and stubsets and the disconnected flag273 // lock to protect access to instance sets and the disconnected flag 272 274 PRLock *mLock; 273 275 … … 279 281 DConnectInstanceSet mInstanceSet; 280 282 283 // lock to protect access to mStubs and DConnectStub::mRefCntLevels 284 // (also guards every DConnectStub::Release call to provide atomicity) 285 PRLock *mStubLock; 286 281 287 // table of remote object stubs allocated to communicate with peer's instances 282 288 DConnectStubMap mStubs; … … 288 294 PRUint32 mSelfID; 289 295 290 // global lock to protect access to DConnectStub internal data291 PRLock *mStubLock;292 293 296 // global lock to protect access to protect DConnectStub::QueryInterface() 294 297 // (we cannot use mStubLock because it isn't supposed to be held long,
Note:
See TracChangeset
for help on using the changeset viewer.