]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/openmp/runtime/src/kmp_wrapper_getpid.h
MFS r353563:
[FreeBSD/FreeBSD.git] / contrib / openmp / runtime / src / kmp_wrapper_getpid.h
1 /*
2  * kmp_wrapper_getpid.h -- getpid() declaration.
3  */
4
5 //===----------------------------------------------------------------------===//
6 //
7 //                     The LLVM Compiler Infrastructure
8 //
9 // This file is dual licensed under the MIT and the University of Illinois Open
10 // Source Licenses. See LICENSE.txt for details.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #ifndef KMP_WRAPPER_GETPID_H
15 #define KMP_WRAPPER_GETPID_H
16
17 #if KMP_OS_UNIX
18
19 // On Unix-like systems (Linux* OS and OS X*) getpid() is declared in standard
20 // headers.
21 #include <sys/syscall.h>
22 #include <sys/types.h>
23 #include <unistd.h>
24 #if KMP_OS_DARWIN
25 // OS X
26 #define __kmp_gettid() syscall(SYS_thread_selfid)
27 #elif KMP_OS_FREEBSD
28 #include <pthread_np.h>
29 #define __kmp_gettid() pthread_getthreadid_np()
30 #elif KMP_OS_NETBSD
31 #include <lwp.h>
32 #define __kmp_gettid() _lwp_self()
33 #elif defined(SYS_gettid)
34 // Hopefully other Unix systems define SYS_gettid syscall for getting os thread
35 // id
36 #define __kmp_gettid() syscall(SYS_gettid)
37 #else
38 #warning No gettid found, use getpid instead
39 #define __kmp_gettid() getpid()
40 #endif
41
42 #elif KMP_OS_WINDOWS
43
44 // On Windows* OS _getpid() returns int (not pid_t) and is declared in
45 // "process.h".
46 #include <process.h>
47 // Let us simulate Unix.
48 #if KMP_MSVC_COMPAT
49 typedef int pid_t;
50 #endif
51 #define getpid _getpid
52 #define __kmp_gettid() GetCurrentThreadId()
53
54 #else
55
56 #error Unknown or unsupported OS.
57
58 #endif
59
60 /* TODO: All the libomp source code uses pid_t type for storing the result of
61    getpid(), it is good. But often it printed as "%d", that is not good, because
62    it ignores pid_t definition (may pid_t be longer that int?). It seems all pid
63    prints should be rewritten as:
64
65    printf( "%" KMP_UINT64_SPEC, (kmp_uint64) pid );
66
67    or (at least) as
68
69    printf( "%" KMP_UINT32_SPEC, (kmp_uint32) pid );
70
71    (kmp_uint32, kmp_uint64, KMP_UINT64_SPEC, and KMP_UNIT32_SPEC are defined in
72    "kmp_os.h".)  */
73
74 #endif // KMP_WRAPPER_GETPID_H
75
76 // end of file //