LoongArch: Use "$fcsr0" instead of "$r0" in _FPU_{GET,SET}CW
[glibc.git] / sysdeps / pthread / tst-pthread-raise-blocked-self.c
blob5dc2932dceebbef33af2579868a1810cb17fb43f
1 /* Test that raise sends signal to current thread even if blocked.
2 Copyright (C) 2021-2024 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <https://www.gnu.org/licenses/>. */
19 #include <signal.h>
20 #include <support/check.h>
21 #include <support/xsignal.h>
22 #include <support/xthread.h>
23 #include <pthread.h>
24 #include <unistd.h>
26 /* Used to create a dummy thread ID distinct from all other thread
27 IDs. */
28 static void *
29 noop (void *ignored)
31 return NULL;
34 static volatile pthread_t signal_thread;
36 static void
37 signal_handler (int signo)
39 signal_thread = pthread_self ();
42 /* Used to ensure that waiting_thread has launched and can accept
43 signals. */
44 static pthread_barrier_t barrier;
46 static void *
47 waiting_thread (void *ignored)
49 xpthread_barrier_wait (&barrier);
50 pause ();
51 return NULL;
54 static int
55 do_test (void)
57 xsignal (SIGUSR1, signal_handler);
58 xpthread_barrier_init (&barrier, NULL, 2);
60 /* Distinct thread ID value to */
61 pthread_t dummy = xpthread_create (NULL, noop, NULL);
62 signal_thread = dummy;
64 pthread_t helper = xpthread_create (NULL, waiting_thread, NULL);
66 /* Make sure that the thread is running. */
67 xpthread_barrier_wait (&barrier);
69 /* Block signals on this thread. */
70 sigset_t set;
71 sigfillset (&set);
72 xpthread_sigmask (SIG_BLOCK, &set, NULL);
74 /* Send the signal to this thread. It must not be delivered. */
75 raise (SIGUSR1);
76 TEST_VERIFY (signal_thread == dummy);
78 /* Wait a bit to give a chance for signal delivery (increases
79 chances of failure with bug 28407). */
80 usleep (50 * 1000);
82 /* Unblocking should cause synchronous delivery of the signal. */
83 xpthread_sigmask (SIG_UNBLOCK, &set, NULL);
84 TEST_VERIFY (signal_thread == pthread_self ());
86 xpthread_cancel (helper);
87 xpthread_join (helper);
88 xpthread_join (dummy);
89 return 0;
92 #include <support/test-driver.c>