mirror of
https://github.com/janet-lang/janet
synced 2025-01-13 00:50:26 +00:00
On linux, available CPUs is more useful information.
This commit is contained in:
parent
48289acee6
commit
8145f3b68d
@ -1,6 +1,9 @@
|
|||||||
# Changelog
|
# Changelog
|
||||||
All notable changes to this project will be documented in this file.
|
All notable changes to this project will be documented in this file.
|
||||||
|
|
||||||
|
## Unreleased - ???
|
||||||
|
- Added `os/cpu-count` to get the number of available processors on a machine
|
||||||
|
|
||||||
## 1.22.0 - 2022-05-09
|
## 1.22.0 - 2022-05-09
|
||||||
- Prohibit negative size argument to `table/new`.
|
- Prohibit negative size argument to `table/new`.
|
||||||
- Add `module/value`.
|
- Add `module/value`.
|
||||||
|
@ -36,6 +36,11 @@
|
|||||||
# endif
|
# endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/* Needed for sched.h for cpu count */
|
||||||
|
#ifdef __linux__
|
||||||
|
#define _GNU_SOURCE
|
||||||
|
#endif
|
||||||
|
|
||||||
#if defined(WIN32) || defined(_WIN32)
|
#if defined(WIN32) || defined(_WIN32)
|
||||||
#define WIN32_LEAN_AND_MEAN
|
#define WIN32_LEAN_AND_MEAN
|
||||||
#endif
|
#endif
|
||||||
|
@ -43,6 +43,10 @@
|
|||||||
#include <sys/sysctl.h>
|
#include <sys/sysctl.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef JANET_LINUX
|
||||||
|
#include <sched.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef JANET_WINDOWS
|
#ifdef JANET_WINDOWS
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
#include <direct.h>
|
#include <direct.h>
|
||||||
@ -218,7 +222,11 @@ JANET_CORE_FN(os_cpu_count,
|
|||||||
return janet_wrap_integer(info.dwNumberOfProcessors);
|
return janet_wrap_integer(info.dwNumberOfProcessors);
|
||||||
#elif defined(JANET_LINUX)
|
#elif defined(JANET_LINUX)
|
||||||
(void) dflt;
|
(void) dflt;
|
||||||
return janet_wrap_integer(sysconf(_SC_NPROCESSORS_ONLN));
|
cpu_set_t cs;
|
||||||
|
CPU_ZERO(&cs);
|
||||||
|
sched_getaffinity(0, sizeof(cs), &cs);
|
||||||
|
int count = CPU_COUNT(&cs);
|
||||||
|
return janet_wrap_integer(count);
|
||||||
#elif defined(JANET_BSD) && defined(HW_NCPUONLINE)
|
#elif defined(JANET_BSD) && defined(HW_NCPUONLINE)
|
||||||
(void) dflt;
|
(void) dflt;
|
||||||
const int name[2] = {CTL_HW, HW_NCPUONLINE};
|
const int name[2] = {CTL_HW, HW_NCPUONLINE};
|
||||||
|
Loading…
Reference in New Issue
Block a user