#include <Bound_Ptr.h>
Collaboration diagram for ACE_Bound_Ptr_Counter< ACE_LOCK >:

Public Member Functions | |
| ACE_Bound_Ptr_Counter (int init_obj_ref_count=0) | |
| ~ACE_Bound_Ptr_Counter (void) | |
Static Public Member Functions | |
| ACE_Bound_Ptr_Counter< ACE_LOCK > * | create_strong (void) |
| int | attach_strong (ACE_Bound_Ptr_Counter< ACE_LOCK > *counter) |
| int | detach_strong (ACE_Bound_Ptr_Counter< ACE_LOCK > *counter) |
| ACE_Bound_Ptr_Counter< ACE_LOCK > * | create_weak (void) |
| void | attach_weak (ACE_Bound_Ptr_Counter< ACE_LOCK > *counter) |
| Increase the counter reference count and return argument. | |
| void | detach_weak (ACE_Bound_Ptr_Counter< ACE_LOCK > *counter) |
| int | 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 | |
| ACE_Bound_Ptr_Counter< ACE_LOCK > * | internal_create (int init_obj_ref_count) |
Private Attributes | |
| int | obj_ref_count_ |
| int | self_ref_count_ |
| Reference count of this counter. | |
| ACE_LOCK | lock_ |
| Mutex variable to synchronize access to the reference counts. | |
Do not use this class directly, use ACE_Strong_Bound_Ptr or ACE_Weak_Bound_Ptr instead.
Definition at line 38 of file Bound_Ptr.h.
|
||||||||||
|
Definition at line 135 of file Bound_Ptr.inl.
00136 : obj_ref_count_ (init_obj_ref_count), 00137 self_ref_count_ (1) 00138 { 00139 } |
|
||||||||||
|
Definition at line 142 of file Bound_Ptr.inl.
00143 {
00144 }
|
|
||||||||||
|
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. References ACE_GUARD_RETURN, ACE_Bound_Ptr_Counter< ACE_LOCK >::lock_, ACE_Bound_Ptr_Counter< ACE_LOCK >::obj_ref_count_, and ACE_Bound_Ptr_Counter< ACE_LOCK >::self_ref_count_.
00041 {
00042 ACE_GUARD_RETURN (ACE_LOCK, guard, counter->lock_, -1);
00043
00044 // Can't attach a strong pointer to an object that has already been deleted.
00045 if (counter->obj_ref_count_ == -1)
00046 return -1;
00047
00048 int new_obj_ref_count = ++counter->obj_ref_count_;
00049 ++counter->self_ref_count_;
00050
00051 return new_obj_ref_count;
00052 }
|
|
||||||||||
|
Increase the counter reference count and return argument.
Definition at line 99 of file Bound_Ptr.inl. References ACE_GUARD, ACE_Bound_Ptr_Counter< ACE_LOCK >::lock_, and ACE_Bound_Ptr_Counter< ACE_LOCK >::self_ref_count_.
00100 {
00101 ACE_GUARD (ACE_LOCK, guard, counter->lock_);
00102
00103 ++counter->self_ref_count_;
00104 }
|
|
||||||||||
|
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. References ACE_ASSERT, ACE_throw_bad_alloc, and ACE_Bound_Ptr_Counter< ACE_LOCK >::internal_create().
00025 {
00026 // Set initial object reference count to 1.
00027 ACE_Bound_Ptr_Counter<ACE_LOCK> *temp = internal_create (1);
00028 #if defined (ACE_NEW_THROWS_EXCEPTIONS)
00029 if (temp == 0)
00030 ACE_throw_bad_alloc;
00031 #else
00032 ACE_ASSERT (temp != 0);
00033 #endif /* ACE_NEW_THROWS_EXCEPTIONS */
00034 return temp;
00035 }
|
|
||||||||||
|
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. References ACE_ASSERT, ACE_throw_bad_alloc, and ACE_Bound_Ptr_Counter< ACE_LOCK >::internal_create().
00085 {
00086 // Set initial object reference count to 0.
00087
00088 ACE_Bound_Ptr_Counter<ACE_LOCK> *temp = internal_create (0);
00089 #if defined (ACE_NEW_THROWS_EXCEPTIONS)
00090 if (temp == 0)
00091 ACE_throw_bad_alloc;
00092 #else
00093 ACE_ASSERT (temp != 0);
00094 #endif /* ACE_NEW_THROWS_EXCEPTIONS */
00095 return temp;
00096 }
|
|
||||||||||
|
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. References ACE_GUARD_RETURN, ACE_Bound_Ptr_Counter< ACE_LOCK >::lock_, ACE_Bound_Ptr_Counter< ACE_LOCK >::obj_ref_count_, and ACE_Bound_Ptr_Counter< ACE_LOCK >::self_ref_count_.
00056 {
00057 ACE_Bound_Ptr_Counter<ACE_LOCK> *counter_del = 0;
00058 int new_obj_ref_count;
00059
00060 {
00061 ACE_GUARD_RETURN (ACE_LOCK, guard, counter->lock_, -1);
00062
00063 if ((new_obj_ref_count = --counter->obj_ref_count_) == 0)
00064 // Change the object reference count to -1 to indicate that the
00065 // object has been deleted, as opposed to a weak pointer that
00066 // simply hasn't had any strong pointers created from it yet.
00067 counter->obj_ref_count_ = -1;
00068
00069 if (--counter->self_ref_count_ == 0)
00070 // Since counter contains the lock held by the ACE_Guard, the
00071 // guard needs to be released before freeing the memory holding
00072 // the lock. So save the pointer to free, then release, then
00073 // free.
00074 counter_del = counter;
00075
00076 } // Release the lock
00077
00078 delete counter_del;
00079
00080 return new_obj_ref_count;
00081 }
|
|
||||||||||
|
Decreases the counter reference count and deletes the counter if it has no more references. Definition at line 107 of file Bound_Ptr.inl. References ACE_GUARD, ACE_Bound_Ptr_Counter< ACE_LOCK >::lock_, and ACE_Bound_Ptr_Counter< ACE_LOCK >::self_ref_count_.
00108 {
00109 ACE_Bound_Ptr_Counter<ACE_LOCK> *counter_del = 0;
00110
00111 {
00112 ACE_GUARD (ACE_LOCK, guard, counter->lock_);
00113
00114 if (--counter->self_ref_count_ == 0)
00115 // Since counter contains the lock held by the ACE_Guard, the
00116 // guard needs to be released before freeing the memory holding
00117 // the lock. So save the pointer to free, then release, then
00118 // free.
00119 counter_del = counter;
00120
00121 } // Release the lock
00122
00123 delete counter_del;
00124 }
|
|
||||||||||
|
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. References ACE_NEW_RETURN. Referenced by ACE_Bound_Ptr_Counter< ACE_LOCK >::create_strong(), and ACE_Bound_Ptr_Counter< ACE_LOCK >::create_weak().
00015 {
00016 ACE_Bound_Ptr_Counter<ACE_LOCK> *temp = 0;
00017 ACE_NEW_RETURN (temp,
00018 ACE_Bound_Ptr_Counter<ACE_LOCK> (init_obj_ref_count),
00019 0);
00020 return temp;
00021 }
|
|
||||||||||
|
Determine whether the object has been deleted.
Definition at line 127 of file Bound_Ptr.inl. References ACE_GUARD_RETURN, ACE_Bound_Ptr_Counter< ACE_LOCK >::lock_, and ACE_Bound_Ptr_Counter< ACE_LOCK >::obj_ref_count_.
00128 {
00129 ACE_GUARD_RETURN (ACE_LOCK, guard, counter->lock_, 0);
00130
00131 return counter->obj_ref_count_ == -1;
00132 }
|
|
|||||
|
Declare the dynamic allocation hooks.
Definition at line 42 of file Bound_Ptr.h. |
|
|||||
|
Mutex variable to synchronize access to the reference counts.
Definition at line 92 of file Bound_Ptr.h. Referenced by ACE_Bound_Ptr_Counter< ACE_LOCK >::attach_strong(), ACE_Bound_Ptr_Counter< ACE_LOCK >::attach_weak(), ACE_Bound_Ptr_Counter< ACE_LOCK >::detach_strong(), ACE_Bound_Ptr_Counter< ACE_LOCK >::detach_weak(), and ACE_Bound_Ptr_Counter< ACE_LOCK >::object_was_deleted(). |
|
|||||
|
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 86 of file Bound_Ptr.h. Referenced by ACE_Bound_Ptr_Counter< ACE_LOCK >::attach_strong(), ACE_Bound_Ptr_Counter< ACE_LOCK >::detach_strong(), and ACE_Bound_Ptr_Counter< ACE_LOCK >::object_was_deleted(). |
|
|||||
|
Reference count of this counter.
Definition at line 89 of file Bound_Ptr.h. Referenced by ACE_Bound_Ptr_Counter< ACE_LOCK >::attach_strong(), ACE_Bound_Ptr_Counter< ACE_LOCK >::attach_weak(), ACE_Bound_Ptr_Counter< ACE_LOCK >::detach_strong(), and ACE_Bound_Ptr_Counter< ACE_LOCK >::detach_weak(). |
1.3.6