summaryrefslogtreecommitdiff
path: root/ace/Message_Queue.i
blob: 73bdb402b8fb164492cc1886a61f94e5a352fb08 (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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
/* -*- C++ -*- */
// $Id$

// Message_Queue.i

template <ACE_SYNCH_1> ACE_INLINE ACE_Notification_Strategy *
ACE_Message_Queue<ACE_SYNCH_2>::notification_strategy (void)
{
  ACE_TRACE ("ACE_Message_Queue<ACE_SYNCH_2>::notification_strategy");

  return this->notification_strategy_;
}

template <ACE_SYNCH_1> ACE_INLINE void
ACE_Message_Queue<ACE_SYNCH_2>::notification_strategy (ACE_Notification_Strategy *s)
{
  ACE_TRACE ("ACE_Message_Queue<ACE_SYNCH_2>::notification_strategy");

  this->notification_strategy_ = s;
}

// Check if queue is empty (does not hold locks). 

template <ACE_SYNCH_1> ACE_INLINE int
ACE_Message_Queue<ACE_SYNCH_2>::is_empty_i (void)
{
  ACE_TRACE ("ACE_Message_Queue<ACE_SYNCH_2>::is_empty_i");
  return this->cur_bytes_ <= 0 && this->cur_count_ <= 0;
}

// Check if queue is full (does not hold locks). 

template <ACE_SYNCH_1> ACE_INLINE int 
ACE_Message_Queue<ACE_SYNCH_2>::is_full_i (void)
{
  ACE_TRACE ("ACE_Message_Queue<ACE_SYNCH_2>::is_full_i");
  return this->cur_bytes_ > this->high_water_mark_;
}

// Check if queue is empty (holds locks).

template <ACE_SYNCH_1> ACE_INLINE int 
ACE_Message_Queue<ACE_SYNCH_2>::is_empty (void)
{
  ACE_TRACE ("ACE_Message_Queue<ACE_SYNCH_2>::is_empty");
  ACE_GUARD_RETURN (ACE_SYNCH_MUTEX, ace_mon, this->lock_, -1);

  return this->is_empty_i ();
}

// Check if queue is full (holds locks).

template <ACE_SYNCH_1> ACE_INLINE int 
ACE_Message_Queue<ACE_SYNCH_2>::is_full (void)
{
  ACE_TRACE ("ACE_Message_Queue<ACE_SYNCH_2>::is_full");
  ACE_GUARD_RETURN (ACE_SYNCH_MUTEX, ace_mon, this->lock_, -1);

  return this->is_full_i ();
}

template <ACE_SYNCH_1> ACE_INLINE size_t
ACE_Message_Queue<ACE_SYNCH_2>::high_water_mark (void)
{
  ACE_TRACE ("ACE_Message_Queue<ACE_SYNCH_2>::high_water_mark");
  ACE_GUARD_RETURN (ACE_SYNCH_MUTEX, ace_mon, this->lock_, 0);

  return this->high_water_mark_;
}

template <ACE_SYNCH_1> ACE_INLINE void 
ACE_Message_Queue<ACE_SYNCH_2>::high_water_mark (size_t hwm)
{
  ACE_TRACE ("ACE_Message_Queue<ACE_SYNCH_2>::high_water_mark");
  ACE_GUARD (ACE_SYNCH_MUTEX, ace_mon, this->lock_);

  this->high_water_mark_ = hwm;
}

template <ACE_SYNCH_1> ACE_INLINE size_t
ACE_Message_Queue<ACE_SYNCH_2>::low_water_mark (void)
{
  ACE_TRACE ("ACE_Message_Queue<ACE_SYNCH_2>::low_water_mark");
  ACE_GUARD_RETURN (ACE_SYNCH_MUTEX, ace_mon, this->lock_, 0);

  return this->low_water_mark_;
}

template <ACE_SYNCH_1> ACE_INLINE void 
ACE_Message_Queue<ACE_SYNCH_2>::low_water_mark (size_t lwm)
{
  ACE_TRACE ("ACE_Message_Queue<ACE_SYNCH_2>::low_water_mark");
  ACE_GUARD (ACE_SYNCH_MUTEX, ace_mon, this->lock_);

  this->low_water_mark_ = lwm;
}

// Return the current number of bytes in the queue.

template <ACE_SYNCH_1> ACE_INLINE size_t
ACE_Message_Queue<ACE_SYNCH_2>::message_bytes (void)
{ 
  ACE_TRACE ("ACE_Message_Queue<ACE_SYNCH_2>::message_bytes");
  ACE_GUARD_RETURN (ACE_SYNCH_MUTEX, ace_mon, this->lock_, 0);

  return this->cur_bytes_;
}

// Return the current number of messages in the queue.

template <ACE_SYNCH_1> ACE_INLINE size_t
ACE_Message_Queue<ACE_SYNCH_2>::message_count (void)
{
  ACE_TRACE ("ACE_Message_Queue<ACE_SYNCH_2>::message_count");
  ACE_GUARD_RETURN (ACE_SYNCH_MUTEX, ace_mon, this->lock_, 0);

  return this->cur_count_;
}

template <ACE_SYNCH_1> int
ACE_Message_Queue<ACE_SYNCH_2>::activate (void)
{
  ACE_TRACE ("ACE_Message_Queue<ACE_SYNCH_2>::activate");
  ACE_GUARD_RETURN (ACE_SYNCH_MUTEX, ace_mon, this->lock_, -1);

  return this->activate_i ();
}

template <ACE_SYNCH_1> int
ACE_Message_Queue<ACE_SYNCH_2>::deactivate (void)
{
  ACE_TRACE ("ACE_Message_Queue<ACE_SYNCH_2>::deactivate");
  ACE_GUARD_RETURN (ACE_SYNCH_MUTEX, ace_mon, this->lock_, -1);

  return this->deactivate_i ();
}

template <ACE_SYNCH_1>
ACE_Message_Queue_Iterator<ACE_SYNCH_2>::ACE_Message_Queue_Iterator (ACE_Message_Queue <ACE_SYNCH_2> &queue)
: queue_ (queue),
  curr_ (queue_.head_)
{
}

template <ACE_SYNCH_1> int 
ACE_Message_Queue_Iterator<ACE_SYNCH_2>::next (ACE_Message_Block *&entry)
{
  ACE_Read_Guard<ACE_SYNCH_MUTEX> m (this->queue_.lock_);

  if (this->curr_ != 0)
    {
      entry = this->curr_;
      return 1;
    }
  else
    return 0;
}

template <ACE_SYNCH_1> int
ACE_Message_Queue_Iterator<ACE_SYNCH_2>::advance (void)
{
  ACE_Read_Guard<ACE_SYNCH_MUTEX> m (this->queue_.lock_);

  this->curr_ = this->curr_->next ();
  return this->curr_ != 0;
}

template <ACE_SYNCH_1> void 
ACE_Message_Queue_Iterator<ACE_SYNCH_2>::dump (void) const
{
}

ACE_ALLOC_HOOK_DEFINE(ACE_Message_Queue_Iterator)


template <ACE_SYNCH_1>
ACE_Message_Queue_Reverse_Iterator<ACE_SYNCH_2>::ACE_Message_Queue_Reverse_Iterator (ACE_Message_Queue <ACE_SYNCH_2> &queue)
: queue_ (queue),
  curr_ (queue_.tail_)
{
}

template <ACE_SYNCH_1> int 
ACE_Message_Queue_Reverse_Iterator<ACE_SYNCH_2>::next (ACE_Message_Block *&entry)
{
  ACE_Read_Guard<ACE_SYNCH_MUTEX> m (this->queue_.lock_);

  if (this->curr_ != 0)
    {
      entry = this->curr_;
      return 1;
    }
  else
    return 0;
}

template <ACE_SYNCH_1> int
ACE_Message_Queue_Reverse_Iterator<ACE_SYNCH_2>::advance (void)
{
  ACE_Read_Guard<ACE_SYNCH_MUTEX> m (this->queue_.lock_);

  this->curr_ = this->curr_->prev ();
  return this->curr_ != 0;
}

template <ACE_SYNCH_1> void 
ACE_Message_Queue_Reverse_Iterator<ACE_SYNCH_2>::dump (void) const
{
}

ACE_ALLOC_HOOK_DEFINE(ACE_Message_Queue_Reverse_Iterator)