vbox的更動 65406 路徑 trunk/src/libs
- 時間撮記:
- 2017-1-23 下午03:47:55 (8 年 以前)
- 檔案:
-
- 修改 1 筆資料
圖例:
- 未更動
- 新增
- 刪除
-
trunk/src/libs/xpcom18a4/xpcom/glue/nsISupportsImpl.h
r1 r65406 50 50 51 51 #include "nsDebug.h" 52 #include "nsTraceRefcnt.h" 52 #include "nsTraceRefcnt.h" 53 #ifdef VBOX 54 # include "iprt/asm.h" 55 # include "iprt/assert.h" 56 #endif 53 57 54 58 //////////////////////////////////////////////////////////////////////////////// … … 80 84 81 85 public: 82 nsAutoRefCnt() : mValue(0) {} 86 nsAutoRefCnt() : mValue(0) 87 #ifdef VBOX 88 , mState(0) 89 #endif 90 {} 83 91 nsAutoRefCnt(nsrefcnt aValue) : mValue(aValue) {} 84 92 … … 86 94 nsrefcnt operator++() { return ++mValue; } 87 95 nsrefcnt operator--() { return --mValue; } 88 96 89 97 nsrefcnt operator=(nsrefcnt aValue) { return (mValue = aValue); } 90 98 operator nsrefcnt() const { return mValue; } 91 99 nsrefcnt get() const { return mValue; } 100 #ifdef VBOX 101 nsrefcnt *ref() { return &mValue; } 102 PRUint32 getState() const { return mState; } 103 PRUint32 *refState() { return &mState; } 104 #endif 92 105 private: 93 106 // do not define these to enforce the faster prefix notation … … 95 108 nsrefcnt operator--(int); 96 109 nsrefcnt mValue; 110 #ifdef VBOX 111 PRUint32 mState; 112 #endif 97 113 }; 98 114 … … 685 701 */ 686 702 703 #ifdef VBOX 704 #define NS_IMPL_THREADSAFE_ADDREF(_class) \ 705 NS_IMETHODIMP_(nsrefcnt) _class::AddRef(void) \ 706 { \ 707 nsrefcnt count = mRefCnt.get(); \ 708 PRUint32 state = mRefCnt.getState(); \ 709 AssertReleaseMsg( state <= 1 \ 710 && ( (state == 0 && count == 0) \ 711 || (state == 1 && count < PR_UINT32_MAX/2)), \ 712 ("AddRef: illegal refcnt=%u state=%d\n", count, state)); \ 713 switch (state) \ 714 { \ 715 case 0: \ 716 if (!ASMAtomicCmpXchgU32(mRefCnt.refState(), 1, 0)) \ 717 AssertReleaseMsgFailed(("AddRef: racing for first increment\n")); \ 718 count = ASMAtomicIncU32(mRefCnt.ref()); \ 719 AssertReleaseMsg(count == 1, \ 720 ("AddRef: unexpected refcnt=%u\n", count)); \ 721 break; \ 722 case 1: \ 723 count = ASMAtomicIncU32(mRefCnt.ref()); \ 724 AssertReleaseMsg(count <= PR_UINT32_MAX/2, \ 725 ("AddRef: unexpected refcnt=%u\n", count)); \ 726 break; \ 727 case 2: \ 728 AssertReleaseMsgFailed(("AddRef: freed object\n")); \ 729 break; \ 730 default: \ 731 AssertReleaseMsgFailed(("AddRef: garbage object\n")); \ 732 } \ 733 NS_LOG_ADDREF(this, count, #_class, sizeof(*this)); \ 734 return count; \ 735 } 736 #else 687 737 #define NS_IMPL_THREADSAFE_ADDREF(_class) \ 688 738 NS_IMETHODIMP_(nsrefcnt) _class::AddRef(void) \ … … 694 744 return count; \ 695 745 } 746 #endif 696 747 697 748 /** … … 700 751 */ 701 752 753 #ifdef VBOX 754 #define NS_IMPL_THREADSAFE_RELEASE(_class) \ 755 NS_IMETHODIMP_(nsrefcnt) _class::Release(void) \ 756 { \ 757 nsrefcnt count = mRefCnt.get(); \ 758 PRUint32 state = mRefCnt.getState(); \ 759 AssertReleaseMsg(state == 1 && count <= PR_UINT32_MAX/2, \ 760 ("Release: illegal refcnt=%u state=%d\n", count, state)); \ 761 switch (state) \ 762 { \ 763 case 0: \ 764 AssertReleaseMsgFailed(("Release: new object\n")); \ 765 break; \ 766 case 1: \ 767 count = ASMAtomicDecU32(mRefCnt.ref()); \ 768 AssertReleaseMsg(count < PR_UINT32_MAX/2, \ 769 ("Release: unexpected refcnt=%u\n", count)); \ 770 if (count == 0) \ 771 { \ 772 if (!ASMAtomicCmpXchgU32(mRefCnt.refState(), 2, 1)) \ 773 AssertReleaseMsgFailed(("Release: racing for state free\n")); \ 774 /* Use better stabilization: reserve everything with top bit set. */ \ 775 if (!ASMAtomicCmpXchgU32(mRefCnt.ref(), PR_UINT32_MAX/4*3, 0)) \ 776 AssertReleaseMsgFailed(("Release: racing for refcnt stabilize\n")); \ 777 NS_DELETEXPCOM(this); \ 778 } \ 779 break; \ 780 case 2: \ 781 AssertReleaseMsgFailed(("Release: freed object\n")); \ 782 break; \ 783 default: \ 784 AssertReleaseMsgFailed(("Release: garbage object\n")); \ 785 } \ 786 NS_LOG_RELEASE(this, count, #_class); \ 787 return count; \ 788 } 789 #else 702 790 #define NS_IMPL_THREADSAFE_RELEASE(_class) \ 703 791 NS_IMETHODIMP_(nsrefcnt) _class::Release(void) \ … … 716 804 return count; \ 717 805 } 806 #endif 718 807 719 808 #define NS_IMPL_THREADSAFE_ISUPPORTS0(_class) \
注意:
瀏覽 TracChangeset
來幫助您使用更動檢視器