blob: 10c53019a7c416231287cb41ef95ee952fc5625b (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
|
// -*- C++ -*-
/**
* @file Refcountable.h
*
* @author Pradeep Gore <pradeep@oomworks.com>
*/
#ifndef TAO_Notify_REFCOUNTABLE_H
#define TAO_Notify_REFCOUNTABLE_H
#include /**/ "ace/pre.h"
#include "orbsvcs/Notify/notify_serv_export.h"
#include "orbsvcs/Notify/Refcountable_Guard_T.h"
#if !defined (ACE_LACKS_PRAGMA_ONCE)
# pragma once
#endif /* ACE_LACKS_PRAGMA_ONCE */
#include "tao/orbconf.h"
#include "tao/Basic_Types.h"
#include "ace/Synch_Traits.h"
#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.
*
* 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.
*
* 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;
/// Constructor
TAO_Notify_Refcountable ();
/// Destructor
/// public for stack allocated instances
virtual ~TAO_Notify_Refcountable ();
/// This method signatures deliberately match the RefCounting methods required for ESF Proxy
/// Public for bridge implementations and various guard classes
CORBA::ULong _incr_refcnt ();
CORBA::ULong _decr_refcnt ();
#if (TAO_NOTIFY_REFCOUNT_DIAGNOSTICS != 0)
static void diagnostic_dump( const char* title = 0 );
#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
};
TAO_END_VERSIONED_NAMESPACE_DECL
#include /**/ "ace/post.h"
#endif /* TAO_Notify_REFCOUNTABLE_H */
|