#ifdef AIX_PROD
/* @(#)82       1.20  src/threads/pthread.h, threads.src, os2dce21.dss, 960602a.1  3/18/96  14:52:52 */
/*
 * COMPONENT_NAME: threads.src
 *
 * FUNCTIONS:
 *
 * ORIGINS: 72 27
 *
 * OBJECT CODE ONLY SOURCE MATERIALS
 *
 */
#endif /* AIX_PROD */
/*
 * @OSF_COPYRIGHT@
 * COPYRIGHT NOTICE
 * Copyright (c) 1990, 1991, 1992, 1993, 1994 Open Software Foundation, Inc.
 * ALL RIGHTS RESERVED (DCE).  See the file named COPYRIGHT.DCE for
 * the full copyright text.
 */
/*
 * HISTORY
 * $Log: pthread.h,v $
 * Revision 1.2.9.2  1994/06/09  13:39:20  devsrc
 * 	 CR10892 - fix copyright in file
 * 	[1994/06/09  13:29:07  devsrc]
 *
 * Revision 1.2.9.1  1994/04/01  20:18:08  jd
 * 	Fist drop of code cleanup
 * 	[1994/03/28  19:19:53  jd]
 * 
 * Revision 1.2.5.4  1993/02/01  22:32:55  hinman
 * 	[hinman@sni] - Final merge before bsubmit
 * 	[1993/01/31  17:34:37  hinman]
 * 
 * 	[hinman] - Check in merged SNI version
 * 	[1993/01/11  16:24:28  hinman]
 * 
 * Revision 9.5.1.6  92/12/17  14:15:09  raj
 * 	[raj] New naming + parallelized reentrant library changes.
 * 
 * Revision 9.5.3.2  92/11/06  11:31:29  raj
 * 	[raj] Changes for new naming scheme with reentrant libraries.
 * 
 * Revision 9.5.1.5  92/09/10  16:38:21  hinman
 * 	[hinman] - Fold forward from raj_om
 * 
 * Revision 9.5.2.2  92/09/10  16:14:29  raj
 * 	[raj] merging SVR4 changes into 1.0.2
 * 
 * Revision 9.9  92/09/02  14:13:29  hinman
 * 	Update checkin
 * 
 * Revision 1.1.2.3  1992/08/14  20:24:04  bolinger
 * 	Bring forward 1.0.1 revision 1.2.3.2.
 * 	[1992/08/10  16:43:15  bolinger]
 * 
 * Revision 1.1.2.2  1992/05/09  00:22:02  bolinger
 * 	BL10 CMA sources from DEC.
 * 	[1992/05/09  00:21:48  bolinger]
 * 
 * $EndLog$
 */
/*
 *      src/threads/pthread.h, threads.src, os2dce21.dss, 960602a.1     (DEC OSF/1)    3/18/96
 */
/*
 *  Copyright (c) 1990, 1992 by
 *  Digital Equipment Corporation, Maynard Massachusetts.
 *  All rights reserved.
 *
 *  This software is furnished under a license and may be used and  copied
 *  only  in  accordance  with  the  terms  of  such  license and with the
 *  inclusion of the above copyright notice.  This software or  any  other
 *  copies  thereof may not be provided or otherwise made available to any
 *  other person.  No title to and ownership of  the  software  is  hereby
 *  transferred.
 *
 *  The information in this software is subject to change  without  notice
 *  and  should  not  be  construed  as  a commitment by DIGITAL Equipment
 *  Corporation.
 *
 *  DIGITAL assumes no responsibility for the use or  reliability  of  its
 *  software on equipment which is not supplied by DIGITAL.
 */

/*
 *  FACILITY:
 *
 *	Common Multithread Architecture (CMA) services; POSIX 1003.4 interface
 *
 *  ABSTRACT:
 *
 *	External definitions for CMA's pthreads services
 *
 *  AUTHORS:
 *
 *	Dave Butenhof
 *
 *  CREATION DATE:
 * 
 *	20 February 1990
 *
 *  MODIFIED BY:
 *
 *	Dave Butenhof
 *	Paul Curtin
 *	Webb Scales
 *
 *      Sy Lin  -  01/27/94  CMVC 8106 to support other C++
 */

#ifndef PTHREAD
#define PTHREAD

