1 // Created on: 2016-06-20
2 // Created by: Oleg AGASHIN
3 // Copyright (c) 2016 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License version 2.1 as published
9 // by the Free Software Foundation, with special exception defined in the file
10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 // distribution for complete text of the license and disclaimer of any warranty.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
16 #ifndef _BRepMesh_IncAllocator_HeaderFile
17 #define _BRepMesh_IncAllocator_HeaderFile
19 #include <NCollection_IncAllocator.hxx>
20 #include <Standard_Mutex.hxx>
22 //! Extension for NCollection_IncAllocator implementing simple thread safety
23 //! by introduction of Mutex. Intended for use in couple with BRepMeshData
24 //! entities in order to prevent data races while building data model in
25 //! parallel mode. Note that this allocator is supposed for use by collections
26 //! which allocate memory by huge blocks at arbitrary moment, thus it should
27 //! not introduce significant performance slow down.
28 class BRepMesh_IncAllocator : public NCollection_IncAllocator
32 BRepMesh_IncAllocator(const size_t theBlockSize = DefaultBlockSize)
33 : NCollection_IncAllocator(theBlockSize)
37 //! Allocate memory with given size. Returns NULL on failure
38 virtual void* Allocate(const size_t size) Standard_OVERRIDE
40 Standard_Mutex::Sentry aSentry(myMutex);
41 return NCollection_IncAllocator::Allocate(size);
44 DEFINE_STANDARD_RTTI_INLINE(BRepMesh_IncAllocator, NCollection_IncAllocator)
47 Standard_Mutex myMutex;