Use glibc_likely instead __builtin_expect.
[jlayton/glibc.git] / nptl / sysdeps / unix / sysv / linux / raise.c
1 /* Copyright (C) 2002-2014 Free Software Foundation, Inc.
2    This file is part of the GNU C Library.
3    Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
4
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.
9
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.
14
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    <http://www.gnu.org/licenses/>.  */
18
19 #include <errno.h>
20 #include <limits.h>
21 #include <signal.h>
22 #include <sysdep.h>
23 #include <nptl/pthreadP.h>
24 #include <kernel-features.h>
25
26
27 int
28 raise (sig)
29      int sig;
30 {
31   struct pthread *pd = THREAD_SELF;
32   pid_t pid = THREAD_GETMEM (pd, pid);
33   pid_t selftid = THREAD_GETMEM (pd, tid);
34   if (selftid == 0)
35     {
36       /* This system call is not supposed to fail.  */
37 #ifdef INTERNAL_SYSCALL
38       INTERNAL_SYSCALL_DECL (err);
39       selftid = INTERNAL_SYSCALL (gettid, err, 0);
40 #else
41       selftid = INLINE_SYSCALL (gettid, 0);
42 #endif
43       THREAD_SETMEM (pd, tid, selftid);
44
45       /* We do not set the PID field in the TID here since we might be
46          called from a signal handler while the thread executes fork.  */
47       pid = selftid;
48     }
49   else
50     /* raise is an async-safe function.  It could be called while the
51        fork/vfork function temporarily invalidated the PID field.  Adjust for
52        that.  */
53     if (__glibc_unlikely (pid <= 0))
54       pid = (pid & INT_MAX) == 0 ? selftid : -pid;
55
56   return INLINE_SYSCALL (tgkill, 3, pid, selftid, sig);
57 }
58 libc_hidden_def (raise)
59 weak_alias (raise, gsignal)