LLVM OpenMP* Runtime Library
src
kmp_wrapper_getpid.h
1
/*
2
* kmp_wrapper_getpid.h -- getpid() declaration.
3
*/
4
5
6
//===----------------------------------------------------------------------===//
7
//
8
// The LLVM Compiler Infrastructure
9
//
10
// This file is dual licensed under the MIT and the University of Illinois Open
11
// Source Licenses. See LICENSE.txt for details.
12
//
13
//===----------------------------------------------------------------------===//
14
15
16
#ifndef KMP_WRAPPER_GETPID_H
17
#define KMP_WRAPPER_GETPID_H
18
19
#if KMP_OS_UNIX
20
21
// On Unix-like systems (Linux* OS and OS X*) getpid() is declared in standard
22
// headers.
23
#include <sys/syscall.h>
24
#include <sys/types.h>
25
#include <unistd.h>
26
#if KMP_OS_DARWIN
27
// OS X
28
#define __kmp_gettid() syscall(SYS_thread_selfid)
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
typedef
int
pid_t;
45
#define getpid _getpid
46
#define __kmp_gettid() GetCurrentThreadId()
47
48
#else
49
50
#error Unknown or unsupported OS.
51
52
#endif
53
54
/* TODO: All the libomp source code uses pid_t type for storing the result of
55
getpid(), it is good. But often it printed as "%d", that is not good, because
56
it ignores pid_t definition (may pid_t be longer that int?). It seems all pid
57
prints should be rewritten as:
58
59
printf( "%" KMP_UINT64_SPEC, (kmp_uint64) pid );
60
61
or (at least) as
62
63
printf( "%" KMP_UINT32_SPEC, (kmp_uint32) pid );
64
65
(kmp_uint32, kmp_uint64, KMP_UINT64_SPEC, and KMP_UNIT32_SPEC are defined in
66
"kmp_os.h".) */
67
68
#endif // KMP_WRAPPER_GETPID_H
69
70
// end of file //
Generated by
1.8.13