From bd0c22ce9f7d0effcb2a38e64d71c500470d819f Mon Sep 17 00:00:00 2001 From: szv Date: Fri, 24 May 2013 09:26:45 +0400 Subject: [PATCH] 0023988: Force use of reentrant mode Reentrant mode switch is eliminated --- src/IGESControl/IGESControl_Reader.cxx | 1 - src/MeshTest/MeshTest.cxx | 2 - src/MeshTest/MeshTest_PluginCommands.cxx | 2 - src/NCollection/NCollection_BaseAllocator.cxx | 7 +--- src/NCollection/NCollection_IncAllocator.cxx | 14 ++----- src/Standard/Standard.cdl | 20 ---------- src/Standard/Standard.cxx | 30 +------------- src/Standard/Standard_ErrorHandler.cxx | 21 ++++------ src/Standard/Standard_MMgrOpt.cxx | 40 +++++++------------ src/Standard/Standard_MMgrOpt.hxx | 9 +---- src/Standard/Standard_MMgrRoot.cxx | 9 ----- src/Standard/Standard_MMgrRoot.hxx | 6 --- src/XSDRAWSTLVRML/XSDRAWSTLVRML.cxx | 4 +- 13 files changed, 30 insertions(+), 135 deletions(-) diff --git a/src/IGESControl/IGESControl_Reader.cxx b/src/IGESControl/IGESControl_Reader.cxx index bd412a6aa8..f2f25c27fb 100755 --- a/src/IGESControl/IGESControl_Reader.cxx +++ b/src/IGESControl/IGESControl_Reader.cxx @@ -49,7 +49,6 @@ #include #include #include -#include #include #include #include diff --git a/src/MeshTest/MeshTest.cxx b/src/MeshTest/MeshTest.cxx index 5142232313..d1af84b07b 100755 --- a/src/MeshTest/MeshTest.cxx +++ b/src/MeshTest/MeshTest.cxx @@ -208,8 +208,6 @@ static Standard_Integer incrementalmesh(Draw_Interpretor& di, Standard_Integer n di << "Incremental Mesh, multi-threading " << (isInParallel ? "ON\n" : "OFF\n"); - Standard::SetReentrant(isInParallel); - BRepMesh_IncrementalMesh MESH(aShape, aDeflection, Standard_False, 0.5, isInParallel); Standard_Integer statusFlags = MESH.GetStatusFlags(); diff --git a/src/MeshTest/MeshTest_PluginCommands.cxx b/src/MeshTest/MeshTest_PluginCommands.cxx index 7e33ef5cdd..99b22e45aa 100755 --- a/src/MeshTest/MeshTest_PluginCommands.cxx +++ b/src/MeshTest/MeshTest_PluginCommands.cxx @@ -529,8 +529,6 @@ static int mpparallel (Draw_Interpretor& di, Standard_Integer argc, const char** { Standard_Boolean isParallelOn = Draw::Atoi (argv[1]) == 1; BRepMesh_IncrementalMesh::SetParallelDefault (isParallelOn); - if (isParallelOn) - Standard::SetReentrant(Standard_True); } std::cout << "Incremental Mesh, multi-threading " << (BRepMesh_IncrementalMesh::IsParallelDefault() ? "ON\n" : "OFF\n"); diff --git a/src/NCollection/NCollection_BaseAllocator.cxx b/src/NCollection/NCollection_BaseAllocator.cxx index f51c48f0f9..267744cd9b 100755 --- a/src/NCollection/NCollection_BaseAllocator.cxx +++ b/src/NCollection/NCollection_BaseAllocator.cxx @@ -183,9 +183,7 @@ void NCollection_BaseAllocator::StandardCallBack const Standard_Size /*theSize*/) { static Standard_Mutex aMutex; - Standard_Boolean isReentrant = Standard::IsReentrant(); - if (isReentrant) - aMutex.Lock(); + aMutex.Lock(); // statistics by storage size NCollection_DataMap& aStMap = StorageMap(); if (!aStMap.IsBound(theRoundSize)) @@ -230,8 +228,7 @@ void NCollection_BaseAllocator::StandardCallBack } } - if (isReentrant) - aMutex.Unlock(); + aMutex.Unlock(); } //======================================================================= diff --git a/src/NCollection/NCollection_IncAllocator.cxx b/src/NCollection/NCollection_IncAllocator.cxx index e6934eb7b9..74ed5ab594 100755 --- a/src/NCollection/NCollection_IncAllocator.cxx +++ b/src/NCollection/NCollection_IncAllocator.cxx @@ -98,13 +98,10 @@ static Standard_Size CATCH_ID = 0; static void Debug_Create(Standard_Address theAlloc) { static Standard_Mutex aMutex; - Standard_Boolean isReentrant = Standard::IsReentrant(); - if (isReentrant) - aMutex.Lock(); + aMutex.Lock(); StorageIDMap().Bind(theAlloc, ++CurrentID); StorageIDSet().Add(CurrentID); - if (isReentrant) - aMutex.Unlock(); + aMutex.Unlock(); if (CurrentID == CATCH_ID) { // Place for break point for creation of investigated allocator @@ -120,17 +117,14 @@ static void Debug_Create(Standard_Address theAlloc) static void Debug_Destroy(Standard_Address theAlloc) { static Standard_Mutex aMutex; - Standard_Boolean isReentrant = Standard::IsReentrant(); - if (isReentrant) - aMutex.Lock(); + aMutex.Lock(); if (StorageIDMap().IsBound(theAlloc)) { Standard_Size anID = StorageIDMap()(theAlloc); StorageIDSet().Remove(anID); StorageIDMap().UnBind(theAlloc); } - if (isReentrant) - aMutex.Unlock(); + aMutex.Unlock(); } //======================================================================= diff --git a/src/Standard/Standard.cdl b/src/Standard/Standard.cdl index 6ac326174a..1379d19529 100755 --- a/src/Standard/Standard.cdl +++ b/src/Standard/Standard.cdl @@ -153,24 +153,4 @@ is -- and clears the list. -- Returns non-zero if some memory has been actually freed. - IsReentrant returns Boolean from Standard; - ---Purpose: Returns boolean flag indicating whether OCCT is - -- operating in reentrant mode. This flag affects OCCT - -- memory manager, exception and signal handling, - -- operations with handles etc., making them thread-safe. - -- - -- By default, this flag is set to False, in order - -- to avoid performance reduction due to locking. - -- - -- In multithreaded applications this flag must be set to - -- True, either by calling method SetReentrant(), - -- or by defining environment variable MMGT_REENTRANT. - - SetReentrant (isReentrant: Boolean from Standard); - ---Purpose: Sets boolean flag indicating whether OCCT is - -- operating in reentrant mode. - -- See method IsReentrant() for more information. - -- Note: This method may be called only when no any other - -- thread using OCCT exists - end Standard; diff --git a/src/Standard/Standard.cxx b/src/Standard/Standard.cxx index 47bb1bfd58..441573347e 100755 --- a/src/Standard/Standard.cxx +++ b/src/Standard/Standard.cxx @@ -38,9 +38,6 @@ #define OCCT_MMGT_OPT_DEFAULT 0 #endif -// Global reentrant flag -static Standard_Boolean Standard_IsReentrant = Standard_True; - //======================================================================= //class : Standard_MMgrFactory //purpose : Container for pointer to memory manager; @@ -94,10 +91,6 @@ Standard_MMgrFactory::Standard_MMgrFactory() } #endif - aVar = getenv ("MMGT_REENTRANT"); - if ( aVar != NULL ) - Standard_IsReentrant = (atoi (aVar) != 0); - switch (anAllocId) { case 1: // OCCT optimized memory allocator @@ -106,7 +99,7 @@ Standard_MMgrFactory::Standard_MMgrFactory() Standard_Integer aCellSize = (aVar = getenv ("MMGT_CELLSIZE" )) ? atoi (aVar) : 200; Standard_Integer aNbPages = (aVar = getenv ("MMGT_NBPAGES" )) ? atoi (aVar) : 1000; Standard_Integer aThreshold = (aVar = getenv ("MMGT_THRESHOLD")) ? atoi (aVar) : 40000; - myFMMgr = new Standard_MMgrOpt (toClear, bMMap, aCellSize, aNbPages, aThreshold, Standard_IsReentrant); + myFMMgr = new Standard_MMgrOpt (toClear, bMMap, aCellSize, aNbPages, aThreshold); break; } case 2: // TBB memory allocator @@ -220,24 +213,3 @@ Standard_Integer Standard::Purge() { return GetMMgr()->Purge(); } - -//======================================================================= -//function : IsReentrant -//purpose : -//======================================================================= - -Standard_Boolean Standard::IsReentrant() -{ - return Standard_IsReentrant; -} - -//======================================================================= -//function : SetReentrant -//purpose : -//======================================================================= - -void Standard::SetReentrant (const Standard_Boolean isReentrant) -{ - Standard_IsReentrant = isReentrant; - GetMMgr()->SetReentrant (isReentrant); -} diff --git a/src/Standard/Standard_ErrorHandler.cxx b/src/Standard/Standard_ErrorHandler.cxx index 8ee470eda9..ea8801e20c 100755 --- a/src/Standard/Standard_ErrorHandler.cxx +++ b/src/Standard/Standard_ErrorHandler.cxx @@ -68,12 +68,10 @@ Standard_ErrorHandler::Standard_ErrorHandler () : { myThread = GetThreadID(); - if (Standard::IsReentrant()) - theMutex.Lock(); + theMutex.Lock(); myPrevious = Top; Top = this; - if (Standard::IsReentrant()) - theMutex.Unlock(); + theMutex.Unlock(); } @@ -100,8 +98,7 @@ void Standard_ErrorHandler::Destroy() void Standard_ErrorHandler::Unlink() { // put a lock on the stack - if (Standard::IsReentrant()) - theMutex.Lock(); + theMutex.Lock(); Standard_ErrorHandler* aPrevious = 0; Standard_ErrorHandler* aCurrent = Top; @@ -113,8 +110,7 @@ void Standard_ErrorHandler::Unlink() } if(aCurrent==0) { - if (Standard::IsReentrant()) - theMutex.Unlock(); + theMutex.Unlock(); return; } @@ -126,8 +122,7 @@ void Standard_ErrorHandler::Unlink() aPrevious->myPrevious=aCurrent->myPrevious; } myPrevious = 0; - if (Standard::IsReentrant()) - theMutex.Unlock(); + theMutex.Unlock(); // unlink and destroy all registered callbacks Standard_Address aPtr = aCurrent->myCallbackPtr; @@ -226,8 +221,7 @@ Standard_ErrorHandler* Standard_ErrorHandler::FindHandler(const Standard_Handler const Standard_Boolean theUnlink) { // lock the stack - if (Standard::IsReentrant()) - theMutex.Lock(); + theMutex.Lock(); // Find the current ErrorHandler Accordin tread Standard_ErrorHandler* aPrevious = 0; @@ -272,8 +266,7 @@ Standard_ErrorHandler* Standard_ErrorHandler::FindHandler(const Standard_Handler aStop = Standard_True; } } - if (Standard::IsReentrant()) - theMutex.Unlock(); + theMutex.Unlock(); return anActive; } diff --git a/src/Standard/Standard_MMgrOpt.cxx b/src/Standard/Standard_MMgrOpt.cxx index 13f246c8a3..332c9bfc8a 100755 --- a/src/Standard/Standard_MMgrOpt.cxx +++ b/src/Standard/Standard_MMgrOpt.cxx @@ -189,8 +189,7 @@ Standard_MMgrOpt::Standard_MMgrOpt(const Standard_Boolean aClear, const Standard_Boolean aMMap, const Standard_Size aCellSize, const Standard_Integer aNbPages, - const Standard_Size aThreshold, - const Standard_Boolean isReentrant) + const Standard_Size aThreshold) { // check basic assumption if ( sizeof(Standard_Size) != sizeof(Standard_Address) ) @@ -213,7 +212,6 @@ Standard_MMgrOpt::Standard_MMgrOpt(const Standard_Boolean aClear, myCellSize = aCellSize; myNbPages = aNbPages; myThreshold = aThreshold; - myReentrant = isReentrant; // initialize Initialize(); @@ -364,7 +362,7 @@ Standard_Address Standard_MMgrOpt::Allocate(const Standard_Size aSize) // The unlock is called as soon as possible, for every treatment case. // We also do not use Sentry, since in case if OCC signal or exception is // caused by this block we will have deadlock anyway... - if (myReentrant) myMutex.Lock(); + myMutex.Lock(); // if free block of the requested size is available, return it if ( myFreeList[Index] ) { @@ -375,7 +373,7 @@ Standard_Address Standard_MMgrOpt::Allocate(const Standard_Size aSize) myFreeList[Index] = *(Standard_Size**)aBlock; // unlock the mutex - if ( myReentrant ) myMutex.Unlock(); + myMutex.Unlock(); // record size of the allocated block in the block header and // shift the pointer to the beginning of the user part of block @@ -389,12 +387,12 @@ Standard_Address Standard_MMgrOpt::Allocate(const Standard_Size aSize) // else if block size is small allocate it in pools else if ( RoundSize <= myCellSize ) { // unlock the mutex for free lists - if ( myReentrant ) myMutex.Unlock(); + myMutex.Unlock(); // and lock the specific mutex used to protect access to small blocks pools; // note that this is done by sentry class so as to ensure unlocking in case of // possible exception that may be thrown from AllocMemory() - Standard_Mutex::Sentry aSentry (myReentrant ? &myMutexPools : NULL); + Standard_Mutex::Sentry aSentry (myMutexPools); // check for availability of requested space in the current pool Standard_Size *aBlock = myNextAddr; @@ -410,10 +408,10 @@ Standard_Address Standard_MMgrOpt::Allocate(const Standard_Size aSize) const Standard_Size aRPSize = ROUNDDOWN_CELL(aPSize); const Standard_Size aPIndex = INDEX_CELL(aRPSize); if ( aPIndex > 0 && aPIndex <= myFreeListMax ) { - if (myReentrant) myMutex.Lock(); + myMutex.Lock(); *(Standard_Size**)myNextAddr = myFreeList[aPIndex]; myFreeList[aPIndex] = myNextAddr; - if (myReentrant) myMutex.Unlock(); + myMutex.Unlock(); } } @@ -438,7 +436,7 @@ Standard_Address Standard_MMgrOpt::Allocate(const Standard_Size aSize) // blocks of medium size are allocated directly else { // unlock the mutex immediately, as we do not need further to access any field - if ( myReentrant ) myMutex.Unlock(); + myMutex.Unlock(); // we use operator ?: instead of if() since it is faster Standard_Size *aBlock = (Standard_Size*) (myClear ? calloc( RoundSizeN+BLOCK_SHIFT, sizeof(Standard_Size)) : @@ -509,14 +507,14 @@ void Standard_MMgrOpt::Free(Standard_Address& theStorage) // of standard library are already protected by their implementation. // We also do not use Sentry, since in case if OCC signal or exception is // caused by this block we will have deadlock anyway... - if (myReentrant) myMutex.Lock(); + myMutex.Lock(); // in the memory block header, record address of the next free block *(Standard_Size**)aBlock = myFreeList[Index]; // add new block to be first in the list myFreeList[Index] = aBlock; - if (myReentrant) myMutex.Unlock(); + myMutex.Unlock(); } // otherwise, we have block of big size which shall be simply released else @@ -530,10 +528,10 @@ void Standard_MMgrOpt::Free(Standard_Address& theStorage) //purpose : Frees all free lists except small blocks (less than CellSize) //======================================================================= -Standard_Integer Standard_MMgrOpt::Purge(Standard_Boolean )//isDeleted) +Standard_Integer Standard_MMgrOpt::Purge(Standard_Boolean ) { // Lock access to critical data by mutex - Standard_Mutex::Sentry aSentry (myReentrant ? &myMutex : NULL); + Standard_Mutex::Sentry aSentry (myMutex); // TODO: implement support for isDeleted = True @@ -553,7 +551,7 @@ Standard_Integer Standard_MMgrOpt::Purge(Standard_Boolean )//isDeleted) } // Lock access to critical data by mutex - Standard_Mutex::Sentry aSentry1 (myReentrant ? &myMutexPools : NULL); + Standard_Mutex::Sentry aSentry1 (myMutexPools); // release memory pools containing no busy memory; // for that for each pool count the summary size of blocks @@ -696,7 +694,7 @@ Standard_Integer Standard_MMgrOpt::Purge(Standard_Boolean )//isDeleted) void Standard_MMgrOpt::FreePools() { // Lock access to critical data by mutex - Standard_Mutex::Sentry aSentry (myReentrant ? &myMutexPools : NULL); + Standard_Mutex::Sentry aSentry (myMutexPools); // last pool is remembered in myAllocList Standard_Size * aFree = myAllocList; @@ -873,13 +871,3 @@ void Standard_MMgrOpt::FreeMemory (Standard_Address aBlock, else free(aBlock); } - -//======================================================================= -//function : SetReentrant -//purpose : -//======================================================================= - -void Standard_MMgrOpt::SetReentrant(Standard_Boolean isReentrant) -{ - myReentrant = isReentrant; -} diff --git a/src/Standard/Standard_MMgrOpt.hxx b/src/Standard/Standard_MMgrOpt.hxx index dcbcb4e3d7..de9c8d4640 100755 --- a/src/Standard/Standard_MMgrOpt.hxx +++ b/src/Standard/Standard_MMgrOpt.hxx @@ -95,8 +95,7 @@ class Standard_MMgrOpt : public Standard_MMgrRoot const Standard_Boolean aMMap = Standard_True, const Standard_Size aCellSize = 200, const Standard_Integer aNbPages = 10000, - const Standard_Size aThreshold = 40000, - const Standard_Boolean isReentrant = Standard_False); + const Standard_Size aThreshold = 40000); //! Frees all free lists and pools allocated for small blocks Standard_EXPORT virtual ~Standard_MMgrOpt(); @@ -118,11 +117,6 @@ class Standard_MMgrOpt : public Standard_MMgrRoot //! Returns number of actually freed blocks Standard_EXPORT virtual Standard_Integer Purge(Standard_Boolean isDestroyed); - //! Set reentrant mode on or off. - //! Note: This method may be called only when no any other thread can - //! access this object simultaneously - Standard_EXPORT virtual void SetReentrant(Standard_Boolean isReentrant); - //! Declaration of a type pointer to the callback function that //! should accept the following arguments:
//! theIsAlloc - true if the data is allocated, false if it is freed;
@@ -174,7 +168,6 @@ protected: Standard_Mutex myMutex; //!< Mutex to protect free lists data Standard_Mutex myMutexPools; //!< Mutex to protect small block pools data - Standard_Boolean myReentrant; //!< Use mutex to provide correct reentrant behaviour }; #endif diff --git a/src/Standard/Standard_MMgrRoot.cxx b/src/Standard/Standard_MMgrRoot.cxx index ed3ebe9315..7da63ac038 100755 --- a/src/Standard/Standard_MMgrRoot.cxx +++ b/src/Standard/Standard_MMgrRoot.cxx @@ -39,12 +39,3 @@ Standard_Integer Standard_MMgrRoot::Purge(Standard_Boolean) { return 0; } - -//======================================================================= -//function : SetReentrant -//purpose : -//======================================================================= - -void Standard_MMgrRoot::SetReentrant(Standard_Boolean) -{ -} diff --git a/src/Standard/Standard_MMgrRoot.hxx b/src/Standard/Standard_MMgrRoot.hxx index 6ad915c00a..208a155436 100755 --- a/src/Standard/Standard_MMgrRoot.hxx +++ b/src/Standard/Standard_MMgrRoot.hxx @@ -74,12 +74,6 @@ class Standard_MMgrRoot //! //! Default implementation does nothing and returns 0. Standard_EXPORT virtual Standard_Integer Purge(Standard_Boolean isDestroyed=Standard_False); - - //! Set reentrant mode on or off. - //! Note: This method may be called only when no any other thread can - //! access this object simultaneously. - //! Default implementation does nothing. - Standard_EXPORT virtual void SetReentrant(Standard_Boolean isReentrant); }; #endif diff --git a/src/XSDRAWSTLVRML/XSDRAWSTLVRML.cxx b/src/XSDRAWSTLVRML/XSDRAWSTLVRML.cxx index e6f75d5158..d7b95da3d5 100755 --- a/src/XSDRAWSTLVRML/XSDRAWSTLVRML.cxx +++ b/src/XSDRAWSTLVRML/XSDRAWSTLVRML.cxx @@ -98,10 +98,8 @@ static Standard_Integer writestl Standard_Boolean isInParallel = Standard_False; if (argc > 3) { isASCIIMode = (Draw::Atoi(argv[3]) == 0); - if (argc > 4) { + if (argc > 4) isInParallel = (Draw::Atoi(argv[4]) == 1); - Standard::SetReentrant(isInParallel); - } } StlAPI_Writer aWriter; aWriter.ASCIIMode() = isASCIIMode;