summaryrefslogtreecommitdiff
path: root/ACE/ace/Signal.inl
blob: 04ecfbfb49fa906c456746767a7555e083489062 (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
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
// -*- C++ -*-
//
// $Id$

#include "ace/OS_NS_signal.h"
#include "ace/config-all.h"
#include "ace/Trace.h"
#include "ace/Object_Manager_Base.h"
#include "ace/OS_NS_Thread.h"

ACE_BEGIN_VERSIONED_NAMESPACE_DECL

ACE_INLINE
ACE_Sig_Set::ACE_Sig_Set (sigset_t *ss)
  // : sigset_ ()
{
  ACE_TRACE ("ACE_Sig_Set::ACE_Sig_Set");

  if (ss == 0)
    ACE_OS::sigfillset (&this->sigset_);
  else
    // Structure assignment.
    this->sigset_ = *ss;
}

ACE_INLINE
ACE_Sig_Set::ACE_Sig_Set (int fill)
  // : sigset_ ()
{
  ACE_TRACE ("ACE_Sig_Set::ACE_Sig_Set");

  if (fill)
    ACE_OS::sigfillset (&this->sigset_);
  else
    ACE_OS::sigemptyset (&this->sigset_);
}

ACE_INLINE
ACE_Sig_Set::ACE_Sig_Set (ACE_Sig_Set *ss)
  // : sigset_ ()
{
  ACE_TRACE ("ACE_Sig_Set::ACE_Sig_Set");

  if (ss == 0)
    ACE_OS::sigfillset (&this->sigset_);
  else
    this->sigset_ = ss->sigset_;
}

ACE_INLINE int
ACE_Sig_Set::empty_set (void)
{
  ACE_TRACE ("ACE_Sig_Set::empty_set");
  return ACE_OS::sigemptyset (&this->sigset_);
}

ACE_INLINE int
ACE_Sig_Set::fill_set (void)
{
  ACE_TRACE ("ACE_Sig_Set::fill_set");
  return ACE_OS::sigfillset (&this->sigset_);
}

ACE_INLINE int
ACE_Sig_Set::sig_add (int signo)
{
  ACE_TRACE ("ACE_Sig_Set::sig_add");
  return ACE_OS::sigaddset (&this->sigset_, signo);
}

ACE_INLINE int
ACE_Sig_Set::sig_del (int signo)
{
  ACE_TRACE ("ACE_Sig_Set::sig_del");
  return ACE_OS::sigdelset (&this->sigset_, signo);
}

ACE_INLINE int
ACE_Sig_Set::is_member (int signo) const
{
  ACE_TRACE ("ACE_Sig_Set::is_member");
  return ACE_OS::sigismember (const_cast<sigset_t *> (&this->sigset_), signo);
}

ACE_INLINE
ACE_Sig_Set::operator sigset_t *(void)
{
  ACE_TRACE ("ACE_Sig_Set::operator sigset_t *");
  return &this->sigset_;
}

ACE_INLINE sigset_t
ACE_Sig_Set::sigset (void) const
{
  ACE_TRACE ("ACE_Sig_Set::sigset");
  return this->sigset_;
}

ACE_INLINE int
ACE_Sig_Action::flags (void)
{
  ACE_TRACE ("ACE_Sig_Action::flags");
  return this->sa_.sa_flags;
}

ACE_INLINE void
ACE_Sig_Action::flags (int flags)
{
  ACE_TRACE ("ACE_Sig_Action::flags");
  this->sa_.sa_flags = flags;
}

ACE_INLINE sigset_t *
ACE_Sig_Action::mask (void)
{
  ACE_TRACE ("ACE_Sig_Action::mask");
  return &this->sa_.sa_mask;
}

ACE_INLINE void
ACE_Sig_Action::mask (sigset_t *ss)
{
  ACE_TRACE ("ACE_Sig_Action::mask");
  if (ss != 0)
    this->sa_.sa_mask = *ss; // Structure assignment
}

ACE_INLINE void
ACE_Sig_Action::mask (ACE_Sig_Set &ss)
{
  ACE_TRACE ("ACE_Sig_Action::mask");
  this->sa_.sa_mask = ss.sigset (); // Structure assignment
}

ACE_INLINE ACE_SignalHandler
ACE_Sig_Action::handler (void)
{
  ACE_TRACE ("ACE_Sig_Action::handler");
  return ACE_SignalHandler (this->sa_.sa_handler);
}

ACE_INLINE void
ACE_Sig_Action::handler (ACE_SignalHandler handler)
{
  ACE_TRACE ("ACE_Sig_Action::handler");
#if !defined(ACE_HAS_TANDEM_SIGNALS)
  this->sa_.sa_handler = ACE_SignalHandlerV (handler);
#else
  this->sa_.sa_handler = (void (*)()) ACE_SignalHandlerV (handler);
#endif /* !ACE_HAS_TANDEM_SIGNALS */
}

#if 0
ACE_INLINE ACE_SignalHandler
ACE_Sig_Action::sigaction (void)
{
  ACE_TRACE ("ACE_Sig_Action::sigaction");
  return ACE_SignalHandler (this->sa_.sa_sigaction);
}

ACE_INLINE void
ACE_Sig_Action::sigaction (ACE_SignalHandler handler)
{
  ACE_TRACE ("ACE_Sig_Action::sigaction");
  this->sa_.sa_sigaction = (void (*)()) ACE_SignalHandlerV (handler);
}
#endif /* 0 */

ACE_INLINE void
ACE_Sig_Action::set (struct sigaction *sa)
{
  ACE_TRACE ("ACE_Sig_Action::set");
  this->sa_ = *sa; // Structure assignment.
}

ACE_INLINE struct sigaction *
ACE_Sig_Action::get (void)
{
  ACE_TRACE ("ACE_Sig_Action::get");
  return &this->sa_;
}

ACE_INLINE
ACE_Sig_Action::operator struct sigaction * ()
{
  ACE_TRACE ("ACE_Sig_Action::operator struct sigaction *");
  return &this->sa_;
}

ACE_INLINE
ACE_Sig_Action::ACE_Sig_Action (const ACE_Sig_Action &s)
  // : sa_ ()
{
  ACE_TRACE ("ACE_Sig_Action::ACE_Sig_Action");
  *this = s; // structure copy.
}

ACE_INLINE int
ACE_Sig_Action::register_action (int signum, ACE_Sig_Action *oaction)
{
  ACE_TRACE ("ACE_Sig_Action::register_action");
  struct sigaction *sa = oaction == 0 ? 0 : oaction->get ();

  return ACE_OS::sigaction (signum, &this->sa_, sa);
}

ACE_INLINE int
ACE_Sig_Action::retrieve_action (int signum)
{
  ACE_TRACE ("ACE_Sig_Action::retrieve_action");
  return ACE_OS::sigaction (signum, 0, &this->sa_);
}

ACE_INLINE int
ACE_Sig_Action::restore_action (int signum, ACE_Sig_Action &oaction)
{
  ACE_TRACE ("ACE_Sig_Action::restore_action");
  this->sa_ = *oaction.get (); // Structure assignment
  return ACE_OS::sigaction (signum, &this->sa_, 0);
}

// Block out the signal MASK until the destructor is called.

ACE_INLINE
ACE_Sig_Guard::ACE_Sig_Guard (ACE_Sig_Set *mask,
                              bool condition)
  : omask_ ()
  , condition_ (condition)
{
  //ACE_TRACE ("ACE_Sig_Guard::ACE_Sig_Guard");
  if (!this->condition_)
    return;

#if defined (ACE_LACKS_UNIX_SIGNALS)
  ACE_UNUSED_ARG (mask);
#else
  // If MASK is 0 then block all signals!
  if (mask == 0)
    {
#  if defined (ACE_LACKS_PTHREAD_THR_SIGSETMASK)
      ACE_OS::sigprocmask (SIG_BLOCK,
                           ACE_OS_Object_Manager::default_mask (),
                           (sigset_t *) this->omask_);
#  else
      ACE_OS::thr_sigsetmask (SIG_BLOCK,
                              ACE_OS_Object_Manager::default_mask (),
                              (sigset_t *) this->omask_);
#  endif /* ACE_LACKS_PTHREAD_THR_SIGSETMASK */
    }
  else
#  if defined (ACE_LACKS_PTHREAD_THR_SIGSETMASK)
    ACE_OS::sigprocmask (SIG_BLOCK,
                         (sigset_t *) *mask,
                         (sigset_t *)
                         this->omask_);
#  else
    ACE_OS::thr_sigsetmask (SIG_BLOCK,
                            (sigset_t *) *mask,
                            (sigset_t *)
                            this->omask_);
#  endif /* ACE_LACKS_PTHREAD_THR_SIGSETMASK */
#endif /* ACE_LACKS_UNIX_SIGNALS */
}

ACE_END_VERSIONED_NAMESPACE_DECL