You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

sysinfo.h 2.9 kB

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