File: globus_thread_none.c

package info (click to toggle)
globus-common 18.15-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,684 kB
  • sloc: ansic: 36,506; sh: 4,534; makefile: 354; perl: 151
file content (501 lines) | stat: -rw-r--r-- 10,170 bytes parent folder | download | duplicates (8)
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
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
/*
 * Copyright 1999-2006 University of Chicago
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef GLOBUS_DONT_DOCUMENT_INTERNAL
/**
 * @file globus_thread_none.c
 * @brief Non-threaded stubs for the Globus Threads interface
 */
#endif /* GLOBUS_DONT_DOCUMENT_INTERNAL */

/******************************************************************************
                             Include header files
******************************************************************************/
#include "globus_i_common_config.h"
#include "globus_common_include.h"
#include "globus_thread.h"
#include "globus_thread_common.h"
#include "globus_i_thread.h"
#include "version.h"
#include "globus_time.h"
#include "globus_libc.h"
#include "globus_handle_table.h"

/* Module activation function prototypes */
static int
globus_l_thread_none_activate(void);

static int
globus_l_thread_none_deactivate(void);

static
void *
globus_l_thread_none_get_impl(void);

static
void *
globus_l_thread_none_keys[512];

static
int
globus_l_thread_none_next_key = 0;

/* Module definition */
globus_module_descriptor_t
globus_i_thread_none_module =
{
    "globus_thread_none",
    globus_l_thread_none_activate,
    globus_l_thread_none_deactivate,
    GLOBUS_NULL,
    globus_l_thread_none_get_impl,
    &local_version
};

/**
 * globus_i_thread_pre_activate()
 *
 * Since globus_module depends on threads and globus_thread depends on
 * globus_module, we need this bootstrapping function.
 * 
 */
static
int
globus_l_thread_none_pre_activate(void)
{
#ifndef WIN32
    return globus_i_thread_ignore_sigpipe();
#else
    return 1;
#endif
}

static
int
globus_l_thread_none_activate(void)
{
    return globus_module_activate(GLOBUS_THREAD_COMMON_MODULE);
}
/* globus_l_thread_none_activate() */


static
int
globus_l_thread_none_deactivate()
{
    return globus_module_deactivate(GLOBUS_THREAD_COMMON_MODULE);
}
/* globus_l_thread_none_deactivate() */


/**
 * Return GLOBUS_TRUE (non-zero) if we are using preemptive threads.
 */
static
globus_bool_t
globus_l_thread_none_preemptive_threads(void)
{
    return GLOBUS_FALSE;
}
/* globus_thread_none_preemptive_threads() */


/*
 * globus_thread_none_key_create()
 */
static
int
globus_l_thread_none_key_create(
    globus_thread_key_t *               key,
    globus_thread_key_destructor_func_t func)
{
    key->none = globus_l_thread_none_next_key++;
    globus_l_thread_none_keys[key->none] = NULL;

    return 0;
}
/* globus_key_create() */


/*
 * globus_thread_none_key_setspecific()
 */
static
int
globus_l_thread_none_key_setspecific(
    globus_thread_key_t                 key,
    void *                              value)
{
    globus_l_thread_none_keys[key.none] = value;

    return 0;
}
/* globus_thread_none_setspecific() */

static
int
globus_l_thread_none_key_delete(
    globus_thread_key_t                 key)
{
    return 0;
} /* globus_thread_none_key_delete() */

/*
 * globus_thread_none_getspecific()
 */
static
void *
globus_l_thread_none_key_getspecific(
    globus_thread_key_t                 key)
{
    return globus_l_thread_none_keys[key.none];
}
/* globus_thread_none_getspecific() */

/*
 * globus_thread_none_once()
 */
static
int
globus_l_thread_none_once(
    globus_thread_once_t *              once_control,
    void                                (*init_routine)(void))
{
    if (once_control == NULL || init_routine == NULL)
    {
        return EINVAL;
    }
    if (once_control->none == GLOBUS_THREAD_ONCE_INIT_VALUE.none)
    {
        once_control->none = !GLOBUS_THREAD_ONCE_INIT_VALUE.none;
        (*init_routine)();
    }
    return 0;
}
/* globus_thread_none_once() */


/*
 * globus_thread_none_self()
 */
static
globus_thread_t
globus_l_thread_none_self(void)
{
    static globus_thread_t self;

    self.none = 0;

    return self;
}
/* globus_thread_none_self() */


/*
 * globus_thread_none_equal()
 */
static
int
globus_l_thread_none_equal(
    globus_thread_t                     thread1,
    globus_thread_t                     thread2)
{
    return (thread1.none == thread2.none);
}
/* globus_thread_none_equal() */

static
globus_bool_t
globus_l_thread_none_i_am_only_thread(void)
{
    return GLOBUS_TRUE;
}

/*
 * globus_thread_none_create()
 */
static
int
globus_l_thread_none_thread_create(
    globus_thread_t *                   thread,
    globus_threadattr_t *               attr,
    globus_thread_func_t                func,
    void *                              user_arg)
{
    thread->none = -1;

    return EAGAIN;
}

static
void
globus_l_thread_none_yield(void)
{
    globus_poll_nonblocking();
}
/* globus_thread_none_yield() */

/*
 * globus_none_condattr_init()
 */
static
int
globus_l_thread_none_condattr_init(
    globus_condattr_t *                 attr)
{
    globus_callback_space_reference(GLOBUS_CALLBACK_GLOBAL_SPACE);
    attr->none = GLOBUS_CALLBACK_GLOBAL_SPACE;
    return 0;
}

