From d20912e67d810ce5eb9dc1b8f8afd8c22aa2451b Mon Sep 17 00:00:00 2001 From: Ludovic Courtès Date: Mon, 25 Apr 2011 22:41:58 +0200 Subject: Move `{total,current}-processor-count' outside of `posix.c'. * libguile/posix.c (scm_total_processor_count, scm_current_processor_count): Move to... * libguile/threads.c: ... here. * libguile/posix.h (scm_total_processor_count, scm_current_processor_count): Move declarations to... * libguile/threads.h: ... here. * test-suite/tests/posix.test ("nproc"): Move tests to... * test-suite/tests/threads.test: ... here. --- libguile/threads.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'libguile/threads.c') diff --git a/libguile/threads.c b/libguile/threads.c index 4de819395..f49696b1d 100644 --- a/libguile/threads.c +++ b/libguile/threads.c @@ -39,6 +39,7 @@ #endif #include +#include #include "libguile/validate.h" #include "libguile/root.h" @@ -2010,6 +2011,39 @@ scm_c_thread_exited_p (SCM thread) } #undef FUNC_NAME +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_current_processor_count +{ + return scm_from_ulong (num_processors (NPROC_CURRENT)); +} +#undef FUNC_NAME + + + + static scm_i_pthread_cond_t wake_up_cond; static int threads_initialized_p = 0; -- cgit v1.2.3