packagefs: Add CountReferences method to InlineReferenceable.
This commit is contained in:
@@ -13,7 +13,7 @@
|
|||||||
#include "EmptyAttributeDirectoryCookie.h"
|
#include "EmptyAttributeDirectoryCookie.h"
|
||||||
|
|
||||||
|
|
||||||
DEFINE_REFERENCEABLE_ACQUIRE_RELEASE(Node, fReferenceable);
|
DEFINE_INLINE_REFERENCEABLE_METHODS(Node, fReferenceable);
|
||||||
|
|
||||||
|
|
||||||
Node::Node(ino_t id)
|
Node::Node(ino_t id)
|
||||||
|
|||||||
@@ -41,6 +41,7 @@ public:
|
|||||||
|
|
||||||
void AcquireReference();
|
void AcquireReference();
|
||||||
void ReleaseReference();
|
void ReleaseReference();
|
||||||
|
int32 CountReferences();
|
||||||
|
|
||||||
inline bool ReadLock();
|
inline bool ReadLock();
|
||||||
inline void ReadUnlock();
|
inline void ReadUnlock();
|
||||||
|
|||||||
@@ -16,7 +16,7 @@
|
|||||||
#include "Utils.h"
|
#include "Utils.h"
|
||||||
|
|
||||||
|
|
||||||
DEFINE_REFERENCEABLE_ACQUIRE_RELEASE(PackageNode, fReferenceable);
|
DEFINE_INLINE_REFERENCEABLE_METHODS(PackageNode, fReferenceable);
|
||||||
|
|
||||||
|
|
||||||
PackageNode::PackageNode(Package* package, mode_t mode)
|
PackageNode::PackageNode(Package* package, mode_t mode)
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ public:
|
|||||||
|
|
||||||
void AcquireReference();
|
void AcquireReference();
|
||||||
void ReleaseReference();
|
void ReleaseReference();
|
||||||
|
int32 CountReferences();
|
||||||
|
|
||||||
BReference<Package> GetPackage() const;
|
BReference<Package> GetPackage() const;
|
||||||
// Since PackageNode does only hold a
|
// Since PackageNode does only hold a
|
||||||
|
|||||||
@@ -15,18 +15,18 @@
|
|||||||
* is only sizeof(int32) == 4. */
|
* is only sizeof(int32) == 4. */
|
||||||
class InlineReferenceable {
|
class InlineReferenceable {
|
||||||
public:
|
public:
|
||||||
InlineReferenceable()
|
inline InlineReferenceable()
|
||||||
:
|
:
|
||||||
fReferenceCount(1)
|
fReferenceCount(1)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
~InlineReferenceable()
|
inline ~InlineReferenceable()
|
||||||
{
|
{
|
||||||
ASSERT(fReferenceCount == 0 || fReferenceCount == 1);
|
ASSERT(fReferenceCount == 0 || fReferenceCount == 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
int32
|
inline int32
|
||||||
AcquireReference()
|
AcquireReference()
|
||||||
{
|
{
|
||||||
const int32 previousCount = atomic_add(&fReferenceCount, 1);
|
const int32 previousCount = atomic_add(&fReferenceCount, 1);
|
||||||
@@ -34,7 +34,7 @@ public:
|
|||||||
return previousCount;
|
return previousCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32
|
inline int32
|
||||||
ReleaseReference()
|
ReleaseReference()
|
||||||
{
|
{
|
||||||
const int32 previousCount = atomic_add(&fReferenceCount, -1);
|
const int32 previousCount = atomic_add(&fReferenceCount, -1);
|
||||||
@@ -42,14 +42,21 @@ public:
|
|||||||
return previousCount;
|
return previousCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline int32
|
||||||
|
CountReferences()
|
||||||
|
{
|
||||||
|
return atomic_get(&fReferenceCount);
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int32 fReferenceCount;
|
int32 fReferenceCount;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
#define DEFINE_REFERENCEABLE_ACQUIRE_RELEASE(CLASS, InlineReferenceable) \
|
#define DEFINE_INLINE_REFERENCEABLE_METHODS(CLASS, InlineReferenceable) \
|
||||||
void CLASS::AcquireReference() { InlineReferenceable.AcquireReference(); } \
|
void CLASS::AcquireReference() { InlineReferenceable.AcquireReference(); } \
|
||||||
void CLASS::ReleaseReference() { if (InlineReferenceable.ReleaseReference() == 1) delete this; }
|
void CLASS::ReleaseReference() { if (InlineReferenceable.ReleaseReference() == 1) delete this; } \
|
||||||
|
int32 CLASS::CountReferences() { return InlineReferenceable.CountReferences(); }
|
||||||
|
|
||||||
|
|
||||||
#endif // INLINE_REFERENCEABLE_H
|
#endif // INLINE_REFERENCEABLE_H
|
||||||
|
|||||||
Reference in New Issue
Block a user