MCPcopy Create free account
hub / github.com/FlaxEngine/FlaxEngine / ConcurrentBuffer

Class ConcurrentBuffer

Source/Engine/Threading/ConcurrentBuffer.h:16–400  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

14/// </summary>
15template<typename T>
16class ConcurrentBuffer
17{
18 friend ConcurrentBuffer;
19
20private:
21
22 int64 _count;
23 int64 _capacity;
24 T* _data;
25 CriticalSection _resizeLocker;
26
27public:
28
29 /// <summary>
30 /// Initializes a new instance of the <see cref="ConcurrentBuffer"/> class.
31 /// </summary>
32 ConcurrentBuffer()
33 : _count(0)
34 , _capacity(0)
35 , _data(nullptr)
36 {
37 }
38
39 /// <summary>
40 /// Initializes a new instance of the <see cref="ConcurrentBuffer"/> class.
41 /// </summary>
42 /// <param name="capacity">The capacity.</param>
43 ConcurrentBuffer(int32 capacity)
44 : _count(0)
45 , _capacity(capacity)
46 {
47 if (_capacity > 0)
48 _data = (T*)Allocator::Allocate(_capacity * sizeof(T));
49 else
50 _data = nullptr;
51 }
52
53 /// <summary>
54 /// Finalizes an instance of the <see cref="ConcurrentBuffer"/> class.
55 /// </summary>
56 ~ConcurrentBuffer()
57 {
58 Allocator::Free(_data);
59 }
60
61public:
62
63 /// <summary>
64 /// Gets the amount of the elements in the collection.
65 /// </summary>
66 /// <returns>The items count.</returns>
67 FORCE_INLINE int64 Count()
68 {
69 return Platform::AtomicRead(&_count);
70 }
71
72 /// <summary>
73 /// Get amount of the elements that can be holed by collection without resizing.

Callers

nothing calls this directly

Calls 2

EnsureCapacityFunction · 0.85
InterlockedAddFunction · 0.50

Tested by

no test coverage detected