August 01, 1997
A Portable Multithreading Framework
August 1997/A Portable Multithreading Framework/Listing 4
Listing 4: NTreference count implementation
////////////////////////////////////////////
// Copyright (c) Panos Kougiouris 1997
////////////////////////////////////////////
#include <kfReferenceCount.h>
CKFReferenceCount::CKFReferenceCount()
{
m_count = 1;
}
CKFReferenceCount::~CKFReferenceCount()
{
assert(m_count == 0);
}
//------------------------------------------
void
CKFReferenceCount::increment()
{
InterlockedIncrement((LPLONG)&m_count);
}
//------------------------------------------
void
CKFReferenceCount::decrement()
{
LONG ret =
InterlockedDecrement((LPLONG)&m_count);
assert(ret >= 0); // less than 0 means
// too many decrements
if (m_count == 0) {
delete this;
}
}
//------------------------------------------
int
CKFReferenceCount::count()
{
return m_count;
}
//End of File
Previous Page |
1
|
2
|
3
|
4
|
5
|
6
Next Page