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 defined(SYS_gettid) 28 // Hopefully other Unix systems define SYS_gettid syscall for getting os thread 29 // id 30 #define __kmp_gettid() syscall(SYS_gettid) 31 #else 32 #warning No gettid found, use getpid instead 33 #define __kmp_gettid() getpid() 34 #endif 35 36 #elif KMP_OS_WINDOWS 37 38 // On Windows* OS _getpid() returns int (not pid_t) and is declared in 39 // "process.h". 40 #include <process.h> 41 // Let us simulate Unix. 42 typedef int pid_t; 43 #define getpid _getpid 44 #define __kmp_gettid() GetCurrentThreadId() 45 46 #else 47 48 #error Unknown or unsupported OS. 49 50 #endif 51 52 /* TODO: All the libomp source code uses pid_t type for storing the result of 53 getpid(), it is good. But often it printed as "%d", that is not good, because 54 it ignores pid_t definition (may pid_t be longer that int?). It seems all pid 55 prints should be rewritten as: 56 57 printf( "%" KMP_UINT64_SPEC, (kmp_uint64) pid ); 58 59 or (at least) as 60 61 printf( "%" KMP_UINT32_SPEC, (kmp_uint32) pid ); 62 63 (kmp_uint32, kmp_uint64, KMP_UINT64_SPEC, and KMP_UNIT32_SPEC are defined in 64 "kmp_os.h".) */ 65 66 #endif // KMP_WRAPPER_GETPID_H 67 68 // end of file // 69