thr_kill.c revision 71581
1223013Sdim/* 2223013Sdim * Copyright (c) 1997 John Birrell <jb@cimlogic.com.au>. 3223013Sdim * All rights reserved. 4223013Sdim * 5223013Sdim * Redistribution and use in source and binary forms, with or without 6223013Sdim * modification, are permitted provided that the following conditions 7223013Sdim * are met: 8223013Sdim * 1. Redistributions of source code must retain the above copyright 9223013Sdim * notice, this list of conditions and the following disclaimer. 10234353Sdim * 2. Redistributions in binary form must reproduce the above copyright 11234353Sdim * notice, this list of conditions and the following disclaimer in the 12234353Sdim * documentation and/or other materials provided with the distribution. 13234353Sdim * 3. All advertising materials mentioning features or use of this software 14223013Sdim * must display the following acknowledgement: 15223013Sdim * This product includes software developed by John Birrell. 16223013Sdim * 4. Neither the name of the author nor the names of any co-contributors 17223013Sdim * may be used to endorse or promote products derived from this software 18223013Sdim * without specific prior written permission. 19249423Sdim * 20224145Sdim * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND 21223013Sdim * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22226633Sdim * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23226633Sdim * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 24249423Sdim * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25234353Sdim * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 26223013Sdim * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27223013Sdim * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 28234353Sdim * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 29243830Sdim * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30243830Sdim * SUCH DAMAGE. 31243830Sdim * 32243830Sdim * $FreeBSD: head/lib/libkse/thread/thr_kill.c 71581 2001-01-24 13:03:38Z deischen $ 33243830Sdim */ 34243830Sdim#include <errno.h> 35249423Sdim#include <signal.h> 36234353Sdim#include <pthread.h> 37234353Sdim#include "pthread_private.h" 38234353Sdim 39223013Sdim#pragma weak pthread_kill=_pthread_kill 40223013Sdim 41234353Sdimint 42223013Sdim_pthread_kill(pthread_t pthread, int sig) 43223013Sdim{ 44234353Sdim int ret; 45234353Sdim 46223013Sdim /* Check for invalid signal numbers: */ 47249423Sdim if (sig < 0 || sig >= NSIG) 48223013Sdim /* Invalid signal: */ 49223013Sdim ret = EINVAL; 50223013Sdim /* 51223013Sdim * Ensure the thread is in the list of active threads, and the 52223013Sdim * signal is valid (signal 0 specifies error checking only) and 53223013Sdim * not being ignored: 54223013Sdim */ 55223013Sdim else if (((ret = _find_thread(pthread)) == 0) && (sig > 0) && 56223013Sdim (_thread_sigact[sig - 1].sa_handler != SIG_IGN)) { 57223013Sdim /* 58223013Sdim * Defer signals to protect the scheduling queues from 59223013Sdim * access by the signal handler: 60223013Sdim */ 61239462Sdim _thread_kern_sig_defer(); 62239462Sdim 63239462Sdim _thread_sig_send(pthread, sig); 64223013Sdim 65223013Sdim /* 66223013Sdim * Undefer and handle pending signals, yielding if 67223013Sdim * necessary: 68234353Sdim */ 69223013Sdim _thread_kern_sig_undefer(); 70223013Sdim } 71223013Sdim 72223013Sdim /* Return the completion status: */ 73223013Sdim return (ret); 74223013Sdim} 75223013Sdim