summaryrefslogtreecommitdiff
path: root/TAO/orbsvcs/orbsvcs/Notify/Refcountable.h
blob: 77a45cd16fa5e803ee1d676f4954dd7fb35638d7 (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
/* -*- C++ -*- */
/**
 *  @file Refcountable.h
 *
 *  $Id$
 *
 *  @author Pradeep Gore <pradeep@oomworks.com>
 *
 *
 */

#ifndef TAO_NS_REFCOUNTABLE_H
#define TAO_NS_REFCOUNTABLE_H
#include "ace/pre.h"

#include "notify_export.h"

#if !defined (ACE_LACKS_PRAGMA_ONCE)
# pragma once
#endif /* ACE_LACKS_PRAGMA_ONCE */

#include "ace/Synch_T.h"
#include "tao/orbconf.h"
#include "tao/corbafwd.h"

/**
 * @class TAO_NS_Refcountable
 *
 * @brief Thread-safe refounting, calls the <release> method when refcount falls to 0.
 *
 */
class TAO_Notify_Export TAO_NS_Refcountable
{
public:
  /// Constuctor
  TAO_NS_Refcountable (void);

  /// Destructor
  virtual ~TAO_NS_Refcountable ();

  /// This method sigantures deliberately match the RefCounting methods required for ESF Proxy
  CORBA::ULong _incr_refcnt (void);
  CORBA::ULong _decr_refcnt (void);

  /// The release method is called when the refcount reaches 0.
  virtual void release (void) = 0;

protected:
  /// The reference count.
  CORBA::ULong refcount_;

  /// The mutex to serialize access to state variables.
  TAO_SYNCH_MUTEX lock_;
};

/***********************************************************************/

/**
 * @class TAO_NS_Refcountable_Guard
 *
 * @brief Ref. Count Guard
 *        Increments the reference count in the constructor, the count is decremented when the guard's is destructor.
 *
 */
class TAO_Notify_Export TAO_NS_Refcountable_Guard
{
public:
  TAO_NS_Refcountable_Guard (TAO_NS_Refcountable& refcountable);

  ~TAO_NS_Refcountable_Guard ();

protected:
  TAO_NS_Refcountable& refcountable_;
};

#if defined (__ACE_INLINE__)
#include "Refcountable.inl"
#endif /* __ACE_INLINE__ */

#include "ace/post.h"
#endif /* TAO_NS_REFCOUNTABLE_H */