#include <OSD_Timer.hxx>
#include <Transfer_TransferOutput.hxx>
#include <ShapeExtend_Explorer.hxx>
-#include <Message_ProgressSentry.hxx>
#include <Message_Messenger.hxx>
#include <Transfer_ActorOfTransientProcess.hxx>
#include <IGESToBRep_Actor.hxx>
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();
{
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");
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<Standard_Size, StorageInfo>& aStMap = StorageMap();
if (!aStMap.IsBound(theRoundSize))
}
}
- if (isReentrant)
- aMutex.Unlock();
+ aMutex.Unlock();
}
//=======================================================================
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
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();
}
//=======================================================================
-- 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;
#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;
}
#endif
- aVar = getenv ("MMGT_REENTRANT");
- if ( aVar != NULL )
- Standard_IsReentrant = (atoi (aVar) != 0);
-
switch (anAllocId)
{
case 1: // OCCT optimized memory allocator
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
{
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);
-}
{
myThread = GetThreadID();
- if (Standard::IsReentrant())
- theMutex.Lock();
+ theMutex.Lock();
myPrevious = Top;
Top = this;
- if (Standard::IsReentrant())
- theMutex.Unlock();
+ theMutex.Unlock();
}
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;
}
if(aCurrent==0) {
- if (Standard::IsReentrant())
- theMutex.Unlock();
+ theMutex.Unlock();
return;
}
aPrevious->myPrevious=aCurrent->myPrevious;
}
myPrevious = 0;
- if (Standard::IsReentrant())
- theMutex.Unlock();
+ theMutex.Unlock();
// unlink and destroy all registered callbacks
Standard_Address aPtr = aCurrent->myCallbackPtr;
const Standard_Boolean theUnlink)
{
// lock the stack
- if (Standard::IsReentrant())
- theMutex.Lock();
+ theMutex.Lock();
// Find the current ErrorHandler Accordin tread
Standard_ErrorHandler* aPrevious = 0;
aStop = Standard_True;
}
}
- if (Standard::IsReentrant())
- theMutex.Unlock();
+ theMutex.Unlock();
return anActive;
}
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) )
myCellSize = aCellSize;
myNbPages = aNbPages;
myThreshold = aThreshold;
- myReentrant = isReentrant;
// initialize
Initialize();
// 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] ) {
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
// 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;
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();
}
}
// 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)) :
// 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
//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
}
// 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
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;
else
free(aBlock);
}
-
-//=======================================================================
-//function : SetReentrant
-//purpose :
-//=======================================================================
-
-void Standard_MMgrOpt::SetReentrant(Standard_Boolean isReentrant)
-{
- myReentrant = isReentrant;
-}
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();
//! 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: <br>
//! theIsAlloc - true if the data is allocated, false if it is freed; <br>
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
{
return 0;
}
-
-//=======================================================================
-//function : SetReentrant
-//purpose :
-//=======================================================================
-
-void Standard_MMgrRoot::SetReentrant(Standard_Boolean)
-{
-}
//!
//! 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
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;