/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* onc720 src/oncplus/usr/include/nsl/synch.h 1.7                         */
/*                                                                        */
/*                                                                        */
/*                                                                        */
/* COPYRIGHT International Business Machines Corp. 1996,2006              */
/* All Rights Reserved                                                    */
/*                                                                        */
/* IBM_PROLOG_END_TAG                                                     */
/*
*  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
*/

/*
 * SYNCH.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.
 */

#ifndef	_SYNCH_H
#define	_SYNCH_H

/* #pragma ident	"@(#)synch.h	1.37	97/02/19 SMI" */

#include <sys/time.h>
#include <pthread.h>
#include <synch.h>

/*
 * synch.h:
 * definitions needed to use the thread synchronization interface
 */

#ifdef __cplusplus
extern "C" {
#endif

/*
 * POSIX.1c Note:
 * POSIX.1c requires that <pthread.h> define the structures pthread_mutex_t
 * and pthread_cond_t.  These structures are identical to mutex_t (lwp_mutex_t)
 * and cond_t (lwp_cond_t) which are defined in <synch.h>.  A nested included
 * of <synch.h> (to allow a "#typedef mutex_t  pthread_mutex_t") would pull in
 * non-posix symbols/constants violating the namespace restrictions.  Hence,
 * pthread_mutex_t/pthread_cond_t have been redefined in <pthread.h>.  Any
 * modifications done to mutex_t/lwp_mutex_t or cond_t/lwp_cond_t should also
 * be done to pthread_mutex_t/pthread_cond_t.
 */
	
typedef struct timestruc_t timestruc_t;

extern int __libnsl_initialized;
#define  cond_init(x,y,z)        (__libnsl_initialized ? cond_init(x,y,z):0) 
#define  cond_destroy(x)         (__libnsl_initialized ? cond_destroy(x):0) 
#define  cond_wait(x,y)          (__libnsl_initialized ? cond_wait(x,y):0) 
#define  cond_timedwait(x,y,z)   (__libnsl_initialized ? cond_timedwait(x,y,z):0)
#define  cond_signal(x)          (__libnsl_initialized ? cond_signal(x):0)
#define  cond_broadcast(x)       (__libnsl_initialized ? cond_broadcast(x):0)

#define mutex_init(x,y,z)        (__libnsl_initialized ? mutex_init(x,y,z):0) 
#define mutex_destroy(x)         (__libnsl_initialized ? mutex_destroy(x):0) 
#define mutex_lock(x)            (__libnsl_initialized ? mutex_lock(x):0)
#define mutex_trylock(x)         (__libnsl_initialized ? mutex_trylock(x):0)
#define mutex_unlock(x)          (__libnsl_initialized ?  mutex_unlock(x):0) 

#define rwlock_init(x,y,z)		 (__libnsl_initialized ?  rwlock_init(x,y,z):0) 
#define rwlock_destroy(x)		 (__libnsl_initialized ? rwlock_destroy(x):0) 
#define rw_rdlock(x)			 (__libnsl_initialized ?  rw_rdlock(x):0) 
#define rw_wrlock(x)			(__libnsl_initialized ?  rw_wrlock(x):0) 
#define rw_unlock(x)			(__libnsl_initialized ?  rw_unlock(x):0) 
#define rw_tryrdlock(x)			(__libnsl_initialized ? rw_tryrdlock(x):0) 
#define rw_trywrlock(x)			(__libnsl_initialized ?  rw_trywrlock(x):0) 

/*
 * POSIX.1c Note:
 * DEFAULTMUTEX is defined same as PTHREAD_MUTEX_INITIALIZER in <pthread.h>.
 * DEFAULTCV is defined same as PTHREAD_COND_INITIALIZER in <pthread.h>.
 * Any changes to these macros should be reflected in <pthread.h>
 */
/*
#define	DEFAULTMUTEX	{0, 0, 0, 0, USYNC_THREAD, MUTEX_MAGIC, \
				0, 0, 0, 0, 0, 0, 0, 0, 0}
				*/
#define DEFAULTMUTEX	PTHREAD_MUTEX_INITIALIZER

#ifdef __64BIT__
#define DEFAULTRWLOCK \
{{ \
        _PTH_FLAGS_INIT64, \
        0, \
        0, \
        0, \
        0 \
}}
#else
#define DEFAULTRWLOCK \
{{ \
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, \
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, \
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, \
        0, 0, 0, 0, 0, \
        0, \
        0, \
        2, \
        0, \
        0 \
}}
#endif /* __64BIT__ */


/*
 * Tests on lock states.
 */
#define	RW_READ_HELD(x)		_rw_read_held(x)
#define	RW_WRITE_HELD(x)	_rw_write_held(x)
#define	RW_LOCK_HELD(x)		(RW_READ_HELD(x) || RW_WRITE_HELD(x))

int _rw_read_held(rwlock_t *);
int _rw_write_held(rwlock_t *);
int mutex_held(mutex_t *);


#ifdef	__cplusplus
}
#endif



#endif