/*
 * globus_none_condattr_destroy()
 */
static
int
globus_l_thread_none_condattr_destroy(
    globus_condattr_t *                 attr)
{
    globus_callback_space_destroy(attr->none);
    attr->none = 0;

    return 0;
}

/*
 * globus_none_condattr_setspace()
 */
static
int
globus_l_thread_none_condattr_setspace(
    globus_condattr_t *                 attr,
    int                                 space)
{
    if (globus_callback_space_reference(space))
    {
        return GLOBUS_FAILURE;
    }
    else
    {
        globus_callback_space_destroy(attr->none);
        attr->none = space;
        return 0;
    }
}

/*
 * globus_none_condattr_getspace()
 */
static
int
globus_l_thread_none_condattr_getspace(
    globus_condattr_t *                 attr,
    int *                               space)
{
    *space = attr->none;

    return 0;
}

/*
 * globus_none_cond_init()
 */
static
int
globus_l_thread_none_cond_init(
    globus_cond_t *                     cv,
    globus_condattr_t *                 attr)
{
    if (attr != NULL)
    {
        cv->none = attr->none;
    }
    else
    {
        cv->none = GLOBUS_CALLBACK_GLOBAL_SPACE;
    }
    return globus_callback_space_reference(cv->none);
}
/* globus_none_cond_init() */


/*
 *  globus_none_cond_destroy()
 */
static
int
globus_l_thread_none_cond_destroy(
    globus_cond_t *                     cv)
{
    globus_callback_space_destroy(cv->none);
    cv->none = GLOBUS_NULL_HANDLE;

    return 0;
}
/* globus_none_cond_destroy() */


/*
 *  globus_none_cond_wait()
 */
static
int
globus_l_thread_none_cond_wait(
    globus_cond_t *                     cv,
    globus_mutex_t *                    mut)
{
    mut->none = 0;
    globus_thread_blocking_space_will_block(cv->none);
    globus_callback_space_poll(&globus_i_abstime_infinity, cv->none);
    mut->none = 1;

    return 0;
}
/* globus_none_cond_wait() */

/*
 *  globus_none_cond_timedwait()
 */
static
int
globus_l_thread_none_cond_timedwait(
    globus_cond_t *                     cv,
    globus_mutex_t *                    mut,
    globus_abstime_t *                  abstime)
{

    mut->none = 0;
    globus_thread_blocking_space_will_block(cv->none);
    globus_callback_space_poll(abstime, cv->none);
    mut->none = 1;

    if (time(NULL) >= abstime->tv_sec)
    {
        return ETIMEDOUT;
    }
    else
    {
        return 0;
    }
}
/* globus_none_cond_timedwait() */


/*
 *  globus_none_cond_signal()
 */
static
int
globus_l_thread_none_cond_signal(
    globus_cond_t *                     cv)
{
    globus_callback_signal_poll();
    return 0;
}
/* globus_none_cond_signal () */

static
void
globus_l_thread_none_thread_exit(
    void *                              value)
{
    exit(0);
}
/* globus_l_thread_none_thread_exit() */

/*
 *  globus_none_cond_broadcast()
 */
static
int
globus_l_thread_none_cond_broadcast(
    globus_cond_t *                     cv)
{
    globus_callback_signal_poll();
    return 0;
}
/* globus_none_cond_broadcast() */

static
int
globus_l_thread_none_kill(
    globus_thread_t                     thread,
    int                                 sig)
{
    int                                 rc;
    if (thread.none != 0)
    {
        return ESRCH;
    }
    rc = raise(sig);
    if (rc != 0)
    {
        rc = errno;
    }
    return rc;
}
/* globus_l_thread_none_kill() */

static globus_thread_impl_t globus_l_thread_none_impl =
{
    NULL /* mutex_init */,
    NULL /* mutex_destroy */,
    NULL /* mutex_lock */,
    NULL /* mutex_unlock */,
    NULL /* mutex_trylock */,
    globus_l_thread_none_cond_init,
    globus_l_thread_none_cond_destroy,
    globus_l_thread_none_cond_wait,
    globus_l_thread_none_cond_timedwait,
    globus_l_thread_none_cond_signal,
    globus_l_thread_none_cond_broadcast,
    NULL /* mutexattr_init */,
    NULL /* mutexattr_destroy */,
    globus_l_thread_none_condattr_init,
    globus_l_thread_none_condattr_destroy,
    globus_l_thread_none_condattr_setspace,
    globus_l_thread_none_condattr_getspace,
    globus_l_thread_none_thread_create,
    globus_l_thread_none_key_create,
    globus_l_thread_none_key_delete,
    globus_l_thread_none_once,
    globus_l_thread_none_key_getspecific,
    globus_l_thread_none_key_setspecific,
    globus_l_thread_none_yield,
    globus_l_thread_none_thread_exit,
#   if HAVE_SIGPROCMASK
    sigprocmask,
#   else
    NULL,
#   endif
    globus_l_thread_none_kill,
    NULL,
    NULL,
    NULL,
    globus_l_thread_none_self,
    globus_l_thread_none_equal,
    globus_l_thread_none_preemptive_threads,
    globus_l_thread_none_i_am_only_thread,
    NULL,
    globus_l_thread_none_pre_activate
};

static
void *
globus_l_thread_none_get_impl(void)
{
    return &globus_l_thread_none_impl;
}