Move `{total,current}-processor-count' outside of `posix.c'.
authorLudovic Courtès <ludo@gnu.org>
Mon, 25 Apr 2011 20:41:58 +0000 (22:41 +0200)
committerLudovic Courtès <ludo@gnu.org>
Mon, 25 Apr 2011 20:41:58 +0000 (22:41 +0200)
* 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/posix.c
libguile/posix.h
libguile/threads.c
libguile/threads.h
test-suite/tests/posix.test
test-suite/tests/threads.test

index bfcefaee3267dd69a1b9d3ffb243b35ac6b3e7a2..15b38e79ce56ea0db876c10165dd55132bf03b56 100644 (file)
@@ -142,7 +142,6 @@ 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... */
@@ -1895,36 +1894,6 @@ 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_current_processor_count
-{
-  return scm_from_ulong (num_processors (NPROC_CURRENT));
-}
-#undef FUNC_NAME
-
 \f
 #if HAVE_GETPASS
 SCM_DEFINE (scm_getpass, "getpass", 1, 0, 0, 
index e2e19ddd217f3fd13aceffa71eb5452f8e071239..92f8b35149a97984acc7bd350e1f2901da39545e 100644 (file)
@@ -3,7 +3,8 @@
 #ifndef SCM_POSIX_H
 #define SCM_POSIX_H
 
-/* Copyright (C) 1995,1996,1997,1998,2000,2001, 2003, 2006, 2008, 2009, 2010 Free Software Foundation, Inc.
+/* Copyright (C) 1995, 1996, 1997, 1998, 2000, 2001, 2003, 2006, 2008,
+ *   2009, 2010, 2011 Free Software Foundation, Inc.
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public License
@@ -91,8 +92,6 @@ SCM_API SCM scm_sethostname (SCM name);
 SCM_API SCM scm_gethostname (void);
 SCM_API SCM scm_getaffinity (SCM pid);
 SCM_API SCM scm_setaffinity (SCM pid, SCM cpu_set);
-SCM_API SCM scm_total_processor_count (void);
-SCM_API SCM scm_current_processor_count (void);
 SCM_INTERNAL void scm_init_posix (void);
 
 SCM_INTERNAL scm_i_pthread_mutex_t scm_i_locale_mutex;
index 4de8193956b0e4defa2728cbfdd8da75c3c5878d..f49696b1df0cb596b7531441c602496ec9e39bd5 100644 (file)
@@ -39,6 +39,7 @@
 #endif
 
 #include <assert.h>
+#include <nproc.h>
 
 #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
+
+
+\f
+
 static scm_i_pthread_cond_t wake_up_cond;
 static int threads_initialized_p = 0;
 
index 9e44684e115ce6ce262aee1bd888f55f0881635d..609262a1922664cb22a5130ca3da19fe4d964425 100644 (file)
@@ -230,6 +230,9 @@ SCM_API int scm_pthread_cond_timedwait (pthread_cond_t *cond,
 SCM_API unsigned int scm_std_sleep (unsigned int);
 SCM_API unsigned long scm_std_usleep (unsigned long);
 
+SCM_API SCM scm_total_processor_count (void);
+SCM_API SCM scm_current_processor_count (void);
+
 #endif  /* SCM_THREADS_H */
 
 /*
index 79f3a92ae4f205795dacf368ffb728028d88a73e..9679042a65814be5bf6b89455348d349a6e220dd 100644 (file)
           (setaffinity (getpid) mask)
           (equal? mask (getaffinity (getpid))))
         (throw 'unresolved))))
-
-;;
-;; nproc
-;;
-
-(with-test-prefix "nproc"
-
-  (pass-if "total-processor-count"
-    (>= (total-processor-count) 1))
-
-  (pass-if "current-processor-count"
-    (and (>= (current-processor-count) 1)
-         (>= (total-processor-count) (current-processor-count)))))
index 1166247c49b5e7ada00fb257331c87dc5f0a6fa6..db002f245fc557cb4032d5c8ea5d703322ed56c4 100644 (file)
                   (lambda () (lock-mutex m))
                   (lambda key (set! success #t)))
            success)))))
+
+
+;;
+;; nproc
+;;
+
+(with-test-prefix "nproc"
+
+  (pass-if "total-processor-count"
+    (>= (total-processor-count) 1))
+
+  (pass-if "current-processor-count"
+    (and (>= (current-processor-count) 1)
+         (>= (total-processor-count) (current-processor-count)))))