/*
 * $Id: signal.h,v 1.7 2000/09/22 22:05:17 k-abe Exp $
 *
 * This file is part of PTL, Portable Thread Library.
 *
 * Copyright (C) 1997-2000 Kota Abe
 *
 */

#ifndef __PTL_SIGNAL_H__
#define __PTL_SIGNAL_H__

/*
 * Defining POSIXSIGFUNC=1 makes to emulate POSIX signal interface with
 * BSD signal system calls.  (defined in <sys/pthread-extsym.h>)
 */

#include <sys/types.h>		/* to #include <sys/signal.h> */

/* ---------------------------------------------------------------- */
#ifdef __PTL_RENAMED__
# define __PTL_ALREADY_RENAMED_SIGNAL_H
#else
# include <sys/pthread-before.h>
#endif

#ifdef __GNUC__
#include <00root-gcc/sys/signal.h>
#else
#include <00root-system/sys/signal.h>
#endif
#ifdef __GNUC__
#include <00root-gcc/signal.h>
#else
#include <00root-system/signal.h>
#endif

#include <sys/pthread-after.h>
/* ---------------------------------------------------------------- */

#include <pthread.h>
#include <sys/pthread-cdecl.h>
#include <sys/pthread-extsym.h>


__PTL_BEGIN_DECLS

/****************************************************************
 *
 *	3.3.1  Signal Concepts
 *
 ****************************************************************/

#if !POSIXSIGFUNC
typedef long	sigset_t;
#endif /* !POSIXSIGFUNC */


/****************************************************************
 *
 *	3.3.3  Manipulate Signal Sets
 *
 ****************************************************************/

#if !POSIXSIGFUNC

extern int sigemptyset __PTL_P((sigset_t*));
extern int sigfillset __PTL_P((sigset_t*));
extern int sigaddset __PTL_P((sigset_t*, int));
extern int sigdelset __PTL_P((sigset_t*, int));
extern int sigismember __PTL_P((const sigset_t*, int));

#endif


/****************************************************************
 *
 *	3.3.4  Examine and Change Signal Action
 *
 ****************************************************************/

#if !POSIXSIGFUNC
struct sigaction {
    void	(*sa_handler)();	/* signal handler */
    sigset_t	sa_mask;		/* signal mask to apply */
    int		sa_flags;		/* signal options */
};
#endif

#if !POSIXSIGFUNC
# define SA_RESTART	SV_RESTART
# define SA_ONSTACK	SV_ONSTACK
#endif /* !POSIXSIGFUNC */

#ifndef HAVE_SIGINFO
struct siginfo {
    int		si_signo;
    int		si_code;
};
#endif

#ifndef PROTO_SIGACTION
extern int sigaction __PTL_P((int, const struct sigaction*,
			      struct sigaction*));
#endif

/****************************************************************
 *
 *	3.3.5  Examine and Change Blocked Signals
 *
 ****************************************************************/

extern int pthread_sigmask __PTL_P((int, const sigset_t*, sigset_t*));

#ifndef SIG_BLOCK
# define SIG_BLOCK	1
# define SIG_UNBLOCK	2
# define SIG_SETMASK	3
#endif /* SIG_BLOCK */


/****************************************************************
 *
 *	3.3.6  Examine Pending Signals
 *
 ****************************************************************/

#ifndef PROTO_SIGPENDING
extern int sigpending __PTL_P((sigset_t*));
#endif


/****************************************************************
 *
 *	3.3.7  Wait for a Signal
 *
 ****************************************************************/

#ifndef PROTO_SIGACTION
/* Since NetBSD declares sigsuspend as renaming function (__sigsuspend14),
 * we dont rename sigsuspend into sigsuspend_orig.  Therefore, 
 * declaration of sigsuspend is done in system's header file.
 */
extern int sigsuspend __PTL_P((const sigset_t*));
#endif
extern int _pthread_sigsuspend __PTL_P((const sigset_t*,
					const char*, const char*, int));


/****************************************************************
 *
 *	3.3.8  Synchronously Accept a Signal
 *
 ****************************************************************/

extern int sigwait __PTL_P((const sigset_t*, int*));
extern int _pthread_sigwait __PTL_P((const sigset_t*, int*,
				     const char*, const char*, int));

#ifndef SIG_SIGWAIT_NP
# define SIG_SIGWAIT_NP	((void (*)())4)
#endif


/****************************************************************
 *
 *	3.3.10  Send a Signal to a Thread
 *
 ****************************************************************/

extern int pthread_kill __PTL_P((pthread_t, int));


/****************************************************************
 *
 *	8.1 Referenced C Language Routines
 *
 ****************************************************************/
extern int raise __PTL_P((int));

#ifdef __next__
# define raise	_pthread_raise
#endif

__PTL_END_DECLS

/* ---------------------------------------------------------------- */
#ifdef __PTL_ALREADY_RENAMED_SIGNAL_H
# include <sys/pthread-before.h>
# undef __PTL_ALREADY_RENAMED_SIGNAL_H
#else
# include <sys/pthread-after.h>
#endif
/* ---------------------------------------------------------------- */

#endif /* __PTL_SIGNAL_H__ */
