/*
*  Multithreaded Demo Source
* 
*  Copyright (C) 1995 by Sun Microsystems, Inc.
*  All rights reserved.
* 
*  This file is a product of SunSoft, Inc. and is provided for
*  unrestricted use provided that this legend is included on all
*  media and as a part of the software program in whole or part.
*  Users may copy, modify or distribute this file at will.
* 
*  THIS FILE IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING
*  THE WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
*  PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
* 
*  This file is provided with no support and without any obligation on the
*  part of SunSoft, Inc. to assist in its use, correction, modification or
*  enhancement.
* 
*  SUNSOFT AND SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT
*  TO THE INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY THIS
*  FILE OR ANY PART THEREOF.
* 
*  IN NO EVENT WILL SUNSOFT OR SUN MICROSYSTEMS, INC. BE LIABLE FOR ANY
*  LOST REVENUE OR PROFITS OR OTHER SPECIAL, INDIRECT AND CONSEQUENTIAL
*  DAMAGES, EVEN IF THEY HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH
*  DAMAGES.
* 
*  SunSoft, Inc.
*  2550 Garcia Avenue
*  Mountain View, California  94043
*/

/*
 * THREAD.H - Solaris to POSIX Interface Layer for Threads.
 *
 * This code is public domain.  It may be freely distributed provided the
 * Copyright notice is retained. This code is not supported in any way.
 * Usage of the code is solely at the user's/programmer's discretion.
 * Sun Microsystems makes no claim as to the reliabilty, correctness or
 * suitability of this code. Sun Microsystems will not be held liable in
 * any way as a result loss or damage arising from the use this code.
 *
 * Written by: Richard.Marejka@Canada.Sun.COM
 * Copyright (c) 1994, by Sun Microsystems, Inc.
 */

#if !defined(THREAD_INCLUDED)
#define	THREAD_INCLUDED

#pragma ident "@(#) thread.h.txt 1.2 95/03/01	Richard.Marejka@Canada.Sun.COM"

/* Feature Test Macros		*/

#define	_POSIX_THREADS

#if !defined(SPILT_MACROS)
#	define	SPILT_MACROS	1	/* use macros where possible	*/
#endif

/* Include Files		*/

#include <pthread.h>
#include <signal.h>

/* Constants & Macros		*/

#define	_SPILT_LIBERAL_DAEMON		0x0001	/* default	*/
#define	_SPILT_LIBERAL_SUSPENDED	0x0002
#define	_SPILT_LIBERAL_NEW_LWP		0x0004	/* default	*/
#define	_SPILT_LIBERAL_SETCONCURRENCY	0x0008	/* default	*/

#define	_SPILT_LIBERAL_GETCONCURRENCY	0x0010	/* default	*/
#define	_SPILT_LIBERAL_SUSPEND		0x0020
#define	_SPILT_LIBERAL_CONTINUE		0x0040
#define	_SPILT_LIBERAL_BOUND		0x0080

#define	_SPILT_LIBERAL_STACKADDR	0x0100	/* default	*/
#define	_SPILT_LIBERAL_STACKSIZE	0x0200	/* default	*/
#define	_SPILT_LIBERAL_SETPRIO		0x0400	/* default	*/
#define	_SPILT_LIBERAL_GETPRIO		0x0800	/* default	*/

#define	_SPILT_LIBERAL_DEFAULT		(0x0f1d)

#define	SPILT_LIBERAL			_SPILT_LIBERAL_DEFAULT

#if defined(SPILT_MACROS)
#	define	thread_t		pthread_t
#	define	thread_key_t		pthread_key_t

#	define	thr_self		pthread_self
#	define	thr_exit		pthread_exit
#	define	thr_yield		sched_yield
#	define	thr_sigsetmask		pthread_sigmask
#	define	thr_kill		pthread_kill
#	define	thr_keycreate		pthread_key_create
#	define	thr_setspecific		pthread_setspecific
#endif	/* SPILT_MACROS	*/

#define	THR_DAEMON		0x0001
#define	THR_NEW_LWP		0x0002
#define	THR_BOUND		0x0004
#define	THR_SUSPENDED		0x0008
#define	THR_DETACHED		0x0010

/* Data Declarations		*/

#if !defined(SPILT_MACROS)
typedef pthread_t	thread_t;
typedef pthread_key_t	thread_key_t;
#endif	/* SPILT_MACROS	*/

/* External References		*/

#if defined(__cplusplus)
extern "C" {
#endif

extern	int	thr_create( void *, size_t, void *(*)( void * ), void *, long, thread_t * );
extern	size_t	thr_min_stack( void );
#if !defined(SPILT_MACROS)
extern	thread_t	thr_self( void );
extern	void	thr_exit( void * );
#endif	/* SPILT_MACROS	*/
extern	int	thr_join( thread_t, thread_t *, void ** );
extern	int	thr_setprio( thread_t, int  );
extern	int	thr_getprio( thread_t, int * );
extern	int	thr_suspend( thread_t );
extern	int	thr_continue( thread_t );
extern	int	thr_setconcurrency( int );
extern	int	thr_getconcurrency( void );
#if !defined(SPILT_MACROS)
extern	int	thr_yield( void );
extern	int	thr_sigsetmask( int, const sigset_t *, sigset_t * );
extern	int	thr_kill( thread_t, int );
extern	int	thr_keycreate( thread_key_t *, void (*)( void * ) );
extern	int	thr_setspecific( thread_key_t, void * );
#endif	/* SPILT_MACROS	*/
extern	int	thr_getspecific( thread_key_t, void ** );

#if defined(__cplusplus)
}
#endif
#endif	/* THREAD_INCLUDED	*/
