An ACE_Bound_Ptr_Counter<ACE_LOCK> object encapsulates an object reference count. More...
#include <Bound_Ptr.h>

Public Member Functions | |
| ACE_Bound_Ptr_Counter (long init_obj_ref_count=0) | |
| ~ACE_Bound_Ptr_Counter (void) | |
Static Public Member Functions | |
| static ACE_Bound_Ptr_Counter < ACE_LOCK > * | create_strong (void) |
| static long | attach_strong (ACE_Bound_Ptr_Counter< ACE_LOCK > *counter) |
| static long | detach_strong (ACE_Bound_Ptr_Counter< ACE_LOCK > *counter) |
| static ACE_Bound_Ptr_Counter < ACE_LOCK > * | create_weak (void) |
| static void | attach_weak (ACE_Bound_Ptr_Counter< ACE_LOCK > *counter) |
| Increase the counter reference count and return argument. | |
| static void | detach_weak (ACE_Bound_Ptr_Counter< ACE_LOCK > *counter) |
| static bool | object_was_deleted (ACE_Bound_Ptr_Counter< ACE_LOCK > *counter) |
| Determine whether the object has been deleted. | |
Public Attributes | |
| ACE_ALLOC_HOOK_DECLARE | |
| Declare the dynamic allocation hooks. | |
Static Private Member Functions | |
| static ACE_Bound_Ptr_Counter < ACE_LOCK > * | internal_create (long init_obj_ref_count) |
Private Attributes | |
| long | obj_ref_count_ |
| long | self_ref_count_ |
| Reference count of this counter. | |
| ACE_LOCK | lock_ |
| Mutex variable to synchronize access to the reference counts. | |
An ACE_Bound_Ptr_Counter<ACE_LOCK> object encapsulates an object reference count.
Do not use this class directly, use ACE_Strong_Bound_Ptr or ACE_Weak_Bound_Ptr instead.
Definition at line 39 of file Bound_Ptr.h.
| ACE_Bound_Ptr_Counter< ACE_LOCK >::ACE_Bound_Ptr_Counter | ( | long | init_obj_ref_count = 0 |
) | [inline] |
Definition at line 135 of file Bound_Ptr.inl.
: obj_ref_count_ (init_obj_ref_count), self_ref_count_ (1) { }
| ACE_Bound_Ptr_Counter< ACE_LOCK >::~ACE_Bound_Ptr_Counter | ( | void | ) | [inline] |
Definition at line 142 of file Bound_Ptr.inl.
{
}
| long ACE_Bound_Ptr_Counter< ACE_LOCK >::attach_strong | ( | ACE_Bound_Ptr_Counter< ACE_LOCK > * | counter | ) | [inline, static] |
Increase both the object and counter reference counts and return the new object reference count. A return value of -1 indicates that the object has already been destroyed.
Definition at line 40 of file Bound_Ptr.inl.
{
ACE_GUARD_RETURN (ACE_LOCK, guard, counter->lock_, -1);
// Can't attach a strong pointer to an object that has already been deleted.
if (counter->obj_ref_count_ == -1)
return -1;
long new_obj_ref_count = ++counter->obj_ref_count_;
++counter->self_ref_count_;
return new_obj_ref_count;
}
| void ACE_Bound_Ptr_Counter< ACE_LOCK >::attach_weak | ( | ACE_Bound_Ptr_Counter< ACE_LOCK > * | counter | ) | [inline, static] |
Increase the counter reference count and return argument.
Definition at line 99 of file Bound_Ptr.inl.
{
ACE_GUARD (ACE_LOCK, guard, counter->lock_);
++counter->self_ref_count_;
}
| ACE_Bound_Ptr_Counter< ACE_LOCK > * ACE_Bound_Ptr_Counter< ACE_LOCK >::create_strong | ( | void | ) | [inline, static] |
Create a ACE_Bound_Ptr_Counter<ACE_LOCK> and initialize the reference count to indicate ownership by a strong pointer.
Definition at line 24 of file Bound_Ptr.inl.
{
// Set initial object reference count to 1.
ACE_Bound_Ptr_Counter<ACE_LOCK> *temp = internal_create (1);
#if defined (ACE_NEW_THROWS_EXCEPTIONS)
if (temp == 0)
ACE_throw_bad_alloc;
#else
ACE_ASSERT (temp != 0);
#endif /* ACE_NEW_THROWS_EXCEPTIONS */
return temp;
}
| ACE_Bound_Ptr_Counter< ACE_LOCK > * ACE_Bound_Ptr_Counter< ACE_LOCK >::create_weak | ( | void | ) | [inline, static] |
Create a ACE_Bound_Ptr_Counter<ACE_LOCK> and initialize the reference count to indicate no ownership.
Definition at line 84 of file Bound_Ptr.inl.
{
// Set initial object reference count to 0.
ACE_Bound_Ptr_Counter<ACE_LOCK> *temp = internal_create (0);
#if defined (ACE_NEW_THROWS_EXCEPTIONS)
if (temp == 0)
ACE_throw_bad_alloc;
#else
ACE_ASSERT (temp != 0);
#endif /* ACE_NEW_THROWS_EXCEPTIONS */
return temp;
}
| long ACE_Bound_Ptr_Counter< ACE_LOCK >::detach_strong | ( | ACE_Bound_Ptr_Counter< ACE_LOCK > * | counter | ) | [inline, static] |
Decreases both the object and counter reference counts and deletes whichever has no more references. Returns the new object reference count.
Definition at line 55 of file Bound_Ptr.inl.
{
ACE_Bound_Ptr_Counter<ACE_LOCK> *counter_del = 0;
long new_obj_ref_count;
{
ACE_GUARD_RETURN (ACE_LOCK, guard, counter->lock_, -1);
if ((new_obj_ref_count = --counter->obj_ref_count_) == 0)
// Change the object reference count to -1 to indicate that the
// object has been deleted, as opposed to a weak pointer that
// simply hasn't had any strong pointers created from it yet.
counter->obj_ref_count_ = -1;
if (--counter->self_ref_count_ == 0)
// Since counter contains the lock held by the ACE_Guard, the
// guard needs to be released before freeing the memory holding
// the lock. So save the pointer to free, then release, then
// free.
counter_del = counter;
} // Release the lock
delete counter_del;
return new_obj_ref_count;
}
| void ACE_Bound_Ptr_Counter< ACE_LOCK >::detach_weak | ( | ACE_Bound_Ptr_Counter< ACE_LOCK > * | counter | ) | [inline, static] |
Decreases the counter reference count and deletes the counter if it has no more references.
Definition at line 107 of file Bound_Ptr.inl.
{
ACE_Bound_Ptr_Counter<ACE_LOCK> *counter_del = 0;
{
ACE_GUARD (ACE_LOCK, guard, counter->lock_);
if (--counter->self_ref_count_ == 0)
// Since counter contains the lock held by the ACE_Guard, the
// guard needs to be released before freeing the memory holding
// the lock. So save the pointer to free, then release, then
// free.
counter_del = counter;
} // Release the lock
delete counter_del;
}
| ACE_Bound_Ptr_Counter< ACE_LOCK > * ACE_Bound_Ptr_Counter< ACE_LOCK >::internal_create | ( | long | init_obj_ref_count | ) | [inline, static, private] |
Allocate a new ACE_Bound_Ptr_Counter<ACE_LOCK> instance, returning NULL if it cannot be created.
Definition at line 14 of file Bound_Ptr.inl.
{
ACE_Bound_Ptr_Counter<ACE_LOCK> *temp = 0;
ACE_NEW_RETURN (temp,
ACE_Bound_Ptr_Counter<ACE_LOCK> (init_obj_ref_count),
0);
return temp;
}
| bool ACE_Bound_Ptr_Counter< ACE_LOCK >::object_was_deleted | ( | ACE_Bound_Ptr_Counter< ACE_LOCK > * | counter | ) | [inline, static] |
Determine whether the object has been deleted.
Definition at line 127 of file Bound_Ptr.inl.
{
ACE_GUARD_RETURN (ACE_LOCK, guard, counter->lock_, 0);
return counter->obj_ref_count_ == -1;
}
| ACE_Bound_Ptr_Counter< ACE_LOCK >::ACE_ALLOC_HOOK_DECLARE |
Declare the dynamic allocation hooks.
Definition at line 43 of file Bound_Ptr.h.
ACE_LOCK ACE_Bound_Ptr_Counter< ACE_LOCK >::lock_ [private] |
Mutex variable to synchronize access to the reference counts.
Definition at line 93 of file Bound_Ptr.h.
long ACE_Bound_Ptr_Counter< ACE_LOCK >::obj_ref_count_ [private] |
Reference count of underlying object. Is set to -1 once the object has been destroyed to indicate to all weak pointers that it is no longer valid.
Definition at line 87 of file Bound_Ptr.h.
long ACE_Bound_Ptr_Counter< ACE_LOCK >::self_ref_count_ [private] |
Reference count of this counter.
Definition at line 90 of file Bound_Ptr.h.
1.7.0