23 lines
472 B
C++
23 lines
472 B
C++
#pragma once
|
|
|
|
#include <QMutex>
|
|
|
|
namespace Cevo {
|
|
|
|
// Equivalent of SyncCounter.pas's TSyncCounter: a thread-safe counter/ID allocator.
|
|
class SyncCounter {
|
|
public:
|
|
int allocate();
|
|
bool currentEqualTo(int value) const;
|
|
void increment();
|
|
// NOTE: matches the original, which copies Top/Current without locking.
|
|
void assign(const SyncCounter &source);
|
|
|
|
private:
|
|
mutable QMutex m_lock;
|
|
int m_top = 0;
|
|
int m_current = 0;
|
|
};
|
|
|
|
} // namespace Cevo
|