1 /*
2  * pthread_kill.c
3  *
4  * Description:
5  * This translation unit implements the pthread_kill routine.
6  *
7  * --------------------------------------------------------------------------
8  *
9  *      Pthreads4w - POSIX Threads for Windows
10  *      Copyright 1998 John E. Bossom
11  *      Copyright 1999-2018, Pthreads4w contributors
12  *
13  *      Homepage: https://sourceforge.net/projects/pthreads4w/
14  *
15  *      The current list of contributors is contained
16  *      in the file CONTRIBUTORS included with the source
17  *      code distribution. The list can also be seen at the
18  *      following World Wide Web location:
19  *
20  *      https://sourceforge.net/p/pthreads4w/wiki/Contributors/
21  *
22  * Licensed under the Apache License, Version 2.0 (the "License");
23  * you may not use this file except in compliance with the License.
24  * You may obtain a copy of the License at
25  *
26  *     http://www.apache.org/licenses/LICENSE-2.0
27  *
28  * Unless required by applicable law or agreed to in writing, software
29  * distributed under the License is distributed on an "AS IS" BASIS,
30  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
31  * See the License for the specific language governing permissions and
32  * limitations under the License.
33  */
34 
35 #ifdef HAVE_CONFIG_H
36 # include <config.h>
37 #endif
38 
39 #include "pthread.h"
40 #include "implement.h"
41 
42 /*
43  * Not needed yet, but defining it should indicate clashes with build target
44  * environment that should be fixed.
45  */
46 #if !defined(WINCE)
47 #  include <signal.h>
48 #endif
49 
50 int
pthread_kill(pthread_t thread,int sig)51 pthread_kill (pthread_t thread, int sig)
52      /*
53       * ------------------------------------------------------
54       * DOCPUBLIC
55       *      This function requests that a signal be delivered to the
56       *      specified thread. If sig is zero, error checking is
57       *      performed but no signal is actually sent such that this
58       *      function can be used to check for a valid thread ID.
59       *
60       * PARAMETERS
61       *      thread  reference to an instances of pthread_t
62       *      sig     signal. Currently only a value of 0 is supported.
63       *
64       *
65       * DESCRIPTION
66       *      This function requests that a signal be delivered to the
67       *      specified thread. If sig is zero, error checking is
68       *      performed but no signal is actually sent such that this
69       *      function can be used to check for a valid thread ID.
70       *
71       * RESULTS
72       *              ESRCH           the thread is not a valid thread ID,
73       *              EINVAL          the value of the signal is invalid
74       *                              or unsupported.
75       *              0               the signal was successfully sent.
76       *
77       * ------------------------------------------------------
78       */
79 {
80   int result = 0;
81 
82   if (0 != sig)
83     {
84       /*
85        * Currently does not support any signals.
86        */
87       result = EINVAL;
88     }
89   else
90     {
91       __ptw32_mcs_local_node_t node;
92       __ptw32_thread_t * tp;
93 
94       __ptw32_mcs_lock_acquire(&__ptw32_thread_reuse_lock, &node);
95 
96       tp = (__ptw32_thread_t *) thread.p;
97 
98       if (NULL == tp
99 	  || thread.x != tp->ptHandle.x
100 	  || tp->state < PThreadStateRunning)
101 	{
102 	  result = ESRCH;
103 	}
104 
105       __ptw32_mcs_lock_release(&node);
106     }
107 
108   return result;
109 
110 }				/* pthread_kill */
111