Module: Threads Package: Smart Pointer
Does not inherit
#include <rw/pointer/RWAtomicCounter.h>
RWAtomicCounter is a class for maintaining a reference count. It can be safely used in a multithreaded environment. If multithread safety is not an issue, use an RWUnsafeCounter. On systems that support atomic integer operations, this class is more efficient than the equivalent RWTCounter<RWMutexLock>.
#include <rw/pointer/RWTCountedPointer.h> #include <rw/pointer/RWAtomicCounter.h> #include <rw/sync/RWMutexLock.h> #include <iostream.h> class Foo : public RWAtomicCounter { public: void bar(void) { cout << "I'm a foo example" << endl; } }; typedef RWTCountedPointer<Foo> FooPointer; int main(void) { try { FooPointer p1(new Foo); p1->bar(); } catch(RWxmsg& msg) { cout << msg.why() << endl; } return 0; }
RWAtomicCounter(RWStaticCtor);
Constructs a static instance (does not initialize the reference count). Throws no exceptions.
RWAtomicCounter(unsigned initCount = 0);
Constructs a default instance (initializes the reference count). Throws no exceptions.
RWAtomicCounter(const RWAtomicCounter& second);
Default-initializes the internal count to zero.
unsigned addReference();
Increments and returns the reference count.
unsigned references() const;
Queries the current reference count. Throws no exceptions.
unsigned removeReference();
Decrements and returns the reference count.
RWAtomicCounter& operator=(const RWAtomicCounter&);
Copy assignment operator. Does nothing. Returns *this.
RWUnsafeCounter, RWTCounter<RWMutexLock>
© Copyright Rogue Wave Software, Inc. All Rights Reserved.
Rogue Wave and SourcePro are registered trademarks of Rogue Wave Software, Inc. in the United States and other countries. All other trademarks are the property of their respective owners.
Contact Rogue Wave about documentation or support issues.