summaryrefslogtreecommitdiff
path: root/TAO/tao/Nested_Upcall_Guard.h
blob: e13950c4b07261a339ba91290353bb635e629a6e (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
98
99
100
101
102
103
104
105
// -*- C++ -*-

//=============================================================================
/**
 *  @file    Nested_Upcall_Guard.h
 *
 *  @author  Chris Cleeland <cleeland@ociweb.com>
 */
//=============================================================================


#ifndef TAO_NESTED_UPCALL_GUARD_H
#define TAO_NESTED_UPCALL_GUARD_H

#include /**/ "ace/pre.h"

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

#include "tao/Transport.h"
#include "tao/ORB_Core.h"
#include "tao/ORB_Core_TSS_Resources.h"
#include "tao/debug.h"

TAO_BEGIN_VERSIONED_NAMESPACE_DECL
namespace TAO
{
  /**
   * @class Nested_Upcall_Guard
   *
   * @brief: Magic class that sets the status of the thread in the
   * TSS.
   *
   * This class was originally internal to the Wait_On_LF_NoUpcall
   * implementation, but now it needs to be shared with the LF
   * Connect wait as well.
   */
  class Nested_Upcall_Guard
  {
  public:
    // Maybe we should instead just take in a ptr to
    // TAO_ORB_Core_TSS_Resources?  Or at least ORB_Core*?
    explicit Nested_Upcall_Guard (TAO_Transport *t, bool enable=true)
      : t_ (t),
        enable_ (enable)
    {
      if (!this->enable_)
        {
          return;
        }

      TAO_ORB_Core_TSS_Resources *tss =
        t_->orb_core ()->get_tss_resources ();

      tss->upcalls_temporarily_suspended_on_this_thread_ = true;

      if (TAO_debug_level > 6)
        TAOLIB_DEBUG ((LM_DEBUG,
                    "TAO (%P|%t) - Wait_On_LF_No_Upcall[%d]::wait, "
                    "disabling upcalls\n", t->id ()));
    }

    ~Nested_Upcall_Guard ()
    {
      if (!this->enable_)
        {
          return;
        }

      TAO_ORB_Core_TSS_Resources *tss =
        this->t_->orb_core ()->get_tss_resources ();

      tss->upcalls_temporarily_suspended_on_this_thread_ = false;

      if (TAO_debug_level > 6)
        {
          TAOLIB_DEBUG ((LM_DEBUG,
                      "TAO (%P|%t) - Wait_On_LF_No_Upcall[%d]::wait, "
                      "re-enabling upcalls\n", this->t_->id ()));
        }
    }

  private:
    Nested_Upcall_Guard ();

    Nested_Upcall_Guard (const Nested_Upcall_Guard&) = delete;
    Nested_Upcall_Guard &operator= (const Nested_Upcall_Guard&) = delete;
    Nested_Upcall_Guard (Nested_Upcall_Guard&&) = delete;
    Nested_Upcall_Guard &operator= (Nested_Upcall_Guard&&) = delete;

  private:
    /// Pointer to the transport that we plan to use.
    TAO_Transport *t_;

    /// A flag to support conditional waiting in the LF_Connect_Strategy
    bool enable_;
  };
}

TAO_END_VERSIONED_NAMESPACE_DECL

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

#endif /* TAO_NESTED_UPCALL_GUARD_H */