diff --git a/src/servers/registrar/RChangeCounter.h b/src/servers/registrar/RChangeCounter.h new file mode 100644 index 0000000000..c7ba20ed77 --- /dev/null +++ b/src/servers/registrar/RChangeCounter.h @@ -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 + +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 Locker; + +private: + int32 fCount; + int32 fLocked; + bool fChanged; +}; + +#endif // CHANGE_COUNTER_H