summaryrefslogtreecommitdiff
path: root/ace/Thread.i
blob: 1684c0c7f14aec3b59d29201c1b0c13ab597f805 (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
/* -*- C++ -*- */
// $Id$

// Thread.i

// Allocates a <keyp> that is used to identify data that is specific
// to each thread in the process.  The key is global to all threads in
// the process.

ACE_INLINE int
ACE_Thread::keycreate (ACE_thread_key_t *keyp,
#if defined (ACE_HAS_THR_C_DEST)
		       ACE_THR_C_DEST destructor,
#else
		       ACE_THR_DEST destructor,
#endif /* ACE_HAS_THR_C_DEST */
		       void *inst)
{
  ACE_TRACE ("ACE_Thread::keycreate");
  return ACE_OS::thr_keycreate (keyp, destructor, inst);
}

// Free up the key so that other threads can reuse it.

ACE_INLINE int
ACE_Thread::keyfree (ACE_thread_key_t key)
{
  ACE_TRACE ("ACE_Thread::keyfree");
  return ACE_OS::thr_keyfree (key);
}

// Bind value to the thread-specific data key, <key>, for the calling
// thread.

ACE_INLINE int 
ACE_Thread::setspecific (ACE_thread_key_t key, void *value)
{
  ACE_TRACE ("ACE_Thread::setspecific");
  return ACE_OS::thr_setspecific (key, value);
}

// Stores the current value bound to <key> for the calling thread
// into the location pointed to by <valuep>.

ACE_INLINE int 
ACE_Thread::getspecific (ACE_thread_key_t key, void **valuep)
{
  ACE_TRACE ("ACE_Thread::getspecific");
  return ACE_OS::thr_getspecific (key, valuep);
}

ACE_INLINE ACE_thread_t 
ACE_Thread::self (void)
{
//  ACE_TRACE ("ACE_Thread::self");
  return ACE_OS::thr_self ();
}

ACE_INLINE void 
ACE_Thread::exit (void *status)
{
  ACE_TRACE ("ACE_Thread::exit");
  ACE_OS::thr_exit (status);
}

ACE_INLINE void
ACE_Thread::yield (void)
{
  ACE_TRACE ("ACE_Thread::yield");
  ACE_OS::thr_yield ();
}

ACE_INLINE int 
ACE_Thread::spawn (ACE_THR_FUNC func, 
		   void *arg, 
		   long flags, 
		   ACE_thread_t *t_id, 
		   ACE_hthread_t *t_handle,
		   u_int priority,
		   void *stack, 
		   size_t stack_size)
{
  ACE_TRACE ("ACE_Thread::spawn");
  return ACE_OS::thr_create (func, arg, flags, t_id, t_handle, 
			     priority, stack, stack_size);
}

ACE_INLINE int 
ACE_Thread::resume (ACE_hthread_t t_id)
{
  ACE_TRACE ("ACE_Thread::resume");
  return ACE_OS::thr_continue (t_id);
}

ACE_INLINE int 
ACE_Thread::suspend (ACE_hthread_t t_id)
{
  ACE_TRACE ("ACE_Thread::suspend");
  return ACE_OS::thr_suspend (t_id);
}

ACE_INLINE int 
ACE_Thread::kill (ACE_thread_t t_id, int signum)
{
  ACE_TRACE ("ACE_Thread::kill");
  return ACE_OS::thr_kill (t_id, signum);
}

ACE_INLINE int 
ACE_Thread::join (ACE_thread_t wait_for, 
		  ACE_thread_t *departed, 
		  void **status)
{
  ACE_TRACE ("ACE_Thread::join");
  return ACE_OS::thr_join (wait_for, departed, status);
}

ACE_INLINE int 
ACE_Thread::join (ACE_hthread_t wait_for,
		  void **status)
{
  ACE_TRACE ("ACE_Thread::join");
  return ACE_OS::thr_join (wait_for, status);
}

ACE_INLINE int 
ACE_Thread::getconcurrency (void)
{
  ACE_TRACE ("ACE_Thread::getconcurrency");
  return ACE_OS::thr_getconcurrency ();
}

ACE_INLINE int 
ACE_Thread::setconcurrency (int new_level)
{
  ACE_TRACE ("ACE_Thread::setconcurrency");
  return ACE_OS::thr_setconcurrency (new_level);
}

ACE_INLINE int 
ACE_Thread::sigsetmask (int how, 
			const sigset_t *set, 
			sigset_t *oset)
{
  ACE_TRACE ("ACE_Thread::sigsetmask");
  return ACE_OS::thr_sigsetmask (how, set, oset);
}

ACE_INLINE int
ACE_Thread::disablecancel (struct cancel_state *old_state)
{
  ACE_TRACE ("ACE_Thread::disablecancel");
  int old_cstate;
  int retval;
  if ((retval = ACE_OS::thr_setcancelstate (THR_CANCEL_DISABLE,
					    &old_cstate)) == 0)
  if (old_state != 0)
    {
      ACE_OS::memset (old_state, 0, sizeof(old_state));
      old_state->cancelstate = old_cstate;
    }

  return retval;
}

ACE_INLINE int
ACE_Thread::enablecancel (struct cancel_state *old_state, 
			  int flag)
{
  ACE_TRACE ("ACE_Thread::enablecancel");
  int old_cstate;
  int old_ctype;
  int retval;

  retval = ACE_OS::thr_setcancelstate (THR_CANCEL_ENABLE, &old_cstate);

  if (retval != 0)
    return retval;

  retval = ACE_OS::thr_setcanceltype (flag, &old_ctype);

  if (retval != 0)
    return retval;

  if (old_state != 0)
    {
      old_state->cancelstate = old_cstate;
      old_state->canceltype = old_ctype;
    }

  return 0;
}

ACE_INLINE int
ACE_Thread::setcancelstate (struct cancel_state &new_state,
			    struct cancel_state *old_state)
{
  ACE_TRACE ("ACE_Thread::setcancelstate");
  int old_cstate;
  int old_ctype;

  if (new_state.cancelstate != 0
      && ACE_OS::thr_setcancelstate (new_state.cancelstate, 
				     &old_cstate) == 0)
    return -1;

  if (new_state.canceltype != 0 
      && ACE_OS::thr_setcanceltype (new_state.canceltype, 
				    &old_ctype) == 0)
    {
      int o_cstate;

      ACE_OS::thr_setcancelstate (old_cstate, 
				  &o_cstate);
      return -1;
    }

  if (old_state != 0)
    {
      old_state->cancelstate = old_cstate;
      old_state->canceltype = old_ctype;
    }

  return 0;
}

ACE_INLINE int
ACE_Thread::cancel (ACE_thread_t t_id)
{
  ACE_TRACE ("ACE_Thread::cancel");

  return ACE_OS::thr_cancel (t_id);
}

ACE_INLINE void
ACE_Thread::testcancel (void)
{
  ACE_TRACE ("ACE_Thread::testcancel");

  ACE_OS::thr_testcancel ();
}

ACE_INLINE void
ACE_Thread::self (ACE_hthread_t &t_id)
{
//  ACE_TRACE ("ACE_Thread::self");
  ACE_OS::thr_self (t_id);
}

ACE_INLINE int 
ACE_Thread::getprio (ACE_hthread_t t_id, int &prio)
{
  ACE_TRACE ("ACE_Thread::getprio");
  return ACE_OS::thr_getprio (t_id, prio);
}

ACE_INLINE int 
ACE_Thread::setprio (ACE_hthread_t t_id, int prio)
{
  ACE_TRACE ("ACE_Thread::setprio");
  return ACE_OS::thr_setprio (t_id, prio);
}