numcpus_solaris.go 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. // Copyright 2021 Tobias Klauser
  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. // http://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. //go:build solaris
  15. package numcpus
  16. import "golang.org/x/sys/unix"
  17. // taken from /usr/include/sys/unistd.h
  18. const (
  19. _SC_NPROCESSORS_CONF = 14
  20. _SC_NPROCESSORS_ONLN = 15
  21. _SC_NPROCESSORS_MAX = 516
  22. )
  23. func getConfigured() (int, error) {
  24. n, err := unix.Sysconf(_SC_NPROCESSORS_CONF)
  25. return int(n), err
  26. }
  27. func getKernelMax() (int, error) {
  28. n, err := unix.Sysconf(_SC_NPROCESSORS_MAX)
  29. return int(n), err
  30. }
  31. func getOffline() (int, error) {
  32. return 0, ErrNotSupported
  33. }
  34. func getOnline() (int, error) {
  35. n, err := unix.Sysconf(_SC_NPROCESSORS_ONLN)
  36. return int(n), err
  37. }
  38. func getPossible() (int, error) {
  39. n, err := unix.Sysconf(_SC_NPROCESSORS_CONF)
  40. return int(n), err
  41. }
  42. func getPresent() (int, error) {
  43. n, err := unix.Sysconf(_SC_NPROCESSORS_CONF)
  44. return int(n), err
  45. }