2 * kmp_wrapper_getpid.h -- getpid() declaration.
5 //===----------------------------------------------------------------------===//
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
11 //===----------------------------------------------------------------------===//
13 #ifndef KMP_WRAPPER_GETPID_H
14 #define KMP_WRAPPER_GETPID_H
18 // On Unix-like systems (Linux* OS and OS X*) getpid() is declared in standard
20 #include <sys/syscall.h>
21 #include <sys/types.h>
25 #define __kmp_gettid() syscall(SYS_thread_selfid)
27 #include <pthread_np.h>
28 #define __kmp_gettid() pthread_getthreadid_np()
31 #define __kmp_gettid() _lwp_self()
32 #elif defined(SYS_gettid)
33 // Hopefully other Unix systems define SYS_gettid syscall for getting os thread
35 #define __kmp_gettid() syscall(SYS_gettid)
37 #warning No gettid found, use getpid instead
38 #define __kmp_gettid() getpid()
43 // On Windows* OS _getpid() returns int (not pid_t) and is declared in
46 // Let us simulate Unix.
50 #define getpid _getpid
51 #define __kmp_gettid() GetCurrentThreadId()
55 #error Unknown or unsupported OS.
59 /* TODO: All the libomp source code uses pid_t type for storing the result of
60 getpid(), it is good. But often it printed as "%d", that is not good, because
61 it ignores pid_t definition (may pid_t be longer that int?). It seems all pid
62 prints should be rewritten as:
64 printf( "%" KMP_UINT64_SPEC, (kmp_uint64) pid );
68 printf( "%" KMP_UINT32_SPEC, (kmp_uint32) pid );
70 (kmp_uint32, kmp_uint64, KMP_UINT64_SPEC, and KMP_UNIT32_SPEC are defined in
73 #endif // KMP_WRAPPER_GETPID_H