summaryrefslogtreecommitdiff
path: root/TAO/orbsvcs/orbsvcs/Event/EC_ProxyPushSupplier_Set_T.cpp
blob: e2a6029e376761f3427883d12ded58ab2df41aab (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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
// $Id$

#ifndef TAO_EC_PROXYPUSHSUPPLIER_SET_T_CPP
#define TAO_EC_PROXYPUSHSUPPLIER_SET_T_CPP

#include "EC_ProxyPushSupplier_Set_T.h"
#include "EC_Command.h"

#if ! defined (__ACE_INLINE__)
#include "EC_ProxyPushSupplier_Set_T.i"
#endif /* __ACE_INLINE__ */

ACE_RCSID(Event, EC_ProxyPushSupplier_Set_T, "$Id$")

template<class ACE_LOCK>int
TAO_EC_ProxyPushSupplier_Set_Immediate<ACE_LOCK>::busy (void)
{
  return this->lock_.acquire_read ();
}

template<class ACE_LOCK> int
TAO_EC_ProxyPushSupplier_Set_Immediate<ACE_LOCK>::idle (void)
{
  return this->lock_.release ();
}

template<class ACE_LOCK> void
TAO_EC_ProxyPushSupplier_Set_Immediate<ACE_LOCK>::connected (
      TAO_EC_ProxyPushSupplier* supplier,
      CORBA::Environment& ACE_TRY_ENV)
{
  ACE_GUARD_THROW (ACE_LOCK, ace_mon, this->lock_,
      RtecEventChannelAdmin::EventChannel::SYNCHRONIZATION_ERROR ());

  supplier->_incr_refcnt ();
  this->connected_i (supplier, ACE_TRY_ENV);
}

template<class ACE_LOCK> void
TAO_EC_ProxyPushSupplier_Set_Immediate<ACE_LOCK>::disconnected (
      TAO_EC_ProxyPushSupplier* supplier,
      CORBA::Environment& ACE_TRY_ENV)
{
  ACE_GUARD_THROW (ACE_LOCK, ace_mon, this->lock_,
      RtecEventChannelAdmin::EventChannel::SYNCHRONIZATION_ERROR ());

  this->disconnected_i (supplier, ACE_TRY_ENV);
}

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

template<ACE_SYNCH_DECL>int
TAO_EC_ProxyPushSupplier_Set_Delayed<ACE_SYNCH_USE>::busy (void)
{
  ACE_GUARD_RETURN (ACE_SYNCH_MUTEX_T, ace_mon, this->lock_, -1);

  while (this->busy_count_ >= this->busy_hwm ()
         || this->write_delay_ >= this->max_write_delay ())
    this->busy_cond_.wait ();
  this->busy_count_++;

  return 0;
}

template<ACE_SYNCH_DECL> int
TAO_EC_ProxyPushSupplier_Set_Delayed<ACE_SYNCH_USE>::idle (void)
{
  ACE_GUARD_RETURN (ACE_SYNCH_MUTEX_T, ace_mon, this->lock_, -1);

  this->busy_count_--;
  if (this->busy_count_ == 0)
    {
      this->write_delay_ = 0;
      this->execute_delayed_operations ();
      this->busy_cond_.broadcast ();
    }
  return 0;
}

template<ACE_SYNCH_DECL> void
TAO_EC_ProxyPushSupplier_Set_Delayed<ACE_SYNCH_USE>::connected (
      TAO_EC_ProxyPushSupplier* supplier,
      CORBA::Environment& ACE_TRY_ENV)
{
  ACE_GUARD_THROW (ACE_SYNCH_MUTEX_T, ace_mon, this->lock_,
      RtecEventChannelAdmin::EventChannel::SYNCHRONIZATION_ERROR ());

  if (this->busy_count_ == 0)
    {
      // We can add the object immediately
      this->connected_i (supplier, ACE_TRY_ENV);
    }
  else
    {
      supplier->_incr_refcnt ();
      ACE_Command_Base* command;
      ACE_NEW (command,
               TAO_EC_ProxyPushSupplier_Set::Connected_Command (this,
                                                        supplier));

      ACE_DEBUG ((LM_DEBUG,
                  "EC (%P|%t) Delayed connection command = %x\n",
                  command));

      this->command_queue_.enqueue_tail (command);
      this->write_delay_++;
    }
}

template<ACE_SYNCH_DECL> void
TAO_EC_ProxyPushSupplier_Set_Delayed<ACE_SYNCH_USE>::disconnected (
      TAO_EC_ProxyPushSupplier* supplier,
      CORBA::Environment& ACE_TRY_ENV)
{
  ACE_GUARD_THROW (ACE_SYNCH_MUTEX_T, ace_mon, this->lock_,
      RtecEventChannelAdmin::EventChannel::SYNCHRONIZATION_ERROR ());

  if (this->busy_count_ == 0)
    {
      // We can remove the object immediately
      this->disconnected_i (supplier, ACE_TRY_ENV);
    }
  else
    {
      ACE_Command_Base* command;
      ACE_NEW (command,
               TAO_EC_ProxyPushSupplier_Set::Disconnected_Command (this,
                                                           supplier));
      ACE_DEBUG ((LM_DEBUG,
                  "EC (%P|%t) Delayed disconnection command = %x\n",
                  command));

      this->command_queue_.enqueue_tail (command);
      this->write_delay_++;
    }
}

template<ACE_SYNCH_DECL> void
TAO_EC_ProxyPushSupplier_Set_Delayed<ACE_SYNCH_USE>::execute_delayed_operations (void)
{
  // LOCKING: the lock is taken by the idle() function
  while (!this->command_queue_.is_empty ())
    {
      ACE_Command_Base* command;
      this->command_queue_.dequeue_head (command);

      command->execute ();

      ACE_DEBUG ((LM_DEBUG,
                  "EC (%P|%t) Executed delayed command = %x\n",
                  command));

      delete command;
    }
}

#endif /* TAO_EC_PROXYPUSHSUPPLIER_SET_T_CPP */