summaryrefslogtreecommitdiff
path: root/TAO/orbsvcs/orbsvcs/Notify/Refcountable.h
diff options
context:
space:
mode:
Diffstat (limited to 'TAO/orbsvcs/orbsvcs/Notify/Refcountable.h')
-rw-r--r--TAO/orbsvcs/orbsvcs/Notify/Refcountable.h65
1 files changed, 26 insertions, 39 deletions
diff --git a/TAO/orbsvcs/orbsvcs/Notify/Refcountable.h b/TAO/orbsvcs/orbsvcs/Notify/Refcountable.h
index 960c7e37a93..1d03486f3d1 100644
--- a/TAO/orbsvcs/orbsvcs/Notify/Refcountable.h
+++ b/TAO/orbsvcs/orbsvcs/Notify/Refcountable.h
@@ -1,11 +1,12 @@
-// -*- C++ -*-
-
+/* -*- C++ -*- */
/**
* @file Refcountable.h
*
* $Id$
*
* @author Pradeep Gore <pradeep@oomworks.com>
+ *
+ *
*/
#ifndef TAO_Notify_REFCOUNTABLE_H
@@ -13,8 +14,8 @@
#include /**/ "ace/pre.h"
-#include "orbsvcs/Notify/notify_serv_export.h"
-#include "orbsvcs/Notify/Refcountable_Guard_T.h"
+#include "notify_serv_export.h"
+#include "Refcountable_Guard_T.h"
#if !defined (ACE_LACKS_PRAGMA_ONCE)
# pragma once
@@ -26,43 +27,33 @@
#include "ace/Thread_Mutex.h"
#include "ace/Atomic_Op.h"
-// Debugging macros
-#ifndef TAO_NOTIFY_REFCOUNT_DIAGNOSTICS
-#define TAO_NOTIFY_REFCOUNT_DIAGNOSTICS 0
-#endif
-
-TAO_BEGIN_VERSIONED_NAMESPACE_DECL
-
/**
* @class TAO_Notify_Refcountable
*
* @brief Thread-safe refounting, calls the <release> method when refcount falls to 0.
*
- * The refcount is initialized to 0. When an instance of a
- * derived class becomes owned by a managed pointer
- * (Refcountable_Guard_T) the reference count becomes non-zero.
+ * The refcount is initialized to 0. When an instance of a derived class becomes owned
+ * by a managed pointer (Refcountable_Guard_T) the reference count becomes non-zero.
+ * A debug message is printed from the destructor if a refcounted is deleted with a
+ * non-zero refcount.
*
- * Instances declared on the stack should always have a
- * refcount of zero.
+ * Instances declared on the stack should always have a refcount of zero.
*
- * A method that creates or simply returns an instance of
- * Refcountable should not increment the reference count. It is
- * the responsibility of the client to increment the reference
- * count (take ownership or guard against deletion). The client
- * cannot know if the method will or will not incr the refcount
- * on its behalf.
+ * A method that creates or simply returns an instance of Refcountable should not
+ * increment the reference count. It is the responsibility of the client to increment
+ * the reference count (take ownership or guard against deletion). The client cannot
+ * know if the method will or will not incr the refcount in its behalf.
*
- * Use Refcountable_Guard_T or similar service to guarantee the
- * exception safe direct pairing of increments and decrements. Avoid
- * calling _incr_refcnt and _decr_refcnt.
+ * Use Refcountable_Guard_T or similar service to guarantee the exception safe direct
+ * pairing of increments and decrements. Avoid calling _incr_refcnt and _decr_refcnt.
*/
-
class TAO_Notify_Serv_Export TAO_Notify_Refcountable
{
public:
typedef TAO_Notify_Refcountable_Guard_T< TAO_Notify_Refcountable > Ptr;
+ typedef long Counter;
- /// Constructor
+ /// Constuctor
TAO_Notify_Refcountable (void);
/// Destructor
@@ -74,26 +65,22 @@ public:
CORBA::ULong _incr_refcnt (void);
CORBA::ULong _decr_refcnt (void);
-#if ( TAO_NOTIFY_REFCOUNT_DIAGNOSTICS != 0 )
- static void diagnostic_dump( const char* title = 0 );
+protected:
+ /// The mutex to serialize access to state variables.
+ TAO_SYNCH_MUTEX lock_;
+
+ /// Accessor for debugging.
+#ifdef _DEBUG
+ Counter refcount (void) const;
#endif
private:
/// The release method is called when the refcount reaches 0.
virtual void release (void) = 0;
- // Use a signed counter so that we can more easily detect
- // boundary conditions such as too many _decr_refcnt() calls.
- ACE_Atomic_Op<TAO_SYNCH_MUTEX, CORBA::Long> refcount_;
-
-#if ( TAO_NOTIFY_REFCOUNT_DIAGNOSTICS != 0 )
- friend class TAO_Notify_Tracker;
- int ref_id_;
-#endif
+ ACE_Atomic_Op< TAO_SYNCH_MUTEX, Counter > refcount_;
};
-TAO_END_VERSIONED_NAMESPACE_DECL
-
#include /**/ "ace/post.h"
#endif /* TAO_Notify_REFCOUNTABLE_H */