summaryrefslogtreecommitdiff
path: root/TAO/orbsvcs/orbsvcs/ESF/ESF_Proxy_RefCount_Guard.h
blob: 4000763686ffda155e11fbd1ebecdb4ef8a47ab8 (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
// -*- C++ -*-

/**
 *  @file   ESF_Proxy_RefCount_Guard.h
 *
 *  @author Carlos O'Ryan (coryan@cs.wustl.edu)
 *
 *  http://doc.ece.uci.edu/~coryan/EC/index.html
 */

#ifndef TAO_ESF_PROXY_REFCOUNT_GUARD_H
#define TAO_ESF_PROXY_REFCOUNT_GUARD_H

#include "tao/Basic_Types.h"

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

TAO_BEGIN_VERSIONED_NAMESPACE_DECL

/**
 * @class TAO_ESF_Proxy_RefCount_Guard
 *
 * @brief Reference count based guard.
 *
 * A common idiom used on event services is to increment a
 * reference count before starting a long running operation.
 * The system can then execute the operation without any risk of
 * having the underlying object destroyed.  The advantage of using
 * a reference count is that no mutex or lock needs to be held
 * while the operation is being executed.
 * This class implements that common idiom, but it also adds hooks
 * to handle scenarios where more than one operation is performed
 * while holding the reference count.
 *
 * @todo The type of lock could be parametric
 */
template<class EVENT_CHANNEL, class PROXY>
class TAO_ESF_Proxy_RefCount_Guard
{
public:
  /// Constructor
  TAO_ESF_Proxy_RefCount_Guard (CORBA::ULong &refcount,
                                EVENT_CHANNEL *ec,
                                PROXY *proxy);

  /// Destructor
  ~TAO_ESF_Proxy_RefCount_Guard ();

protected:
  /// The reference count, if it gets to zero then the object must be
  /// destroyed
  CORBA::ULong &refcount_;

  /// The event channel used to destroy the proxy
  EVENT_CHANNEL *event_channel_;

  /// The proxy whose lifetime is controlled by the reference count
  PROXY *proxy_;
};

TAO_END_VERSIONED_NAMESPACE_DECL

#if defined (__ACE_INLINE__)
#include "orbsvcs/ESF/ESF_Proxy_RefCount_Guard.inl"
#endif /* __ACE_INLINE__ */

#include "orbsvcs/ESF/ESF_Proxy_RefCount_Guard.cpp"

#endif /* TAO_ESF_PROXY_REFCOUNT_GUARD_H */