source: golgotha/src/i4/threads/linux/pthread.h @ 80

Last change on this file since 80 was 80, checked in by Sam Hocevar, 14 years ago
  • Adding the Golgotha source code. Not sure what's going to be interesting in there, but since it's all public domain, there's certainly stuff to pick up.
  • Property svn:keywords set to Id
File size: 14.8 KB
Line 
1/*
2 * $Id: pthread.h 80 2008-03-04 23:32:10Z sam $
3 ****************************************************************************
4 *   
5 *  COPYRIGHT NOTICE
6 *   
7 *  Copyright (C) 1995, 1996 Michael T. Peterson
8 *  This file is part of the PCthreads (tm) multithreading library
9 *  package.
10 *   
11 *  The source files and libraries constituting the PCthreads (tm) package
12 *  are free software; you can redistribute them and/or modify them under
13 *  the terms of the GNU Library General Public License as published by the Free
14 *  Software Foundation; either version 2 of the License, or (at your
15 *  option) any later version.
16 *   
17 *  The PCthreads (tm) package is distributed in the hope that it will
18 *  be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
19 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
20 *  Library General Public License for more details.
21 *   
22 *  You should have received a copy of the GNU Library General Public
23 *  License along with this library (see the file COPYING.LIB); if not,
24 *  write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge,
25 *  MA 02139, USA.
26 *   
27 *  To report bugs, bug fixes, or provide feedback you may contact the
28 *  author, Michael T. Peterson, at either of the two email addresses listed
29 *  below:
30 *   
31 *             mtp@big.aa.net (preferred)
32 *             mtp@zso.dec.com
33 *   
34 *   
35 *  Michael T. Peterson
36 *  Redmond, WA.
37 *  13 January, 1996
38 ****************************************************************************
39 * $Log: pthread.h,v $
40 * Revision 1.1  1996/08/26 18:24:53  jc
41 * new and improved!
42 *
43 * Revision 1.1.1.1  1996/06/29 01:20:53  mtp
44 * pthreads 1.0 distribution
45 *
46 * Revision 1.1.1.1  1996/06/28 15:45:41  mtp
47 * Official V1.0 Sources
48 *
49 * Revision 2.0  1996/06/28 14:58:13  mtp
50 * + Release 2.0
51 *
52 * Revision 1.6  1996/01/14 20:17:08  mtp
53 * + Changed prototype for pthread_unblockasync_np() to return void.
54 *
55 * Revision 1.5  1996/01/14 18:32:44  mtp
56 * + Replaced @Header@ with COPYRIGHT NOTICE.
57 *
58 * Revision 1.4  1996/01/10 19:05:23  mtp
59 * + Removed prototypes for pthread_mutex_{get,set}prio_ceiling().
60 *
61 * Revision 1.3  1996/01/10 17:15:01  mtp
62 * + Added prototypes for pthread_blockasync_np(), pthread_unblockasync_np(),
63 *   and pthread_cond_signal_intr_np().
64 * + Added comments for all pthread_xxxxx_np() functions.
65 *
66 * Revision 1.2  1995/12/31 06:21:26  mtp
67 * + Changed pthread_get_errno_np() to pthread_geterrno_np().
68 * + Changed pthread_set_errno_np() to pthread_seterrno_np().
69 * + Changed pthread_get_expiration_np() to pthread_getexpiration_np().
70 *
71 * Revision 1.1.1.1  1995/12/16 21:42:00  mtp
72 * Placed under CVS control
73 *
74 ****************************************************************************
75 */
76#ifndef _pthread_
77#define _pthread_
78
79#ifdef __cplusplus
80extern "C" {
81#endif
82#include <unistd.h>
83#include "typedefs.h"
84
85/*
86 * --  Forward declare these pointers to structures that will be defined
87 *     internally.
88 */
89typedef int                                pthread_key_t;
90typedef struct PTHREAD_HANDLE *            pthread_t;
91typedef struct PTHREAD_MUTEX_HANDLE *      pthread_mutex_t;
92typedef struct PTHREAD_CONDV_HANDLE *      pthread_cond_t;
93typedef struct PTHREAD_ATTR_HANDLE *       pthread_attr_t;
94typedef struct PTHREAD_MUTEXATTR_HANDLE *  pthread_mutexattr_t;
95typedef struct PTHREAD_CONDATTR_HANDLE *   pthread_condattr_t;
96
97/*
98 * --   These constants inform clients of the capabilities
99 *      of PCthreads
100 */
101#define _POSIX_THREADS
102#define _POSIX_THREAD_ATTR_STACKSIZE
103#define _POSIX_THREAD_PRIORITY_SCHEDULING
104#define _POSIX_THREAD_PRIO_PROTECT
105#define _POSIX_THREAD_PRIO_INHERIT
106
107#ifdef _POSIX_THREADS_PROCESS_SHARED
108#undef _POSIX_THREADS_PROCESS_SHARED
109#endif
110
111#define PTHREAD_KEYS_MAX PTHREAD_C_MAX_DATAKEYS
112#define PTHREAD_DESTRUCTOR_ITERATIONS ((int) 100)
113
114/*
115 * --  These constants are required by POSIX.1c
116 */
117#define SCHED_FIFO   ((int) SCHED_FCFS_C)
118#define SCHED_RR     ((int) SCHED_ROUND_ROBIN_C)
119#define SCHED_OTHER  ((int) SCHED_PRIORITY_DECAY_C)
120
121#define PRI_FIFO_MIN       PTHREAD_MIN_PRIO_C
122#define PRI_FIFO_DEFAULT   PTHREAD_DEFAULT_PRIO_C
123#define PRI_FIFO_MAX       PTHREAD_MAX_PRIO_C
124
125#define PRI_RR_MIN      PRI_FIFO_MIN
126#define PRI_RR_DEFAULT  PRI_FIFO_DEFAULT
127#define PRI_RR_MAX      PRI_FIFO_MAX
128
129#define PRI_OTHER_MIN      PRI_FIFO_MIN
130#define PRI_OTHER_DEFAULT  PRI_FIFO_DEFAULT
131#define PRI_OTHER_MAX      PRI_FIFO_MAX
132
133#define PTHREAD_INHERIT_SCHED          PTHREAD_USE_ATTRIBUTES_C
134#define PTHREAD_DEFAULT_SCHED          PTHREAD_SCHED_INHERIT_C
135
136#define PTHREAD_CANCEL_ENABLE          THREAD_CANCEL_ENABLED_C
137#define PTHREAD_CANCEL_DISABLE         THREAD_CANCEL_DISABLED_C
138#define PTHREAD_CANCEL_DEFERRED        THREAD_CANCEL_DEFERRED_C
139#define PTHREAD_CANCEL_ASYNCHRONOUS    THREAD_CANCEL_ASYNC_C
140#define PTHREAD_CANCELED               (0xDEADBABE)
141
142#define MUTEX_SCHED_DEFAULT            SCHED_MUTEX_NO_PRIO_INHERIT_C
143#define MUTEX_SCHED_INHERIT            SCHED_MUTEX_PRIO_INHERIT_C
144#define MUTEX_SCHED_PROTECT            SCHED_MUTEX_PRIO_PROTECT_C
145
146#define PTHREAD_CREATE_JOINABLE        PTHREAD_JOINABLE_C
147#define PTHREAD_CREATE_DETACHED        PTHREAD_DETACHED_C
148
149/*-------------------------------------------------------------------------*
150 * --  POSIX .1c API services.                                             *
151 *-------------------------------------------------------------------------*/
152
153/*
154 * This service allows a thread to wait for a specified set of signals
155 * to be delivered to the process.  Upon delivery of any one of the set
156 * of signals, the thread returns from this function with the value of
157 * the delivered signal.  The sigwait() service is a cancellation point.
158 */
159extern int
160sigwait( sigset_t sigset );
161
162
163/*
164 * Client applications should use pthread_sigmask() instead of sigprocmask().
165 * In fact, all occurrences of sigprocmask are redefined to pthread_sigmask()
166 * by this header file.
167 */
168extern int
169pthread_sigmask( int how, const sigset_t *newmask, sigset_t *prev );
170
171
172/*
173 * This routine sends a signal to a specified thread.  Any signal defined to
174 * stop, continue, or terminate will be applied to all threads in the
175 * process, i.e., the effect will be process-wide.  For example, sending
176 * SIGTERM to *any* thread terminates *all* threads in the process - Even
177 * though it may be handled by the thread to which it was sent.
178 */
179extern int
180pthread_kill( pthread_t handle, int sig );
181
182
183extern int 
184pthread_create( pthread_t      *handle,
185                pthread_attr_t *th_attr,
186                void *         (*th_proc)(void *),
187                void *         th_proc_arg );
188extern int 
189pthread_join( pthread_t handle, void **return_value );
190
191extern int 
192pthread_detach( pthread_t  handle );
193
194extern int
195pthread_setschedparam( pthread_t handle,
196                       int policy,
197                       const struct sched_param *param );
198
199extern int
200pthread_getschedparam( pthread_t handle,
201                       int *policy,
202                       struct sched_param *param );
203extern int
204pthread_once( pthread_once_t  *once_control,
205              void (*init_routine)(void));
206
207extern pthread_t
208pthread_self( void );
209
210extern int
211pthread_key_create( pthread_key_t *key, void (*destructor)(void *) );
212
213extern int
214pthread_getspecific( pthread_key_t key, void **value );
215
216extern int
217pthread_setspecific( pthread_key_t key, void *value );
218
219extern int 
220pthread_cancel( pthread_t th_h );
221
222extern void 
223pthread_testcancel( void );
224
225extern int 
226pthread_setcancelstate( int new_state, int *prev_state );
227
228extern int
229pthread_setcanceltype( int new_type, int *old_type );
230
231extern void
232pthread_cleanup_push( void (*cleanup_routine)(void *), void *arg );
233
234extern void
235pthread_cleanup_pop( int execute );
236
237extern void 
238pthread_yield( void  *arg );
239
240extern int
241pthread_equal( pthread_t th1_handle, pthread_t th2_handle );
242
243extern void 
244pthread_exit( void *exit_value );
245
246extern int 
247pthread_mutex_init( pthread_mutex_t  *handle,
248                    pthread_mutexattr_t  *mu_attr_h );
249
250extern int 
251pthread_mutex_destroy( pthread_mutex_t  *handle );
252
253extern int 
254pthread_mutex_lock( pthread_mutex_t  *handle );
255
256extern int 
257pthread_mutex_unlock( pthread_mutex_t  *handle );
258
259extern int 
260pthread_mutex_trylock( pthread_mutex_t  *mu_h );
261
262extern int 
263pthread_cond_init( pthread_cond_t  *handle, pthread_condattr_t  *cv_attr_h );
264
265extern int 
266pthread_cond_destroy( pthread_cond_t  *handle );
267
268extern int 
269pthread_cond_wait( pthread_cond_t  *cv_h,  pthread_mutex_t *mu_h );
270
271extern int 
272pthread_cond_signal( pthread_cond_t  *handle );
273
274extern int
275pthread_cond_broadcast( pthread_cond_t *handle );
276
277extern int 
278pthread_cond_timedwait( pthread_cond_t  *cv_h,
279                        pthread_mutex_t  *mu_h,
280                        const struct timespec *abstime );
281
282extern int 
283pthread_attr_init( pthread_attr_t *handle );
284
285extern int 
286pthread_attr_destroy( pthread_attr_t *handle );
287
288extern int
289pthread_attr_setdetachstate( pthread_attr_t  *handle,
290                             int  detached_state );
291extern int
292pthread_attr_getdetachstate( pthread_attr_t  *handle,
293                             int *detached_state );
294
295extern int 
296pthread_attr_setstacksize( pthread_attr_t  *handle, size_t stack_size );
297
298extern int 
299pthread_attr_getstacksize( pthread_attr_t  *handle, size_t  *stack_size );
300
301extern int 
302pthread_attr_setinheritsched( pthread_attr_t  *handle, int inherit_sched );
303
304extern int 
305pthread_attr_getinheritsched( pthread_attr_t *handle, int *inherit_sched );
306
307extern int 
308pthread_attr_setschedpolicy( pthread_attr_t  *handle, int sched_policy );
309
310extern int
311pthread_attr_getschedpolicy( pthread_attr_t *handle, int *sched_policy );
312
313/*
314 * --  The xxxschedparam() routines replace the get/setscheduler() and
315 *     get/setprio() routines.
316 */
317extern int 
318pthread_attr_getschedparam( pthread_attr_t *handle,
319                            struct sched_param *sched_param );
320
321extern int 
322pthread_attr_setschedparam( pthread_attr_t  *handle,
323                            const struct sched_param *sched_param );
324
325extern int
326pthread_attr_getschedpriority( pthread_attr_t *handle, int *sched_priority );
327
328extern int 
329pthread_mutexattr_init( pthread_mutexattr_t  *handle );
330
331extern int 
332pthread_mutexattr_destroy( pthread_mutexattr_t  *handle );
333
334extern int 
335pthread_mutexattr_setprotocol(pthread_mutexattr_t  *handle,
336                              pthread_protocol_t protocol );
337
338extern int
339pthread_mutexattr_getprotocol( pthread_mutexattr_t *handle,
340                              pthread_protocol_t *protocol );
341
342extern int
343pthread_mutexattr_getprio_ceiling( pthread_mutexattr_t *handle,
344                                   int *prio_ceiling );
345
346extern int
347pthread_mutexattr_setprio_ceiling( pthread_mutexattr_t  *handle,
348                                   int prio_ceiling );
349
350extern int 
351pthread_condattr_init( pthread_condattr_t  *handle );
352
353extern int 
354pthread_condattr_destroy( pthread_condattr_t  *handle );
355
356/*
357 * --  Utility functions (non-portable)
358 */
359extern int
360pthread_delay_np( const struct timespec *interval );
361
362
363/*
364 * Return the thread's sequence number.  This is a unique,
365 * integer valued number such that (2 <= N <= MAX_INT).
366 */
367extern long
368pthread_getsequence_np( const pthread_t handle );
369
370/*
371 * Return the absolute time as the sum of the interval (delta)
372 * and the current time.
373 */
374extern int
375pthread_getexpiration_np( const struct timespec *delta,
376                          struct timespec *abstime );
377
378/*
379 * Returns a process-wide count of the number of thread context
380 * switches.
381 */
382extern int
383pthread_get_ctxsw_counts_np( pthread_t handle,
384                             unsigned long *total_count,
385                             unsigned long *async_count );
386
387/*
388 * Return the number of bytes of stack that have not been
389 * used.  Call this routine at the end of a thread's procedure
390 * to see whether you've allocated too much stack space.
391 */
392extern int
393pthread_checkstack_np( pthread_t handle, size_t *bytes );
394
395/*
396 * Return the thread-specific errno value, or Zero.
397 */
398extern int
399pthread_geterrno_np( pthread_t handle, int *err );
400
401/*
402 * Set a thread-specific errno value.
403 */
404extern int
405pthread_seterrno_np( int err );
406
407/*
408 * Return the number of threads waiting at the specified
409 * condition variable.
410 */
411extern int
412pthread_cond_getwaiters_np( pthread_cond_t handle,
413                            unsigned int *waiting_threads );
414
415/*
416 * Allow a condition variable to be signaled from an interrupt
417 * handler. E.g., signal a condition variable from a ctrl-C interrupt.
418 */
419extern int
420pthread_cond_signal_intr_np( pthread_cond_t *handle );
421
422/*
423 * Return the number of threads blocked at a specified mutex.
424 */
425extern int
426pthread_mutex_getblocked_np( pthread_mutex_t handle,
427                             unsigned int *blocked_threads );
428
429/*
430 * Obtain the execution priority of the specified thread.
431 */
432extern int
433pthread_getprio_np( pthread_t handle, int *current_prio );
434
435/*
436 * Set the execution priority of the specified thread.
437 */
438extern int
439pthread_setprio_np( pthread_t handle, int new_priority );
440
441/*
442 * Thread-safe wrapper for UNIX gettimeofday() function.
443 */
444extern int
445pthread_gettimeofday_np( struct timeval *tv, struct timezone *tz );
446
447/*
448 * Lock and unlock the single, process-wide mutex.
449 */
450extern int
451pthread_lock_global_np( void );
452
453extern int
454pthread_unlock_global_np( void );
455
456/*
457 * Block and unblock asynchronous thread context switches.  Use
458 * as follows:
459 *
460 *      flag = pthread_blockasync_np();
461 *                  .
462 *                  .
463 *                  .
464 *      (void) pthread_unblockasync_np( flag );
465 *
466 * Use with great caution and do not execute any functions that
467 * may cause the thread to take a synchronous context switch, e.g.,
468 * lock a mutex, signal a condition variable, etc.
469 */
470extern int
471pthread_blockasync_np( void );
472
473extern void
474pthread_unblockasync_np( int flag );
475
476/*
477 * Return some process-wide statistics.
478 */
479extern int
480system_get_state( unsigned long *intr_count,
481                  unsigned long *ctxsw_count,
482                  unsigned long *async_preemptions,
483                  unsigned long *elapsed_time,
484                  int *active_priority );
485
486/*
487 * A thread-safe wrapper for sigaction.
488 */
489extern int
490pthread_sigaction_np( int signal,
491                      const struct sigaction *new_action,
492                      struct sigaction *prev_action );
493
494#undef sigprocmask
495#define sigprocmask pthread_sigmask
496
497#undef gettimeofday
498#define gettimeofday pthread_gettimeofday_np
499
500#ifdef _DCE_COMPAT_
501#include <pthread_dce.h>
502#endif
503
504#ifdef __cplusplus
505}
506#endif
507#endif
Note: See TracBrowser for help on using the repository browser.