xref: /aosp_15_r20/external/abseil-cpp/absl/base/internal/sysinfo.h (revision 9356374a3709195abf420251b3e825997ff56c0f)
1*9356374aSAndroid Build Coastguard Worker // Copyright 2017 The Abseil Authors.
2*9356374aSAndroid Build Coastguard Worker //
3*9356374aSAndroid Build Coastguard Worker // Licensed under the Apache License, Version 2.0 (the "License");
4*9356374aSAndroid Build Coastguard Worker // you may not use this file except in compliance with the License.
5*9356374aSAndroid Build Coastguard Worker // You may obtain a copy of the License at
6*9356374aSAndroid Build Coastguard Worker //
7*9356374aSAndroid Build Coastguard Worker //      https://www.apache.org/licenses/LICENSE-2.0
8*9356374aSAndroid Build Coastguard Worker //
9*9356374aSAndroid Build Coastguard Worker // Unless required by applicable law or agreed to in writing, software
10*9356374aSAndroid Build Coastguard Worker // distributed under the License is distributed on an "AS IS" BASIS,
11*9356374aSAndroid Build Coastguard Worker // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12*9356374aSAndroid Build Coastguard Worker // See the License for the specific language governing permissions and
13*9356374aSAndroid Build Coastguard Worker // limitations under the License.
14*9356374aSAndroid Build Coastguard Worker //
15*9356374aSAndroid Build Coastguard Worker // This file includes routines to find out characteristics
16*9356374aSAndroid Build Coastguard Worker // of the machine a program is running on.  It is undoubtedly
17*9356374aSAndroid Build Coastguard Worker // system-dependent.
18*9356374aSAndroid Build Coastguard Worker 
19*9356374aSAndroid Build Coastguard Worker // Functions listed here that accept a pid_t as an argument act on the
20*9356374aSAndroid Build Coastguard Worker // current process if the pid_t argument is 0
21*9356374aSAndroid Build Coastguard Worker // All functions here are thread-hostile due to file caching unless
22*9356374aSAndroid Build Coastguard Worker // commented otherwise.
23*9356374aSAndroid Build Coastguard Worker 
24*9356374aSAndroid Build Coastguard Worker #ifndef ABSL_BASE_INTERNAL_SYSINFO_H_
25*9356374aSAndroid Build Coastguard Worker #define ABSL_BASE_INTERNAL_SYSINFO_H_
26*9356374aSAndroid Build Coastguard Worker 
27*9356374aSAndroid Build Coastguard Worker #ifndef _WIN32
28*9356374aSAndroid Build Coastguard Worker #include <sys/types.h>
29*9356374aSAndroid Build Coastguard Worker #endif
30*9356374aSAndroid Build Coastguard Worker 
31*9356374aSAndroid Build Coastguard Worker #include <cstdint>
32*9356374aSAndroid Build Coastguard Worker 
33*9356374aSAndroid Build Coastguard Worker #include "absl/base/config.h"
34*9356374aSAndroid Build Coastguard Worker #include "absl/base/port.h"
35*9356374aSAndroid Build Coastguard Worker 
36*9356374aSAndroid Build Coastguard Worker namespace absl {
37*9356374aSAndroid Build Coastguard Worker ABSL_NAMESPACE_BEGIN
38*9356374aSAndroid Build Coastguard Worker namespace base_internal {
39*9356374aSAndroid Build Coastguard Worker 
40*9356374aSAndroid Build Coastguard Worker // Nominal core processor cycles per second of each processor.   This is _not_
41*9356374aSAndroid Build Coastguard Worker // necessarily the frequency of the CycleClock counter (see cycleclock.h)
42*9356374aSAndroid Build Coastguard Worker // Thread-safe.
43*9356374aSAndroid Build Coastguard Worker double NominalCPUFrequency();
44*9356374aSAndroid Build Coastguard Worker 
45*9356374aSAndroid Build Coastguard Worker // Number of logical processors (hyperthreads) in system. Thread-safe.
46*9356374aSAndroid Build Coastguard Worker int NumCPUs();
47*9356374aSAndroid Build Coastguard Worker 
48*9356374aSAndroid Build Coastguard Worker // Return the thread id of the current thread, as told by the system.
49*9356374aSAndroid Build Coastguard Worker // No two currently-live threads implemented by the OS shall have the same ID.
50*9356374aSAndroid Build Coastguard Worker // Thread ids of exited threads may be reused.   Multiple user-level threads
51*9356374aSAndroid Build Coastguard Worker // may have the same thread ID if multiplexed on the same OS thread.
52*9356374aSAndroid Build Coastguard Worker //
53*9356374aSAndroid Build Coastguard Worker // On Linux, you may send a signal to the resulting ID with kill().  However,
54*9356374aSAndroid Build Coastguard Worker // it is recommended for portability that you use pthread_kill() instead.
55*9356374aSAndroid Build Coastguard Worker #ifdef _WIN32
56*9356374aSAndroid Build Coastguard Worker // On Windows, process id and thread id are of the same type according to the
57*9356374aSAndroid Build Coastguard Worker // return types of GetProcessId() and GetThreadId() are both DWORD, an unsigned
58*9356374aSAndroid Build Coastguard Worker // 32-bit type.
59*9356374aSAndroid Build Coastguard Worker using pid_t = uint32_t;
60*9356374aSAndroid Build Coastguard Worker #endif
61*9356374aSAndroid Build Coastguard Worker pid_t GetTID();
62*9356374aSAndroid Build Coastguard Worker 
63*9356374aSAndroid Build Coastguard Worker // Like GetTID(), but caches the result in thread-local storage in order
64*9356374aSAndroid Build Coastguard Worker // to avoid unnecessary system calls. Note that there are some cases where
65*9356374aSAndroid Build Coastguard Worker // one must call through to GetTID directly, which is why this exists as a
66*9356374aSAndroid Build Coastguard Worker // separate function. For example, GetCachedTID() is not safe to call in
67*9356374aSAndroid Build Coastguard Worker // an asynchronous signal-handling context nor right after a call to fork().
68*9356374aSAndroid Build Coastguard Worker pid_t GetCachedTID();
69*9356374aSAndroid Build Coastguard Worker 
70*9356374aSAndroid Build Coastguard Worker }  // namespace base_internal
71*9356374aSAndroid Build Coastguard Worker ABSL_NAMESPACE_END
72*9356374aSAndroid Build Coastguard Worker }  // namespace absl
73*9356374aSAndroid Build Coastguard Worker 
74*9356374aSAndroid Build Coastguard Worker #endif  // ABSL_BASE_INTERNAL_SYSINFO_H_
75