Make the counter really singleton, remove non-working static init
This commit is contained in:
parent
4562201455
commit
6ac903ac8f
1 changed files with 17 additions and 11 deletions
|
|
@ -45,6 +45,16 @@ namespace sfz
|
||||||
class BufferCounter
|
class BufferCounter
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
/**
|
||||||
|
* @brief Return the buffer counter object.
|
||||||
|
*/
|
||||||
|
static BufferCounter& counter() noexcept
|
||||||
|
{
|
||||||
|
static BufferCounter counter;
|
||||||
|
return counter;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected:
|
||||||
BufferCounter() noexcept = default;
|
BufferCounter() noexcept = default;
|
||||||
~BufferCounter() noexcept
|
~BufferCounter() noexcept
|
||||||
{
|
{
|
||||||
|
|
@ -54,6 +64,7 @@ public:
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public:
|
||||||
void newBuffer(int size) noexcept
|
void newBuffer(int size) noexcept
|
||||||
{
|
{
|
||||||
numBuffers++;
|
numBuffers++;
|
||||||
|
|
@ -164,9 +175,9 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
if (largerSize > 0)
|
if (largerSize > 0)
|
||||||
_counter.bufferResized(largerSize * sizeof(value_type), tempSize * sizeof(value_type));
|
counter().bufferResized(largerSize * sizeof(value_type), tempSize * sizeof(value_type));
|
||||||
else
|
else
|
||||||
_counter.newBuffer(tempSize * sizeof(value_type));
|
counter().newBuffer(tempSize * sizeof(value_type));
|
||||||
|
|
||||||
largerSize = tempSize;
|
largerSize = tempSize;
|
||||||
alignedSize = newSize;
|
alignedSize = newSize;
|
||||||
|
|
@ -202,13 +213,13 @@ public:
|
||||||
void clear() noexcept
|
void clear() noexcept
|
||||||
{
|
{
|
||||||
if (largerSize > 0)
|
if (largerSize > 0)
|
||||||
_counter.bufferDeleted(largerSize * sizeof(value_type));
|
counter().bufferDeleted(largerSize * sizeof(value_type));
|
||||||
_clear();
|
_clear();
|
||||||
}
|
}
|
||||||
~Buffer() noexcept
|
~Buffer() noexcept
|
||||||
{
|
{
|
||||||
if (largerSize > 0)
|
if (largerSize > 0)
|
||||||
_counter.bufferDeleted(largerSize * sizeof(value_type));
|
counter().bufferDeleted(largerSize * sizeof(value_type));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -259,7 +270,7 @@ public:
|
||||||
{
|
{
|
||||||
if (this != &other) {
|
if (this != &other) {
|
||||||
if (largerSize > 0)
|
if (largerSize > 0)
|
||||||
_counter.bufferDeleted(largerSize * sizeof(value_type));
|
counter().bufferDeleted(largerSize * sizeof(value_type));
|
||||||
largerSize = other.largerSize;
|
largerSize = other.largerSize;
|
||||||
alignedSize = other.alignedSize;
|
alignedSize = other.alignedSize;
|
||||||
normalData = other.normalData;
|
normalData = other.normalData;
|
||||||
|
|
@ -286,7 +297,7 @@ public:
|
||||||
*/
|
*/
|
||||||
static BufferCounter& counter() noexcept
|
static BufferCounter& counter() noexcept
|
||||||
{
|
{
|
||||||
return _counter;
|
return BufferCounter::counter();
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
@ -328,12 +339,7 @@ private:
|
||||||
std::unique_ptr<value_type[], deleter> paddedData;
|
std::unique_ptr<value_type[], deleter> paddedData;
|
||||||
pointer normalEnd { nullptr };
|
pointer normalEnd { nullptr };
|
||||||
pointer _alignedEnd { nullptr };
|
pointer _alignedEnd { nullptr };
|
||||||
static BufferCounter _counter;
|
|
||||||
|
|
||||||
LEAK_DETECTOR(Buffer);
|
LEAK_DETECTOR(Buffer);
|
||||||
};
|
};
|
||||||
|
|
||||||
template <class Type, unsigned int Alignment>
|
|
||||||
BufferCounter Buffer<Type, Alignment>::_counter;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue