FREE Subscription to Dr. Dobb’s Digest: Same Great Content, New Digital Edition
Site Archive (Complete)
C++
Email
Print
Reprint

add to:
Del.icio.us
Digg
Google
Furl
Slashdot
Y! MyWeb
Blink
August 01, 1997

A Portable Multithreading Framework

(Page 5 of 6)

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
RELATED ARTICLES
No Related Articles
TOP 5 ARTICLES
No Top Articles.



MICROSITES
FEATURED TOPIC

ADDITIONAL TOPICS

INFO-LINK