0030345: Mesh, BRepMesh_CurveTessellator - GCPnts_TangentialDeflection throws Standar...
[occt.git] / src / BRepMesh / BRepMesh_IncAllocator.hxx
CommitLineData
7bd071ed 1// Created on: 2016-06-20
2// Created by: Oleg AGASHIN
3// Copyright (c) 2016 OPEN CASCADE SAS
4//
5// This file is part of Open CASCADE Technology software library.
6//
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.
12//
13// Alternatively, this file may be used under the terms of Open CASCADE
14// commercial license or contractual agreement.
15
16#ifndef _BRepMesh_IncAllocator_HeaderFile
17#define _BRepMesh_IncAllocator_HeaderFile
18
19#include <NCollection_IncAllocator.hxx>
20#include <Standard_Mutex.hxx>
21
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.
28class BRepMesh_IncAllocator : public NCollection_IncAllocator
29{
30public:
31 //! Constructor
32 BRepMesh_IncAllocator(const size_t theBlockSize = DefaultBlockSize)
33 : NCollection_IncAllocator(theBlockSize)
34 {
35 }
36
37 //! Allocate memory with given size. Returns NULL on failure
38 virtual void* Allocate(const size_t size) Standard_OVERRIDE
39 {
40 Standard_Mutex::Sentry aSentry(myMutex);
41 return NCollection_IncAllocator::Allocate(size);
42 }
43
44 DEFINE_STANDARD_RTTI_INLINE(BRepMesh_IncAllocator, NCollection_IncAllocator)
45
46private:
47 Standard_Mutex myMutex;
48};
49
50#endif