86 lines · c
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-exception10//11//===----------------------------------------------------------------------===//12 13#ifndef KMP_WRAPPER_GETPID_H14#define KMP_WRAPPER_GETPID_H15 16#if KMP_OS_UNIX17 18// On Unix-like systems (Linux* OS and OS X*) getpid() is declared in standard19// headers.20#if !KMP_OS_AIX && !KMP_OS_HAIKU21#include <sys/syscall.h>22#endif23#include <sys/types.h>24#include <unistd.h>25#if KMP_OS_DARWIN26// OS X27#define __kmp_gettid() pthread_mach_thread_np(pthread_self())28#elif KMP_OS_FREEBSD || KMP_OS_DRAGONFLY29#include <pthread_np.h>30#define __kmp_gettid() pthread_getthreadid_np()31#elif KMP_OS_NETBSD32#include <lwp.h>33#define __kmp_gettid() _lwp_self()34#elif KMP_OS_OPENBSD35#define __kmp_gettid() getthrid()36#elif KMP_OS_AIX || KMP_OS_SOLARIS37#include <pthread.h>38#define __kmp_gettid() pthread_self()39#elif KMP_OS_HAIKU40#include <OS.h>41#define __kmp_gettid() find_thread(NULL)42#elif defined(SYS_gettid)43// Hopefully other Unix systems define SYS_gettid syscall for getting os thread44// id45#define __kmp_gettid() syscall(SYS_gettid)46#else47#warning No gettid found, use getpid instead48#define __kmp_gettid() getpid()49#endif50 51#elif KMP_OS_WINDOWS52 53// On Windows* OS _getpid() returns int (not pid_t) and is declared in54// "process.h".55#include <process.h>56// Let us simulate Unix.57#if KMP_MSVC_COMPAT58typedef int pid_t;59#endif60#define getpid _getpid61#define __kmp_gettid() GetCurrentThreadId()62 63#else64 65#error Unknown or unsupported OS.66 67#endif68 69/* TODO: All the libomp source code uses pid_t type for storing the result of70 getpid(), it is good. But often it printed as "%d", that is not good, because71 it ignores pid_t definition (may pid_t be longer that int?). It seems all pid72 prints should be rewritten as:73 74 printf( "%" KMP_UINT64_SPEC, (kmp_uint64) pid );75 76 or (at least) as77 78 printf( "%" KMP_UINT32_SPEC, (kmp_uint32) pid );79 80 (kmp_uint32, kmp_uint64, KMP_UINT64_SPEC, and KMP_UNIT32_SPEC are defined in81 "kmp_os.h".) */82 83#endif // KMP_WRAPPER_GETPID_H84 85// end of file //86