Tiny inline class representing a change counter.

git-svn-id: file:///srv/svn/repos/haiku/trunk/current@2692 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Ingo Weinhold
2003-02-11 23:33:05 +00:00
parent 26dade365a
commit 9c0367dcec
+42
View File
@@ -0,0 +1,42 @@
//----------------------------------------------------------------------
// This software is part of the OpenBeOS distribution and is covered
// by the OpenBeOS license.
//---------------------------------------------------------------------
#ifndef CHANGE_COUNTER_H
#define CHANGE_COUNTER_H
#include <ObjectLocker.h>
class RChangeCounter {
public:
RChangeCounter() : fCount(0), fLocked(0), fChanged(false) {}
~RChangeCounter() {}
int32 Count() const { return fCount; }
bool Lock() { fLocked++; return true; }
void Unlock() { if (fLocked > 0) fLocked--; }
bool Increment()
{
bool changed = false;
if (fLocked && !fChanged) {
fCount++;
changed = fChanged = true;
}
return changed;
}
void Reset() { fCount = 0; fLocked = 0; fChanged = false; }
public:
typedef BPrivate::BObjectLocker<RChangeCounter> Locker;
private:
int32 fCount;
int32 fLocked;
bool fChanged;
};
#endif // CHANGE_COUNTER_H