summaryrefslogtreecommitdiff
path: root/libguile/posix.c
diff options
context:
space:
mode:
authorLudovic Courtès <ludo@gnu.org>2010-12-07 23:10:41 +0100
committerLudovic Courtès <ludo@gnu.org>2010-12-07 23:13:20 +0100
commitf0c0141fe4bd478edc8205b1eae793f0474d4aa3 (patch)
tree04c7f3bc6776d5ebdd0790dab9a92446647799f6 /libguile/posix.c
parent3ae78cac88d38b9ab913ee0100b00ad1151db306 (diff)
downloadguile-f0c0141fe4bd478edc8205b1eae793f0474d4aa3.tar.gz
Add `total-processor-count' and `current-processor-count'.
* libguile/posix.c (scm_total_processor_count, scm_current_processor_count): New functions. * libguile/posix.h (scm_total_processor_count, scm_current_processor_count): New declarations. * test-suite/tests/posix.test ("nproc"): New test prefix. * doc/ref/posix.texi (Processes): Document `total-processor-count' and `current-processor-count'.
Diffstat (limited to 'libguile/posix.c')
-rw-r--r--libguile/posix.c32
1 files changed, 32 insertions, 0 deletions
diff --git a/libguile/posix.c b/libguile/posix.c
index 652f63d7d..95beb6e3e 100644
--- a/libguile/posix.c
+++ b/libguile/posix.c
@@ -138,6 +138,7 @@ extern char *ttyname();
#endif
#include <sys/file.h> /* from Gnulib */
+#include <nproc.h>
/* Some Unix systems don't define these. CPP hair is dangerous, but
this seems safe enough... */
@@ -1990,6 +1991,37 @@ SCM_DEFINE (scm_setaffinity, "setaffinity", 2, 0, 0,
#endif /* HAVE_SCHED_SETAFFINITY */
+SCM_DEFINE (scm_total_processor_count, "total-processor-count", 0, 0, 0,
+ (void),
+ "Return the total number of processors of the machine, which\n"
+ "is guaranteed to be at least 1. A ``processor'' here is a\n"
+ "thread execution unit, which can be either:\n\n"
+ "@itemize\n"
+ "@item an execution core in a (possibly multi-core) chip, in a\n"
+ " (possibly multi- chip) module, in a single computer, or\n"
+ "@item a thread execution unit inside a core in the case of\n"
+ " @dfn{hyper-threaded} CPUs.\n"
+ "@end itemize\n\n"
+ "Which of the two definitions is used, is unspecified.\n")
+#define FUNC_NAME s_scm_total_processor_count
+{
+ return scm_from_ulong (num_processors (NPROC_ALL));
+}
+#undef FUNC_NAME
+
+SCM_DEFINE (scm_current_processor_count, "current-processor-count", 0, 0, 0,
+ (void),
+ "Like @code{total-processor-count}, but return the number of\n"
+ "processors available to the current process. See\n"
+ "@code{setaffinity} and @code{getaffinity} for more\n"
+ "information.\n")
+#define FUNC_NAME s_scm_total_processor_count
+{
+ return scm_from_ulong (num_processors (NPROC_CURRENT));
+}
+#undef FUNC_NAME
+
+
#if HAVE_GETPASS
SCM_DEFINE (scm_getpass, "getpass", 1, 0, 0,
(SCM prompt),