xref: /relibc/pthreads-emb/pthread_kill.c (revision a12978ccca4c576f02971f5cfc2cbefe23e4daba)
1062c5bc4SJason Schmidlapp /*
2062c5bc4SJason Schmidlapp  * pthread_kill.c
3062c5bc4SJason Schmidlapp  *
4062c5bc4SJason Schmidlapp  * Description:
5062c5bc4SJason Schmidlapp  * This translation unit implements the pthread_kill routine.
6062c5bc4SJason Schmidlapp  *
7062c5bc4SJason Schmidlapp  * --------------------------------------------------------------------------
8062c5bc4SJason Schmidlapp  *
9062c5bc4SJason Schmidlapp  *      Pthreads-embedded (PTE) - POSIX Threads Library for embedded systems
10062c5bc4SJason Schmidlapp  *      Copyright(C) 2008 Jason Schmidlapp
11062c5bc4SJason Schmidlapp  *
12062c5bc4SJason Schmidlapp  *      Contact Email: jschmidlapp@users.sourceforge.net
13062c5bc4SJason Schmidlapp  *
14062c5bc4SJason Schmidlapp  *
15062c5bc4SJason Schmidlapp  *      Based upon Pthreads-win32 - POSIX Threads Library for Win32
16062c5bc4SJason Schmidlapp  *      Copyright(C) 1998 John E. Bossom
17062c5bc4SJason Schmidlapp  *      Copyright(C) 1999,2005 Pthreads-win32 contributors
18062c5bc4SJason Schmidlapp  *
19062c5bc4SJason Schmidlapp  *      Contact Email: rpj@callisto.canberra.edu.au
20062c5bc4SJason Schmidlapp  *
21062c5bc4SJason Schmidlapp  *      The original list of contributors to the Pthreads-win32 project
22062c5bc4SJason Schmidlapp  *      is contained in the file CONTRIBUTORS.ptw32 included with the
23062c5bc4SJason Schmidlapp  *      source code distribution. The list can also be seen at the
24062c5bc4SJason Schmidlapp  *      following World Wide Web location:
25062c5bc4SJason Schmidlapp  *      http://sources.redhat.com/pthreads-win32/contributors.html
26062c5bc4SJason Schmidlapp  *
27062c5bc4SJason Schmidlapp  *      This library is free software; you can redistribute it and/or
28062c5bc4SJason Schmidlapp  *      modify it under the terms of the GNU Lesser General Public
29062c5bc4SJason Schmidlapp  *      License as published by the Free Software Foundation; either
30062c5bc4SJason Schmidlapp  *      version 2 of the License, or (at your option) any later version.
31062c5bc4SJason Schmidlapp  *
32062c5bc4SJason Schmidlapp  *      This library is distributed in the hope that it will be useful,
33062c5bc4SJason Schmidlapp  *      but WITHOUT ANY WARRANTY; without even the implied warranty of
34062c5bc4SJason Schmidlapp  *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
35062c5bc4SJason Schmidlapp  *      Lesser General Public License for more details.
36062c5bc4SJason Schmidlapp  *
37062c5bc4SJason Schmidlapp  *      You should have received a copy of the GNU Lesser General Public
38062c5bc4SJason Schmidlapp  *      License along with this library in the file COPYING.LIB;
39062c5bc4SJason Schmidlapp  *      if not, write to the Free Software Foundation, Inc.,
40062c5bc4SJason Schmidlapp  *      59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
41062c5bc4SJason Schmidlapp  */
42062c5bc4SJason Schmidlapp 
43062c5bc4SJason Schmidlapp #include <stdio.h>
44062c5bc4SJason Schmidlapp #include <stdlib.h>
45062c5bc4SJason Schmidlapp #include <string.h>
46062c5bc4SJason Schmidlapp 
47062c5bc4SJason Schmidlapp #include "pthread.h"
48062c5bc4SJason Schmidlapp #include "implement.h"
49062c5bc4SJason Schmidlapp 
50062c5bc4SJason Schmidlapp int
pthread_kill(pthread_t thread,int sig)51062c5bc4SJason Schmidlapp pthread_kill (pthread_t thread, int sig)
52062c5bc4SJason Schmidlapp /*
53062c5bc4SJason Schmidlapp  * ------------------------------------------------------
54062c5bc4SJason Schmidlapp  * DOCPUBLIC
55062c5bc4SJason Schmidlapp  *      This function requests that a signal be delivered to the
56062c5bc4SJason Schmidlapp  *      specified thread. If sig is zero, error checking is
57062c5bc4SJason Schmidlapp  *      performed but no signal is actually sent such that this
58062c5bc4SJason Schmidlapp  *      function can be used to check for a valid thread ID.
59062c5bc4SJason Schmidlapp  *
60062c5bc4SJason Schmidlapp  * PARAMETERS
61062c5bc4SJason Schmidlapp  *      thread  reference to an instances of pthread_t
62062c5bc4SJason Schmidlapp  *      sig     signal. Currently only a value of 0 is supported.
63062c5bc4SJason Schmidlapp  *
64062c5bc4SJason Schmidlapp  *
65062c5bc4SJason Schmidlapp  * DESCRIPTION
66062c5bc4SJason Schmidlapp  *      This function requests that a signal be delivered to the
67062c5bc4SJason Schmidlapp  *      specified thread. If sig is zero, error checking is
68062c5bc4SJason Schmidlapp  *      performed but no signal is actually sent such that this
69062c5bc4SJason Schmidlapp  *      function can be used to check for a valid thread ID.
70062c5bc4SJason Schmidlapp  *
71062c5bc4SJason Schmidlapp  * RESULTS
72062c5bc4SJason Schmidlapp  *              ESRCH           the thread is not a valid thread ID,
73062c5bc4SJason Schmidlapp  *              EINVAL          the value of the signal is invalid
74062c5bc4SJason Schmidlapp  *                              or unsupported.
75062c5bc4SJason Schmidlapp  *              0               the signal was successfully sent.
76062c5bc4SJason Schmidlapp  *
77062c5bc4SJason Schmidlapp  * ------------------------------------------------------
78062c5bc4SJason Schmidlapp  */
79062c5bc4SJason Schmidlapp {
80062c5bc4SJason Schmidlapp   int result = 0;
81062c5bc4SJason Schmidlapp   pte_thread_t * tp;
82062c5bc4SJason Schmidlapp 
83062c5bc4SJason Schmidlapp 
84062c5bc4SJason Schmidlapp   pte_osMutexLock (pte_thread_reuse_lock);
85062c5bc4SJason Schmidlapp 
86*a12978ccSJeremy Soller   tp = (pte_thread_t *) thread;
87062c5bc4SJason Schmidlapp 
88062c5bc4SJason Schmidlapp   if (NULL == tp
89062c5bc4SJason Schmidlapp       || 0 == tp->threadId)
90062c5bc4SJason Schmidlapp     {
91062c5bc4SJason Schmidlapp       result = ESRCH;
92062c5bc4SJason Schmidlapp     }
93062c5bc4SJason Schmidlapp 
94062c5bc4SJason Schmidlapp   pte_osMutexUnlock(pte_thread_reuse_lock);
95062c5bc4SJason Schmidlapp 
96062c5bc4SJason Schmidlapp   if (0 == result && 0 != sig)
97062c5bc4SJason Schmidlapp     {
98062c5bc4SJason Schmidlapp       /*
99062c5bc4SJason Schmidlapp        * Currently does not support any signals.
100062c5bc4SJason Schmidlapp        */
101062c5bc4SJason Schmidlapp       result = EINVAL;
102062c5bc4SJason Schmidlapp     }
103062c5bc4SJason Schmidlapp 
104062c5bc4SJason Schmidlapp   return result;
105062c5bc4SJason Schmidlapp 
106062c5bc4SJason Schmidlapp }				/* pthread_kill */
107