annotate openmp/runtime/src/kmp_wrapper_getpid.h @ 152:e8a9b4f4d755

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