LLVM OpenMP* Runtime Library
Main Page
Modules
Classes
All
Classes
Functions
Variables
Typedefs
Enumerations
Enumerator
Modules
Pages
src
kmp_wrapper_getpid.h
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-exception
10
//
11
//===----------------------------------------------------------------------===//
12
13
#ifndef KMP_WRAPPER_GETPID_H
14
#define KMP_WRAPPER_GETPID_H
15
16
#if KMP_OS_UNIX
17
18
// On Unix-like systems (Linux* OS and OS X*) getpid() is declared in standard
19
// headers.
20
#include <sys/syscall.h>
21
#include <sys/types.h>
22
#include <unistd.h>
23
#if KMP_OS_DARWIN
24
// OS X
25
#define __kmp_gettid() syscall(SYS_thread_selfid)
26
#elif KMP_OS_NETBSD
27
#include <lwp.h>
28
#define __kmp_gettid() _lwp_self()
29
#elif defined(SYS_gettid)
30
// Hopefully other Unix systems define SYS_gettid syscall for getting os thread
31
// id
32
#define __kmp_gettid() syscall(SYS_gettid)
33
#else
34
#warning No gettid found, use getpid instead
35
#define __kmp_gettid() getpid()
36
#endif
37
38
#elif KMP_OS_WINDOWS
39
40
// On Windows* OS _getpid() returns int (not pid_t) and is declared in
41
// "process.h".
42
#include <process.h>
43
// Let us simulate Unix.
44
#if KMP_MSVC_COMPAT
45
typedef
int
pid_t;
46
#endif
47
#define getpid _getpid
48
#define __kmp_gettid() GetCurrentThreadId()
49
50
#else
51
52
#error Unknown or unsupported OS.
53
54
#endif
55
56
/* TODO: All the libomp source code uses pid_t type for storing the result of
57
getpid(), it is good. But often it printed as "%d", that is not good, because
58
it ignores pid_t definition (may pid_t be longer that int?). It seems all pid
59
prints should be rewritten as:
60
61
printf( "%" KMP_UINT64_SPEC, (kmp_uint64) pid );
62
63
or (at least) as
64
65
printf( "%" KMP_UINT32_SPEC, (kmp_uint32) pid );
66
67
(kmp_uint32, kmp_uint64, KMP_UINT64_SPEC, and KMP_UNIT32_SPEC are defined in
68
"kmp_os.h".) */
69
70
#endif // KMP_WRAPPER_GETPID_H
71
72
// end of file //
Generated by
1.8.8