THIS IS A TEST INSTANCE ONLY! REPOSITORIES CAN BE DELETED AT ANY TIME!

Git Source Code Mirror - This is a publish-only repository and all pull requests are ignored. Please follow Documentation/SubmittingPatches procedure for any of your improvements.
git
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

126 lines
2.6KB

  1. #include "cache.h"
  2. #include "thread-utils.h"
  3. #if defined(hpux) || defined(__hpux) || defined(_hpux)
  4. # include <sys/pstat.h>
  5. #endif
  6. /*
  7. * By doing this in two steps we can at least get
  8. * the function to be somewhat coherent, even
  9. * with this disgusting nest of #ifdefs.
  10. */
  11. #ifndef _SC_NPROCESSORS_ONLN
  12. # ifdef _SC_NPROC_ONLN
  13. # define _SC_NPROCESSORS_ONLN _SC_NPROC_ONLN
  14. # elif defined _SC_CRAY_NCPU
  15. # define _SC_NPROCESSORS_ONLN _SC_CRAY_NCPU
  16. # endif
  17. #endif
  18. int online_cpus(void)
  19. {
  20. #ifdef NO_PTHREADS
  21. return 1;
  22. #else
  23. #ifdef _SC_NPROCESSORS_ONLN
  24. long ncpus;
  25. #endif
  26. #ifdef GIT_WINDOWS_NATIVE
  27. SYSTEM_INFO info;
  28. GetSystemInfo(&info);
  29. if ((int)info.dwNumberOfProcessors > 0)
  30. return (int)info.dwNumberOfProcessors;
  31. #elif defined(hpux) || defined(__hpux) || defined(_hpux)
  32. struct pst_dynamic psd;
  33. if (!pstat_getdynamic(&psd, sizeof(psd), (size_t)1, 0))
  34. return (int)psd.psd_proc_cnt;
  35. #elif defined(HAVE_BSD_SYSCTL) && defined(HW_NCPU)
  36. int mib[2];
  37. size_t len;
  38. int cpucount;
  39. mib[0] = CTL_HW;
  40. # ifdef HW_AVAILCPU
  41. mib[1] = HW_AVAILCPU;
  42. len = sizeof(cpucount);
  43. if (!sysctl(mib, 2, &cpucount, &len, NULL, 0))
  44. return cpucount;
  45. # endif /* HW_AVAILCPU */
  46. mib[1] = HW_NCPU;
  47. len = sizeof(cpucount);
  48. if (!sysctl(mib, 2, &cpucount, &len, NULL, 0))
  49. return cpucount;
  50. #endif /* defined(HAVE_BSD_SYSCTL) && defined(HW_NCPU) */
  51. #ifdef _SC_NPROCESSORS_ONLN
  52. if ((ncpus = (long)sysconf(_SC_NPROCESSORS_ONLN)) > 0)
  53. return (int)ncpus;
  54. #endif
  55. return 1;
  56. #endif
  57. }
  58. int init_recursive_mutex(pthread_mutex_t *m)
  59. {
  60. #ifndef NO_PTHREADS
  61. pthread_mutexattr_t a;
  62. int ret;
  63. ret = pthread_mutexattr_init(&a);
  64. if (!ret) {
  65. ret = pthread_mutexattr_settype(&a, PTHREAD_MUTEX_RECURSIVE);
  66. if (!ret)
  67. ret = pthread_mutex_init(m, &a);
  68. pthread_mutexattr_destroy(&a);
  69. }
  70. return ret;
  71. #else
  72. return 0;
  73. #endif
  74. }
  75. #ifdef NO_PTHREADS
  76. int dummy_pthread_create(pthread_t *pthread, const void *attr,
  77. void *(*fn)(void *), void *data)
  78. {
  79. /*
  80. * Do nothing.
  81. *
  82. * The main purpose of this function is to break compiler's
  83. * flow analysis and avoid -Wunused-variable false warnings.
  84. */
  85. return ENOSYS;
  86. }
  87. int dummy_pthread_init(void *data)
  88. {
  89. /*
  90. * Do nothing.
  91. *
  92. * The main purpose of this function is to break compiler's
  93. * flow analysis or it may realize that functions like
  94. * pthread_mutex_init() is no-op, which means the (static)
  95. * variable is not used/initialized at all and trigger
  96. * -Wunused-variable
  97. */
  98. return ENOSYS;
  99. }
  100. int dummy_pthread_join(pthread_t pthread, void **retval)
  101. {
  102. /*
  103. * Do nothing.
  104. *
  105. * The main purpose of this function is to break compiler's
  106. * flow analysis and avoid -Wunused-variable false warnings.
  107. */
  108. return ENOSYS;
  109. }
  110. #endif