#ifdef PTHREAD_EXC
#error ERROR:pthread_exc.h and pthread.h are mutually exclusive, pthread_exc.h was found first
/*
 *	This is an intentional syntax error to halt compilation,
 *	because pthread_exc.h was already included.
 */
int	exit_compilation:?*+-! = 0;
#endif

#ifndef IBMOS2
#error ERROR:The preprocessor symbol IBMOS2 is not defined
/*
 *	Other headers may have already been included which utilize the IBMOS2
 *	preprocessor definition, therefore it is not safe to continue.
 *	
 *	This is an intentional syntax error to halt compilation,
 *	because IBMOS2 is not defined.
 */
int	exit_compilation:?*+-! = 0;
#endif	/*	!IBMOS2	*/

#ifdef IBMOS2
#ifndef INTEL80x86
#error ERROR:The preprocessor symbol INTEL80x86 is not defined
/*
 *	Other headers may have already been included which utilize the INTEL80x86
 *	preprocessor definition, therefore it is not safe to continue.
 *	
 *	This is an intentional syntax error to halt compilation,
 *	because INTEL80x86 is not defined.
 */
int	exit_compilation:?*+-! = 0;
#endif	/*	!INTEL80x86	*/

#ifdef __cplusplus
extern "C"{
#endif
#endif	/*	IBMOS2	*/


#ifdef vms
# include <cma.h>
#else
# include <dce/cma.h>
# include <signal.h>
#endif

#ifdef IBMOS2
# include <dce/dcedef.h>
#endif	/*	IBMOS2	*/

/*
 * The implementation makes these basic decisions
 */

#ifndef _POSIX_THREADS
#ifdef IBMOS2
# define _POSIX_THREADS                         1
#else	/*	!IBMOS2	*/
# define _POSIX_THREADS
#endif	/*	!IBMOS2	*/
#endif
#ifndef _POSIX_THREAD_ATTR_STACKSIZE
#ifdef IBMOS2
# define _POSIX_THREAD_ATTR_STACKSIZE           1
#else	/*	!IBMOS2	*/
# define _POSIX_THREAD_ATTR_STACKSIZE
#endif	/*	!IBMOS2	*/
#endif
#if _CMA_KTHREADS_ != _CMA__MACH
# define _POSIX_THREADS_REALTIME_SCHEDULING     1
#elif defined (_POSIX_THREADS_REALTIME_SCHEDULING)
# undef _POSIX_THREADS_REALTIME_SCHEDULING
#endif
#ifndef _POSIX_THREADS_PER_PROCESS_SIGNALS_1
# define _POSIX_THREADS_PER_PROCESS_SIGNALS_1   1
#endif

#ifdef IBMOS2
/* CMVC <5846>  */

#ifndef _H_TYPES
/*
 *	typedef and structure for signal mask
 */
typedef struct sigset_t
{
	unsigned long losigs;
	unsigned long hisigs;
} sigset_t;
#endif	/*	!_H_TYPES	*/

/*
 * sigaction structure used in sigaction() system call
 * Defect 19012 - Add #ifndef _SIGACTION_DEFINED in case signal.h
 *   has defined it already.
 */
#ifndef _SIGACTION_DEFINED
#define _SIGACTION_DEFINED

struct sigaction {

#ifdef  _NONSTD_TYPES
	_MBI    (*sa_handler)();
#else   /* ~_NONSTD_TYPES */
#ifdef  _NO_PROTO
	void    (*sa_handler)();        /* signal handler, or action value */
#else   /* ~NO_PROTO */
	void    (*sa_handler)(int);     /* signal handler, or action value */
#endif  /* NO_PROTO */
#endif  /* _NONSTD_TYPES */

	sigset_t sa_mask;               /* signals to block while in handler */
	int     sa_flags;               /* signal action flags */
};

/*
 * valid flag define for sa_flag field of sigaction structure - POSIX
 */
#define SA_NOCLDSTOP    0x00000004      /* do not set SIGCHLD for child stops*/

#endif /*	!_SIGACTION_DEFINED	*/
#endif	/*	IBMOS2		*/

/*
 * Implement push and pop for cancellation handlers, using TRY and ENDTRY
 */

#define pthread_cleanup_push(routine,arg)       \
    { \
    pthread_cleanup_t _XXX_proc = (pthread_cleanup_t)(routine); \
    pthread_addr_t _XXX_arg = (pthread_addr_t)(arg); \
    int _XXX_completed = 0; \
    TRY {

#define pthread_cleanup_pop(execute)    \
    _XXX_completed = 1;} \
    FINALLY { \
	int _XXX_execute = execute; \
	if ((! _XXX_completed) || (_XXX_execute)) _XXX_proc (_XXX_arg);} \
    ENDTRY}

#define pthread_equal_np(thread1,thread2) \
    (((thread1).field1 == (thread2).field1) \
    && ((thread1).field2 == (thread2).field2) \
    && ((thread1).field3 == (thread2).field3))

#define pthread_equal(thread1,thread2) \
    (((thread1).field1 == (thread2).field1) \
    && ((thread1).field2 == (thread2).field2) \
    && ((thread1).field3 == (thread2).field3))

#ifndef IBMOS2
#define pthread_getunique_np(handle) \
    ((unsigned int)((pthread_t *)handle)->field2)
#endif	/*	!IBMOS2	*/

/*
 * Sample decisions for the environment types
 */

typedef cma_t_key               pthread_key_t;

typedef cma_t_address           pthread_addr_t;

/*
 * For compatibility with OSF/1 pthreads
 */
typedef pthread_addr_t          any_t;
typedef void (*pthread_cleanup_t)  (pthread_addr_t);

/*
 * Sample decision for a one-time initialization control block and its
 * initialization macro.
 *
 * Declare a one time initialization control block as:
 *
 *      static pthread_once_t   block = pthread_once_init;
 */
typedef cma_t_once      pthread_once_t;

#define pthread_once_init       cma_once_init

#define CANCEL_ON       1
#define CANCEL_OFF      0

/*
 * The following are the portable pthread definitions
 */

/*
 * Operations on Handles
 */

/*
 * Operations on attributes objects
 */

typedef cma_t_attr      pthread_attr_t;

/*
 * An attributes object is created to specify the attributes of other CMA
 * objects that will be created.
 */

#ifdef IBMOS2
int DCEAPI
pthread_attr_create (pthread_attr_t	*);
#else	/*	!IBMOS2	*/
int pthread_attr_create  (pthread_attr_t *);
#endif	/*	!IBMOS2	*/

/*
 * An attributes object can be deleted when it is no longer needed.
 */

#ifdef IBMOS2
int DCEAPI
pthread_attr_delete (pthread_attr_t	*);
#else	/*	!IBMOS2	*/
int pthread_attr_delete  (pthread_attr_t *);
#endif	/*	!IBMOS2	*/

/*
 * Operations on threads
 */

typedef cma_t_thread            pthread_t;
typedef cma_t_start_routine     pthread_startroutine_t;

#ifdef IBMOS2
typedef cma_t_start_routine_system pthread_startroutine_t_system;
#endif	/*	IBMOS2	*/

/*
 * For compatibility with OSF/1 pthreads
 */
typedef pthread_startroutine_t  pthread_func_t;

#define PTHREAD_INHERIT_SCHED   ((int)cma_c_sched_inherit)
#define PTHREAD_DEFAULT_SCHED   ((int)cma_c_sched_use_default)

#define SCHED_FIFO              ((int)cma_c_sched_fifo)
#define SCHED_RR                ((int)cma_c_sched_rr)
#define SCHED_FG_NP             ((int)cma_c_sched_throughput)
#define SCHED_BG_NP             ((int)cma_c_sched_background)
#define SCHED_OTHER             ((int)cma_c_sched_throughput)
#ifdef IBMOS2
#define SCHED_HRR               ((int)cma_c_sched_hrr)
#endif	/*	IBMOS2	*/

#define PRI_FIFO_MIN            ((int)cma_c_prio_fifo_min)
#define PRI_FIFO_MAX            ((int)cma_c_prio_fifo_max)
#define PRI_RR_MIN              ((int)cma_c_prio_rr_min)
#define PRI_RR_MAX              ((int)cma_c_prio_rr_max)
#define PRI_FG_MIN_NP           ((int)cma_c_prio_through_min)
#define PRI_FG_MAX_NP           ((int)cma_c_prio_through_max)
#define PRI_BG_MIN_NP           ((int)cma_c_prio_back_min)
#define PRI_BG_MAX_NP           ((int)cma_c_prio_back_max)
#define PRI_OTHER_MIN           ((int)cma_c_prio_through_min)
#define PRI_OTHER_MAX           ((int)cma_c_prio_through_max)
#ifdef IBMOS2
#define PRI_HRR_MIN             ((int)cma_c_prio_hrr_min)
#define PRI_HRR_MAX             ((int)cma_c_prio_hrr_max)
#endif	/*	IBMOS2	*/

/*
 * Operations to define thread creation attributes
 */

/*
 * Set or obtain the default thread priority.
 */
#ifdef IBMOS2
int DCEAPI
pthread_attr_setprio (pthread_attr_t  *,
					  int);

int DCEAPI
pthread_attr_getprio (pthread_attr_t);
#else	/*	!IBMOS2	*/
int pthread_attr_setprio  (pthread_attr_t *,int);

int pthread_attr_getprio  (pthread_attr_t);
#endif	/*	!IBMOS2	*/

/*
 * Set or obtain the default scheduling algorithm
 */
#ifdef IBMOS2
int DCEAPI
pthread_attr_setsched (pthread_attr_t  *,
					   int);

int DCEAPI
pthread_attr_getsched (pthread_attr_t);
#else	/*	!IBMOS2	*/
int pthread_attr_setsched  (pthread_attr_t	*,int);

int pthread_attr_getsched  (pthread_attr_t);
#endif	/*	!IBMOS2	*/

/*
 * Set or obtain whether a thread will use the default scheduling attributes,
 * or inherit them from the creating thread.
 */
#ifdef IBMOS2
int DCEAPI
pthread_attr_setinheritsched (pthread_attr_t  *,
							  int);

int DCEAPI
pthread_attr_getinheritsched (pthread_attr_t);
#else	/*	!IBMOS2	*/
int pthread_attr_setinheritsched  (pthread_attr_t *,int);

int pthread_attr_getinheritsched  (pthread_attr_t);
#endif	/*	!IBMOS2	*/

/*
 * Set or obtain the default stack size
 */
#ifdef IBMOS2
int DCEAPI
pthread_attr_setstacksize (pthread_attr_t  *,
						   long);

long DCEAPI
pthread_attr_getstacksize (pthread_attr_t);
#else	/*	!IBMOS2	*/
int pthread_attr_setstacksize  (pthread_attr_t *,long);

long pthread_attr_getstacksize  (pthread_attr_t);
#endif	/*	!IBMOS2	*/

/*
 * Set or obtain the default guard size
 */
#ifdef IBMOS2
int DCEAPI
pthread_attr_setguardsize_np (pthread_attr_t  *,
							  long);

long DCEAPI
pthread_attr_getguardsize_np (pthread_attr_t);
#else	/*	!IBMOS2	*/
int pthread_attr_setguardsize_np  (pthread_attr_t *,long);

long pthread_attr_getguardsize_np  (pthread_attr_t);
#endif	/*	!IBMOS2	*/

/*
 * The following procedures can be used to control thread creation,
 * termination and deletion.
 */

/*
 * To create a thread object and runnable thread, a routine must be specified
 * as the new thread's start routine.  An argument may be passed to this
 * routine, as an untyped address; an untyped address may also be returned as
 * the routine's value.  An attributes object may be used to specify details
 * about the kind of thread being created.
 */
#ifdef IBMOS2
#ifdef DCE_OS2_PTHREAD
int DCEAPI
pthread_create (pthread_t               *,
				pthread_attr_t,
				pthread_startroutine_t,
				pthread_addr_t);
/* CMVC 8106 STARTED  */
#if defined(__IBMC__) || defined(__IBMCPP__)
/* CMVC 8106 ENDED    */
int _Optlink
pthread_create_optlink (pthread_t				*,
						pthread_attr_t,
						pthread_startroutine_t,
						pthread_addr_t);
#endif	/*	__IBMC__ || __IBMCPP__	*/
int DCEAPI
pthread_create_system (pthread_t               *,
					   pthread_attr_t,
					   pthread_startroutine_t,
					   pthread_addr_t);
#else	/*	!DCE_OS2_PTHREAD	*/
/* CMVC 8106 STARTED  */
#if defined(__IBMC__) || defined(__IBMCPP__)
/* CMVC 8106 ENDED    */
int _Optlink
pthread_create_optlink (pthread_t				*,
						pthread_attr_t,
						pthread_startroutine_t,
						pthread_addr_t);
#endif	/*	__IBMC__ || __IBMCPP__	*/
int DCEAPI
pthread_create_system (pthread_t               *,
					   pthread_attr_t,
					   pthread_startroutine_t,
					   pthread_addr_t);
#ifdef DCEOS2_THREAD_SYSTEM_LINKAGE
#define  pthread_create(a,b,c,d)  pthread_create_system(a,b,c,d)
#else	/*	!DCEOS2_THREAD_SYSTEM_LINAGE	*/
#define  pthread_create(a,b,c,d)  pthread_create_optlink(a,b,c,d)
#endif /*	!DCEOS2_THREAD_SYSTEM_LINKAGE	*/
#endif /*	DCE_OS2_PTHREAD	*/
#else	/*	!IBMOS2	*/
int pthread_create  (pthread_t *,pthread_attr_t,pthread_startroutine_t,pthread_addr_t);
#endif	/*	!IBMOS2	*/

/*
 * A thread object may be "detached" to specify that the return value and
 * completion status will not be requested.
 */
#ifdef IBMOS2
int DCEAPI
pthread_detach (pthread_t	*);
#else	/*	!IBMOS2	*/
int pthread_detach  (pthread_t *);
#endif	/*	!IBMOS2	*/

/*
 * A thread may terminate it's own execution.
 */
#ifdef IBMOS2
void DCEAPI
pthread_exit (pthread_addr_t);
#else	/*	!IBMOS2	*/
void pthread_exit  (pthread_addr_t);
#endif	/*	!IBMOS2	*/

/*
 * A thread can await termination of another thread and retrieve the return
 * value of the thread.
 */
#ifdef IBMOS2
int DCEAPI
pthread_join (pthread_t,
			  pthread_addr_t	*);
#else	/*	!IBMOS2	*/
int pthread_join  (pthread_t,pthread_addr_t *);
#endif	/*	!IBMOS2	*/

/*
 * Thread Scheduling Operations
 */

/*
 * The current user_assigned priority of a thread can be changed.
 */
#ifdef IBMOS2
int DCEAPI
pthread_setprio (pthread_t,
				 int);
#else	/*	!IBMOS2	*/
int pthread_setprio  (pthread_t,int);
#endif	/*	!IBMOS2	*/

/*
 * The current user_assigned scheduler algorithm of a thread can be changed.
 */
#ifdef IBMOS2
int DCEAPI
pthread_setscheduler (pthread_t,
					  int,
					  int);
#else	/*	!IBMOS2	*/
int pthread_setscheduler  (pthread_t,int,int);
#endif	/*	!IBMOS2	*/

/*
 * A thread may tell the scheduler that its processor can be made available.
 */
#ifdef IBMOS2
void DCEAPI
pthread_yield (void);
#else	/*	!IBMOS2	*/
void pthread_yield  (void);
#endif	/*	!IBMOS2	*/

/*
 * Thread Information Operations
 */

/*
 * A thread may obtain a copy of its own thread handle.
 */
#ifdef IBMOS2
pthread_t DCEAPI
pthread_self (void);
#else	/*	!IBMOS2	*/
pthread_t pthread_self  (void);
#endif	/*	!IBMOS2	*/

/*
 * The current user_assigned priority of a thread can be read.
 */
#ifdef IBMOS2
int DCEAPI
pthread_getprio (pthread_t);
#else	/*	!IBMOS2	*/
int pthread_getprio  (pthread_t);
#endif	/*	!IBMOS2	*/

/*
 * The current user_assigned scheduler algorithm of a thread can be read.
 */
#ifdef IBMOS2
int DCEAPI
pthread_getscheduler (pthread_t);
#else	/*	!IBMOS2	*/
int pthread_getscheduler  (	pthread_t);
#endif	/*	!IBMOS2	*/

/*
 * Operations on Mutexes
 */

#define MUTEX_FAST_NP           0
#define MUTEX_RECURSIVE_NP      1
#define MUTEX_NONRECURSIVE_NP   2

typedef cma_t_attr      pthread_mutexattr_t;
typedef cma_t_mutex     pthread_mutex_t;

#ifdef IBMOS2
int DCEAPI
pthread_mutexattr_create (pthread_mutexattr_t	*);

int DCEAPI
pthread_mutexattr_delete (pthread_mutexattr_t     *);

int DCEAPI
pthread_mutexattr_setkind_np (pthread_mutexattr_t     *,
							  int);

int DCEAPI
pthread_mutexattr_getkind_np (pthread_mutexattr_t);
#else	/*	!IBMOS2	*/
int pthread_mutexattr_create  (pthread_mutexattr_t *);

int pthread_mutexattr_delete  (pthread_mutexattr_t *);

int pthread_mutexattr_setkind_np  (pthread_mutexattr_t *,int);

int pthread_mutexattr_getkind_np  (pthread_mutexattr_t);
#endif	/*	!IBMOS2	*/

/*
 * The following routines create, delete, lock and unlock mutexes.
 */
#ifdef IBMOS2
int DCEAPI
pthread_mutex_init (pthread_mutex_t		*,
					pthread_mutexattr_t);

int DCEAPI
pthread_mutex_destroy (pthread_mutex_t	*);

int DCEAPI
pthread_mutex_lock (pthread_mutex_t	*);

int DCEAPI
pthread_mutex_trylock (pthread_mutex_t	*);

int DCEAPI
pthread_mutex_unlock (pthread_mutex_t	*);
#else	/*	!IBMOS2	*/
int pthread_mutex_init  (pthread_mutex_t *,pthread_mutexattr_t);

int pthread_mutex_destroy  (pthread_mutex_t *);

int pthread_mutex_lock  (pthread_mutex_t *);

int pthread_mutex_trylock  (pthread_mutex_t *);

int pthread_mutex_unlock  (pthread_mutex_t *);
#endif	/*	!IBMOS2	*/

/*
 * Operations on condition variables
 */

typedef cma_t_attr      pthread_condattr_t;
typedef cma_t_cond      pthread_cond_t;

#ifdef IBMOS2
int DCEAPI
pthread_condattr_create (pthread_condattr_t	*);

int DCEAPI
pthread_condattr_delete (pthread_condattr_t	*);
#else	/*	!IBMOS2	*/
int pthread_condattr_create  (pthread_condattr_t *);

int pthread_condattr_delete  (pthread_condattr_t *);
#endif	/*	!IBMOS2	*/

/*
 * A thread can create and delete condition variables.
 */
#ifdef IBMOS2
int DCEAPI
pthread_cond_init (pthread_cond_t		*,
				   pthread_condattr_t);

int DCEAPI
pthread_cond_destroy (pthread_cond_t	*);
#else	/*	!IBMOS2	*/
int pthread_cond_init  (pthread_cond_t *,pthread_condattr_t);

int pthread_cond_destroy  (pthread_cond_t *);
#endif	/*	!IBMOS2	*/

/*
 * A thread can signal to and broadcast on a condition variable.
 */
#ifdef IBMOS2
int DCEAPI
pthread_cond_broadcast (pthread_cond_t	*);

int DCEAPI
pthread_cond_signal (pthread_cond_t	*);

int DCEAPI
pthread_cond_signal_int_np (pthread_cond_t	*);
#else	/*	!IBMOS2	*/
int pthread_cond_broadcast  (pthread_cond_t *);

int pthread_cond_signal  (pthread_cond_t *);

int pthread_cond_signal_int_np  (pthread_cond_t *);
#endif	/*	!IBMOS2	*/

/*
 * A thread can wait for a condition variable to be signalled or broadcast.
 */
#ifdef IBMOS2
int DCEAPI
pthread_cond_wait (pthread_cond_t          *,
				   pthread_mutex_t         *);
#else	/*	!IBMOS2	*/
int pthread_cond_wait  (pthread_cond_t *,pthread_mutex_t *);
#endif	/*	!IBMOS2	*/

/*
 * Operations for timed waiting
 */

/*
 * A thread can perform a timed wait on a condition variable.
 */
#ifdef IBMOS2
int DCEAPI
pthread_cond_timedwait (pthread_cond_t	*,
						pthread_mutex_t	*,
						struct timespec	*);
#else	/*	!IBMOS2	*/
int pthread_cond_timedwait  (pthread_cond_t *,pthread_mutex_t *,struct timespec *);
#endif	/*	!IBMOS2	*/

/*
 * Operations for client initialization.
 */
typedef void (*pthread_initroutine_t) (void);

#ifdef IBMOS2
#ifdef DCE_OS2_PTHREAD
int DCEAPI
pthread_once (pthread_once_t		*,
			  pthread_initroutine_t);
/* CMVC 8106 STARTED */
#if defined(__IBMC__) || defined(__IBMCPP__)
/* CMVC 8106 ENDED  */
int _Optlink
pthread_once_optlink (pthread_once_t		*,
					  pthread_initroutine_t);
#endif	/*	__IBMC__ || __IBMCPP__	*/

int DCEAPI
pthread_once_system (pthread_once_t			*,
					 pthread_initroutine_t);
#else	/*	!DCE_OS2_PTHREAD	*/
/*  CMVC  8106  STARTED   */
#if defined(__IBMC__) || defined(__IBMCPP__)
/*  CMVC  8106  ENDED  */
int _Optlink
pthread_once_optlink (pthread_once_t		*,
					  pthread_initroutine_t);
#endif	/*	__IBMC__ || __IBMCPP__	*/
int DCEAPI
pthread_once_system (pthread_once_t			*,
					 pthread_initroutine_t);

#ifdef DCEOS2_THREAD_SYSTEM_LINKAGE
#define  pthread_once(a,b)  pthread_once_system(a,b)
#else	/*	!DCE_OS2_THREAD_SYSTEM_LINKAGE	*/
#define  pthread_once(a,b)  pthread_once_optlink(a,b)
#endif /*	!DCEOS2_THREAD_SYSTEM_LINKAGE	*/
#endif /*	!DCE_OS2_PTHREAD	*/
#else	/*	!IBMOS2	*/
int pthread_once  (pthread_once_t *,pthread_initroutine_t);
#endif	/*	!IBMOS2	*/

/*
 * Operations for per-thread context
 */

typedef cma_t_destructor        pthread_destructor_t;

/*
 * A unique per-thread context key can be obtained for the process
 */
#ifdef IBMOS2
int DCEAPI
pthread_keycreate (pthread_key_t		*,
				   pthread_destructor_t);
#else	/*	!IBMOS2	*/
int pthread_keycreate  (pthread_key_t *,pthread_destructor_t);
#endif	/*	!IBMOS2	*/

/*
 * A thread can set a per-thread context value identified by a key.
 */
#ifdef IBMOS2
int DCEAPI
pthread_setspecific (pthread_key_t,
					 pthread_addr_t);
#else	/*	!IBMOS2	*/
int pthread_setspecific  (pthread_key_t,pthread_addr_t);
#endif	/*	!IBMOS2	*/

/*
 * A thread can retrieve a per-thread context value identified by a key.
 */
#ifdef IBMOS2
int DCEAPI
pthread_getspecific (pthread_key_t,
					 pthread_addr_t	*);
#else	/*	!IBMOS2	*/
int pthread_getspecific  (pthread_key_t,pthread_addr_t *);
#endif	/*	!IBMOS2	*/

/*
 * Operations for alerts.
 */

/*
 * The current thread can request that a thread terminate it's execution.
 */

#ifdef IBMOS2
int DCEAPI
pthread_cancel (pthread_t);
#else	/*	!IBMOS2	*/
int pthread_cancel  (pthread_t);
#endif	/*	!IBMOS2	*/

/*
 * The current thread can poll for alert delivery.
 */
#ifdef IBMOS2
void DCEAPI
pthread_testcancel (void);
#else	/*	!IBMOS2	*/
void pthread_testcancel  (void);
#endif	/*	!IBMOS2	*/

/*
 * The current thread can enable or disable alert delivery (PTHREAD
 * "cancels"); it can control "general cancelability" (CMA "defer") or
 * just "asynchronous cancelability" (CMA "asynch disable").
 */
#ifdef IBMOS2
int DCEAPI
pthread_setasynccancel (int);

int DCEAPI
pthread_setcancel (int);
#else	/*	!IBMOS2	*/
int pthread_setasynccancel  (int);

int pthread_setcancel  (int);
#endif	/*	!IBMOS2	*/

#if defined(IBMOS2) && !defined(__BORLANDC__)
/*
 *	__BORLANDC__
 *		appends an "_" to the variable name therfore
 *		all the symbols must be redefined and exported prefaced with an "_"
 */
_CMA_IMPORT_ pthread_attr_t             _pthread_attr_default;
_CMA_IMPORT_ pthread_mutexattr_t        _pthread_mutexattr_default;
_CMA_IMPORT_ pthread_condattr_t         _pthread_condattr_default;

#define  pthread_attr_default          _pthread_attr_default
#define  pthread_mutexattr_default     _pthread_mutexattr_default
#define  pthread_condattr_default      _pthread_condattr_default
#else	/*	!(IBMOS2 && !__BORLANDC__)	*/
_CMA_IMPORT_ pthread_attr_t             pthread_attr_default;
_CMA_IMPORT_ pthread_mutexattr_t        pthread_mutexattr_default;
_CMA_IMPORT_ pthread_condattr_t         pthread_condattr_default;
#endif	/*	!(IBMOS2 && !__BORLANDC__)	*/

/*
 * Define nonportable extensions
 */

#ifdef IBMOS2
extern int DCEAPI
pthread_get_expiration_np (struct timespec *,
						   struct timespec *);

extern int DCEAPI
pthread_delay_np (struct timespec *);

extern void DCEAPI
pthread_lock_global_np (void);

extern void DCEAPI
pthread_unlock_global_np (void);

# if _CMA_OS_ != _CMA__VMS
extern int DCEAPI
pthread_signal_to_cancel_np (sigset_t	*,
							 pthread_t	*);
# endif
#else	/*	!IBMOS2	*/
extern int pthread_get_expiration_np  (struct timespec *,struct timespec	*);

extern int pthread_delay_np  (struct timespec *);

#if (_CMA_UNIX_TYPE == _CMA__SVR4)
extern unsigned int pthread_delay_unsigned_np  (unsigned int );
#endif /* (_CMA_UNIX_TYPE == _CMA__SVR4) */

extern void pthread_lock_global_np  (void);

extern void pthread_unlock_global_np  (void);

# if _CMA_OS_ != _CMA__VMS
extern int pthread_signal_to_cancel_np  (sigset_t *,pthread_t *);
# endif
#endif	/*	!IBMOS2	*/

#ifdef IBMOS2
/*
 *	necessary because of different declarations of 
 *	the functions pthread_pseudo_begin_np() and
 *	pthread_pseudo_end_np()
 */
#ifdef INCL_DOSEXCEPTIONS

extern void DCEAPI
pthread_pseudo_begin_np (unsigned int                   *,
                         unsigned int                   *,
                         EXCEPTIONREGISTRATIONRECORD	*,
                         void                           *);

extern void DCEAPI
pthread_pseudo_end_np (unsigned int,
                       unsigned int,
                       EXCEPTIONREGISTRATIONRECORD	*,
                       void							*);
#else	/*	!INCL_DOSEXCEPTIONS	*/

extern void DCEAPI
pthread_pseudo_begin_np (unsigned int					*,
						 unsigned int					*,
						 EXCEPTIONREGISTRATIONRECORDcma	*,
						 void							*);

extern void DCEAPI
pthread_pseudo_end_np (unsigned int,
					   unsigned int,
					   EXCEPTIONREGISTRATIONRECORDcma	*,
					   void								*);
#endif	/*	!INCL_DOSEXCEPTIONS	*/

extern unsigned int DCEAPI
pthread_getunique_np(pthread_t	*);

extern unsigned int DCEAPI
pthread_get_threadid_np(pthread_t	*);

int DCEAPI
sigaction (int,
		   struct sigaction	*,
		   struct sigaction	*);

int DCEAPI
sigwait (sigset_t	*);

int DCEAPI
sigprocmask (int,
			 sigset_t	*,
			 sigset_t	*);

#ifndef SIG_BLOCK
#define SIG_BLOCK		0
#endif	/*	!SIG_BLOCK	*/

#ifndef SIG_UNBLOCK
#define SIG_UNBLOCK		1
#endif	/*	!SIG_UNBLOCK	*/

#ifndef SIG_SETMASK
#define SIG_SETMASK		2
#endif	/*	!SIG_SETMASK	*/

int DCEAPI
sigpending (sigset_t	*);

int DCEAPI
sigemptyset (sigset_t	*);

int DCEAPI
sigfillset (sigset_t	*);

int DCEAPI
sigaddset (sigset_t	*,
		   int);

int DCEAPI
sigdelset (sigset_t	*,
		   int);

int DCEAPI
sigismember (sigset_t	*,
			 int);

#ifdef __cplusplus
	}
#endif
#endif	/*	IBMOS2	*/

#endif

