1 | /* |
2 | * kmp_wrapper_getpid.h -- getpid() declaration. |
3 | */ |
4 | |
5 | //===----------------------------------------------------------------------===// |
6 | // |
7 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
8 | // See https://llvm.org/LICENSE.txt for license information. |
9 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
10 | // |
11 | //===----------------------------------------------------------------------===// |
12 | |
13 | #ifndef KMP_WRAPPER_GETPID_H |
14 | #define KMP_WRAPPER_GETPID_H |
15 | |
16 | #if KMP_OS_UNIX |
17 | |
18 | // On Unix-like systems (Linux* OS and OS X*) getpid() is declared in standard |
19 | // headers. |
20 | #if !defined(KMP_OS_AIX) |
21 | #include <sys/syscall.h> |
22 | #endif |
23 | #include <sys/types.h> |
24 | #include <unistd.h> |
25 | #if KMP_OS_DARWIN |
26 | // OS X |
27 | #define __kmp_gettid() pthread_mach_thread_np(pthread_self()) |
28 | #elif KMP_OS_FREEBSD || KMP_OS_DRAGONFLY |
29 | #include <pthread_np.h> |
30 | #define __kmp_gettid() pthread_getthreadid_np() |
31 | #elif KMP_OS_NETBSD |
32 | #include <lwp.h> |
33 | #define __kmp_gettid() _lwp_self() |
34 | #elif KMP_OS_OPENBSD |
35 | #define __kmp_gettid() getthrid() |
36 | #elif KMP_OS_AIX |
37 | #include <pthread.h> |
38 | #define __kmp_gettid() pthread_self() |
39 | #elif defined(SYS_gettid) |
40 | // Hopefully other Unix systems define SYS_gettid syscall for getting os thread |
41 | // id |
42 | #define __kmp_gettid() syscall(SYS_gettid) |
43 | #else |
44 | #warning No gettid found, use getpid instead |
45 | #define __kmp_gettid() getpid() |
46 | #endif |
47 | |
48 | #elif KMP_OS_WINDOWS |
49 | |
50 | // On Windows* OS _getpid() returns int (not pid_t) and is declared in |
51 | // "process.h". |
52 | #include <process.h> |
53 | // Let us simulate Unix. |
54 | #if KMP_MSVC_COMPAT |
55 | typedef int pid_t; |
56 | #endif |
57 | #define getpid _getpid |
58 | #define __kmp_gettid() GetCurrentThreadId() |
59 | |
60 | #else |
61 | |
62 | #error Unknown or unsupported OS. |
63 | |
64 | #endif |
65 | |
66 | /* TODO: All the libomp source code uses pid_t type for storing the result of |
67 | getpid(), it is good. But often it printed as "%d", that is not good, because |
68 | it ignores pid_t definition (may pid_t be longer that int?). It seems all pid |
69 | prints should be rewritten as: |
70 | |
71 | printf( "%" KMP_UINT64_SPEC, (kmp_uint64) pid ); |
72 | |
73 | or (at least) as |
74 | |
75 | printf( "%" KMP_UINT32_SPEC, (kmp_uint32) pid ); |
76 | |
77 | (kmp_uint32, kmp_uint64, KMP_UINT64_SPEC, and KMP_UNIT32_SPEC are defined in |
78 | "kmp_os.h".) */ |
79 | |
80 | #endif // KMP_WRAPPER_GETPID_H |
81 | |
82 | // end of file // |
83 | |