guile-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Guile-commits] GNU Guile branch, stable-2.0, updated. v2.0.0-211-gd0476


From: Ludovic Courtès
Subject: [Guile-commits] GNU Guile branch, stable-2.0, updated. v2.0.0-211-gd0476fa
Date: Mon, 25 Apr 2011 20:56:52 +0000

This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "GNU Guile".

http://git.savannah.gnu.org/cgit/guile.git/commit/?id=d0476fa2b061638879fed89cd8d79add6f586448

The branch, stable-2.0 has been updated
       via  d0476fa2b061638879fed89cd8d79add6f586448 (commit)
       via  d20912e67d810ce5eb9dc1b8f8afd8c22aa2451b (commit)
       via  bbec4602457ed3e139e9dae99b4b495a3bc5eb71 (commit)
      from  4a235623391dd0d3d46f87dcf00d152e1787c191 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit d0476fa2b061638879fed89cd8d79add6f586448
Author: Ludovic Courtès <address@hidden>
Date:   Mon Apr 25 22:52:00 2011 +0200

    Compile more file system related procedures when `--disable-posix'.
    
    * libguile/filesys.c (scm_tc16_dir, scm_directory_stream_p, scm_opendir,
      scm_readdir, scm_rewinddir, scm_closedir, scm_dir_print,
      scm_dir_free, scm_lstat): Compile unconditionally.

commit d20912e67d810ce5eb9dc1b8f8afd8c22aa2451b
Author: Ludovic Courtès <address@hidden>
Date:   Mon Apr 25 22:41:58 2011 +0200

    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.

commit bbec4602457ed3e139e9dae99b4b495a3bc5eb71
Author: Ludovic Courtès <address@hidden>
Date:   Mon Apr 25 22:36:30 2011 +0200

    Make the `sizeof (mpz_t)' check at compile-time.
    
    * libguile/init.c (scm_i_init_guile): Remove the `sizeof (mpz_t)'
      run-time check.
    
    * libguile/numbers.c: Add a compile-time check for `sizeof (mpz_t)'.

-----------------------------------------------------------------------

Summary of changes:
 libguile/filesys.c            |  402 ++++++++++++++++++++---------------------
 libguile/init.c               |    7 -
 libguile/numbers.c            |    5 +
 libguile/posix.c              |   31 ---
 libguile/posix.h              |    5 +-
 libguile/threads.c            |   34 ++++
 libguile/threads.h            |    3 +
 test-suite/tests/posix.test   |   13 --
 test-suite/tests/threads.test |   14 ++
 9 files changed, 258 insertions(+), 256 deletions(-)

diff --git a/libguile/filesys.c b/libguile/filesys.c
index fab8ab4..b43536f 100644
--- a/libguile/filesys.c
+++ b/libguile/filesys.c
@@ -602,6 +602,31 @@ SCM_DEFINE (scm_stat, "stat", 1, 1, 0,
 }
 #undef FUNC_NAME
 
+#ifdef HAVE_LSTAT
+SCM_DEFINE (scm_lstat, "lstat", 1, 0, 0, 
+            (SCM str),
+           "Similar to @code{stat}, but does not follow symbolic links, 
i.e.,\n"
+           "it will return information about a symbolic link itself, not the\n"
+           "file it points to.  @var{path} must be a string.")
+#define FUNC_NAME s_scm_lstat
+{
+  int rv;
+  struct stat_or_stat64 stat_temp;
+
+  STRING_SYSCALL (str, c_str, rv = lstat_or_lstat64 (c_str, &stat_temp));
+  if (rv != 0)
+    {
+      int en = errno;
+
+      SCM_SYSERROR_MSG ("~A: ~S",
+                       scm_list_2 (scm_strerror (scm_from_int (en)), str),
+                       en);
+    }
+  return scm_stat2scm (&stat_temp);
+}
+#undef FUNC_NAME
+#endif /* HAVE_LSTAT */
+
 
 #ifdef HAVE_POSIX
 
@@ -630,183 +655,6 @@ SCM_DEFINE (scm_link, "link", 2, 0, 0,
 #endif /* HAVE_LINK */
 
 
-
-/* {Examining Directories}
- */
-
-scm_t_bits scm_tc16_dir;
-
-
-SCM_DEFINE (scm_directory_stream_p, "directory-stream?", 1, 0, 0, 
-            (SCM obj),
-           "Return a boolean indicating whether @var{object} is a directory\n"
-           "stream as returned by @code{opendir}.")
-#define FUNC_NAME s_scm_directory_stream_p
-{
-  return scm_from_bool (SCM_DIRP (obj));
-}
-#undef FUNC_NAME
-
-
-SCM_DEFINE (scm_opendir, "opendir", 1, 0, 0, 
-            (SCM dirname),
-           "Open the directory specified by @var{path} and return a 
directory\n"
-           "stream.")
-#define FUNC_NAME s_scm_opendir
-{
-  DIR *ds;
-  STRING_SYSCALL (dirname, c_dirname, ds = opendir (c_dirname));
-  if (ds == NULL)
-    SCM_SYSERROR;
-  SCM_RETURN_NEWSMOB (scm_tc16_dir | (SCM_DIR_FLAG_OPEN<<16), ds);
-}
-#undef FUNC_NAME
-
-
-/* FIXME: The glibc manual has a portability note that readdir_r may not
-   null-terminate its return string.  The circumstances outlined for this
-   are not clear, nor is it clear what should be done about it.  Lets use
-   NAMLEN and worry about what else should be done if/when someone can
-   figure it out.  */
-
-SCM_DEFINE (scm_readdir, "readdir", 1, 0, 0, 
-            (SCM port),
-           "Return (as a string) the next directory entry from the directory 
stream\n"
-           "@var{stream}.  If there is no remaining entry to be read then 
the\n"
-           "end of file object is returned.")
-#define FUNC_NAME s_scm_readdir
-{
-  struct dirent_or_dirent64 *rdent;
-
-  SCM_VALIDATE_DIR (1, port);
-  if (!SCM_DIR_OPEN_P (port))
-    SCM_MISC_ERROR ("Directory ~S is not open.", scm_list_1 (port));
-
-#if HAVE_READDIR_R
-  /* As noted in the glibc manual, on various systems (such as Solaris) the
-     d_name[] field is only 1 char and you're expected to size the dirent
-     buffer for readdir_r based on NAME_MAX.  The SCM_MAX expressions below
-     effectively give either sizeof(d_name) or NAME_MAX+1, whichever is
-     bigger.
-
-     On solaris 10 there's no NAME_MAX constant, it's necessary to use
-     pathconf().  We prefer NAME_MAX though, since it should be a constant
-     and will therefore save a system call.  We also prefer it since dirfd()
-     is not available everywhere.
-
-     An alternative to dirfd() would be to open() the directory and then use
-     fdopendir(), if the latter is available.  That'd let us hold the fd
-     somewhere in the smob, or just the dirent size calculated once.  */
-  {
-    struct dirent_or_dirent64 de; /* just for sizeof */
-    DIR    *ds = (DIR *) SCM_SMOB_DATA_1 (port);
-#ifdef NAME_MAX
-    char   buf [SCM_MAX (sizeof (de),
-                         sizeof (de) - sizeof (de.d_name) + NAME_MAX + 1)];
-#else
-    char   *buf;
-    long   name_max = fpathconf (dirfd (ds), _PC_NAME_MAX);
-    if (name_max == -1)
-      SCM_SYSERROR;
-    buf = alloca (SCM_MAX (sizeof (de),
-                           sizeof (de) - sizeof (de.d_name) + name_max + 1));
-#endif
-
-    errno = 0;
-    SCM_SYSCALL (readdir_r_or_readdir64_r (ds, (struct dirent_or_dirent64 *) 
buf, &rdent));
-    if (errno != 0)
-      SCM_SYSERROR;
-    if (! rdent)
-      return SCM_EOF_VAL;
-
-    return (rdent ? scm_from_locale_stringn (rdent->d_name, NAMLEN (rdent))
-            : SCM_EOF_VAL);
-  }
-#else
-  {
-    SCM ret;
-    scm_dynwind_begin (0);
-    scm_i_dynwind_pthread_mutex_lock (&scm_i_misc_mutex);
-
-    errno = 0;
-    SCM_SYSCALL (rdent = readdir_or_readdir64 ((DIR *) SCM_SMOB_DATA_1 
(port)));
-    if (errno != 0)
-      SCM_SYSERROR;
-
-    ret = (rdent ? scm_from_locale_stringn (rdent->d_name, NAMLEN (rdent))
-           : SCM_EOF_VAL);
-
-    scm_dynwind_end ();
-    return ret;
-  }
-#endif
-}
-#undef FUNC_NAME
-
-
-SCM_DEFINE (scm_rewinddir, "rewinddir", 1, 0, 0, 
-            (SCM port),
-           "Reset the directory port @var{stream} so that the next call to\n"
-           "@code{readdir} will return the first directory entry.")
-#define FUNC_NAME s_scm_rewinddir
-{
-  SCM_VALIDATE_DIR (1, port);
-  if (!SCM_DIR_OPEN_P (port))
-    SCM_MISC_ERROR ("Directory ~S is not open.", scm_list_1 (port));
-
-  rewinddir ((DIR *) SCM_SMOB_DATA_1 (port));
-
-  return SCM_UNSPECIFIED;
-}
-#undef FUNC_NAME
-
-
-SCM_DEFINE (scm_closedir, "closedir", 1, 0, 0, 
-            (SCM port),
-           "Close the directory stream @var{stream}.\n"
-           "The return value is unspecified.")
-#define FUNC_NAME s_scm_closedir
-{
-  SCM_VALIDATE_DIR (1, port);
-
-  if (SCM_DIR_OPEN_P (port))
-    {
-      int sts;
-
-      SCM_SYSCALL (sts = closedir ((DIR *) SCM_SMOB_DATA_1 (port)));
-      if (sts != 0)
-       SCM_SYSERROR;
-
-      SCM_SET_SMOB_DATA_0 (port, scm_tc16_dir);
-    }
-
-  return SCM_UNSPECIFIED;
-}
-#undef FUNC_NAME
-
-
-static int 
-scm_dir_print (SCM exp, SCM port, scm_print_state *pstate SCM_UNUSED)
-{
-  scm_puts ("#<", port);
-  if (!SCM_DIR_OPEN_P (exp))
-    scm_puts ("closed: ", port);
-  scm_puts ("directory stream ", port);
-  scm_uintprint (SCM_SMOB_DATA_1 (exp), 16, port);
-  scm_putc ('>', port);
-  return 1;
-}
-
-
-static size_t 
-scm_dir_free (SCM p)
-{
-  if (SCM_DIR_OPEN_P (p))
-    closedir ((DIR *) SCM_SMOB_DATA_1 (p));
-  return 0;
-}
-
-
 /* {Navigating Directories}
  */
 
@@ -1250,31 +1098,6 @@ SCM_DEFINE (scm_readlink, "readlink", 1, 0, 0,
 #undef FUNC_NAME
 #endif /* HAVE_READLINK */
 
-#ifdef HAVE_LSTAT
-SCM_DEFINE (scm_lstat, "lstat", 1, 0, 0, 
-            (SCM str),
-           "Similar to @code{stat}, but does not follow symbolic links, 
i.e.,\n"
-           "it will return information about a symbolic link itself, not the\n"
-           "file it points to.  @var{path} must be a string.")
-#define FUNC_NAME s_scm_lstat
-{
-  int rv;
-  struct stat_or_stat64 stat_temp;
-
-  STRING_SYSCALL (str, c_str, rv = lstat_or_lstat64 (c_str, &stat_temp));
-  if (rv != 0)
-    {
-      int en = errno;
-
-      SCM_SYSERROR_MSG ("~A: ~S",
-                       scm_list_2 (scm_strerror (scm_from_int (en)), str),
-                       en);
-    }
-  return scm_stat2scm (&stat_temp);
-}
-#undef FUNC_NAME
-#endif /* HAVE_LSTAT */
-
 SCM_DEFINE (scm_copy_file, "copy-file", 2, 0, 0,
             (SCM oldfile, SCM newfile),
            "Copy the file specified by @var{path-from} to @var{path-to}.\n"
@@ -1814,6 +1637,181 @@ scm_i_relativize_path (SCM path, SCM in_path)
   return SCM_BOOL_F;
 }
 
+
+/* Examining directories.  These procedures are used by `check-guile'
+   and thus compiled unconditionally.  */
+
+scm_t_bits scm_tc16_dir;
+
+
+SCM_DEFINE (scm_directory_stream_p, "directory-stream?", 1, 0, 0,
+           (SCM obj),
+           "Return a boolean indicating whether @var{object} is a directory\n"
+           "stream as returned by @code{opendir}.")
+#define FUNC_NAME s_scm_directory_stream_p
+{
+  return scm_from_bool (SCM_DIRP (obj));
+}
+#undef FUNC_NAME
+
+
+SCM_DEFINE (scm_opendir, "opendir", 1, 0, 0,
+           (SCM dirname),
+           "Open the directory specified by @var{path} and return a 
directory\n"
+           "stream.")
+#define FUNC_NAME s_scm_opendir
+{
+  DIR *ds;
+  STRING_SYSCALL (dirname, c_dirname, ds = opendir (c_dirname));
+  if (ds == NULL)
+    SCM_SYSERROR;
+  SCM_RETURN_NEWSMOB (scm_tc16_dir | (SCM_DIR_FLAG_OPEN<<16), ds);
+}
+#undef FUNC_NAME
+
+
+/* FIXME: The glibc manual has a portability note that readdir_r may not
+   null-terminate its return string.  The circumstances outlined for this
+   are not clear, nor is it clear what should be done about it.  Lets use
+   NAMLEN and worry about what else should be done if/when someone can
+   figure it out.  */
+
+SCM_DEFINE (scm_readdir, "readdir", 1, 0, 0,
+           (SCM port),
+           "Return (as a string) the next directory entry from the directory 
stream\n"
+           "@var{stream}.  If there is no remaining entry to be read then 
the\n"
+           "end of file object is returned.")
+#define FUNC_NAME s_scm_readdir
+{
+  struct dirent_or_dirent64 *rdent;
+
+  SCM_VALIDATE_DIR (1, port);
+  if (!SCM_DIR_OPEN_P (port))
+    SCM_MISC_ERROR ("Directory ~S is not open.", scm_list_1 (port));
+
+#if HAVE_READDIR_R
+  /* As noted in the glibc manual, on various systems (such as Solaris) the
+     d_name[] field is only 1 char and you're expected to size the dirent
+     buffer for readdir_r based on NAME_MAX.  The SCM_MAX expressions below
+     effectively give either sizeof(d_name) or NAME_MAX+1, whichever is
+     bigger.
+
+     On solaris 10 there's no NAME_MAX constant, it's necessary to use
+     pathconf().  We prefer NAME_MAX though, since it should be a constant
+     and will therefore save a system call.  We also prefer it since dirfd()
+     is not available everywhere.
+
+     An alternative to dirfd() would be to open() the directory and then use
+     fdopendir(), if the latter is available.  That'd let us hold the fd
+     somewhere in the smob, or just the dirent size calculated once.  */
+  {
+    struct dirent_or_dirent64 de; /* just for sizeof */
+    DIR    *ds = (DIR *) SCM_SMOB_DATA_1 (port);
+#ifdef NAME_MAX
+    char   buf [SCM_MAX (sizeof (de),
+                        sizeof (de) - sizeof (de.d_name) + NAME_MAX + 1)];
+#else
+    char   *buf;
+    long   name_max = fpathconf (dirfd (ds), _PC_NAME_MAX);
+    if (name_max == -1)
+      SCM_SYSERROR;
+    buf = alloca (SCM_MAX (sizeof (de),
+                          sizeof (de) - sizeof (de.d_name) + name_max + 1));
+#endif
+
+    errno = 0;
+    SCM_SYSCALL (readdir_r_or_readdir64_r (ds, (struct dirent_or_dirent64 *) 
buf, &rdent));
+    if (errno != 0)
+      SCM_SYSERROR;
+    if (! rdent)
+      return SCM_EOF_VAL;
+
+    return (rdent ? scm_from_locale_stringn (rdent->d_name, NAMLEN (rdent))
+           : SCM_EOF_VAL);
+  }
+#else
+  {
+    SCM ret;
+    scm_dynwind_begin (0);
+    scm_i_dynwind_pthread_mutex_lock (&scm_i_misc_mutex);
+
+    errno = 0;
+    SCM_SYSCALL (rdent = readdir_or_readdir64 ((DIR *) SCM_SMOB_DATA_1 
(port)));
+    if (errno != 0)
+      SCM_SYSERROR;
+
+    ret = (rdent ? scm_from_locale_stringn (rdent->d_name, NAMLEN (rdent))
+          : SCM_EOF_VAL);
+
+    scm_dynwind_end ();
+    return ret;
+  }
+#endif
+}
+#undef FUNC_NAME
+
+
+SCM_DEFINE (scm_rewinddir, "rewinddir", 1, 0, 0,
+           (SCM port),
+           "Reset the directory port @var{stream} so that the next call to\n"
+           "@code{readdir} will return the first directory entry.")
+#define FUNC_NAME s_scm_rewinddir
+{
+  SCM_VALIDATE_DIR (1, port);
+  if (!SCM_DIR_OPEN_P (port))
+    SCM_MISC_ERROR ("Directory ~S is not open.", scm_list_1 (port));
+
+  rewinddir ((DIR *) SCM_SMOB_DATA_1 (port));
+
+  return SCM_UNSPECIFIED;
+}
+#undef FUNC_NAME
+
+
+SCM_DEFINE (scm_closedir, "closedir", 1, 0, 0,
+           (SCM port),
+           "Close the directory stream @var{stream}.\n"
+           "The return value is unspecified.")
+#define FUNC_NAME s_scm_closedir
+{
+  SCM_VALIDATE_DIR (1, port);
+
+  if (SCM_DIR_OPEN_P (port))
+    {
+      int sts;
+
+      SCM_SYSCALL (sts = closedir ((DIR *) SCM_SMOB_DATA_1 (port)));
+      if (sts != 0)
+       SCM_SYSERROR;
+
+      SCM_SET_SMOB_DATA_0 (port, scm_tc16_dir);
+    }
+
+  return SCM_UNSPECIFIED;
+}
+#undef FUNC_NAME
+
+
+static int
+scm_dir_print (SCM exp, SCM port, scm_print_state *pstate SCM_UNUSED)
+{
+  scm_puts ("#<", port);
+  if (!SCM_DIR_OPEN_P (exp))
+    scm_puts ("closed: ", port);
+  scm_puts ("directory stream ", port);
+  scm_uintprint (SCM_SMOB_DATA_1 (exp), 16, port);
+  scm_putc ('>', port);
+  return 1;
+}
+
+
+static size_t
+scm_dir_free (SCM p)
+{
+  if (SCM_DIR_OPEN_P (p))
+    closedir ((DIR *) SCM_SMOB_DATA_1 (p));
+  return 0;
+}
 
 
 
diff --git a/libguile/init.c b/libguile/init.c
index 8741846..94de5c9 100644
--- a/libguile/init.c
+++ b/libguile/init.c
@@ -381,13 +381,6 @@ scm_i_init_guile (void *base)
   if (scm_initialized_p)
     return;
 
-  if (sizeof (mpz_t) > (3 * sizeof (scm_t_bits)))
-    {
-      fprintf (stderr,
-               "GMP's mpz_t must fit into a double_cell,"
-               "but doesn't seem to here.\n");
-    }
-
   scm_storage_prehistory ();
   scm_threads_prehistory (base);  /* requires storage_prehistory */
   scm_weaks_prehistory ();        /* requires storage_prehistory */
diff --git a/libguile/numbers.c b/libguile/numbers.c
index 7475381..742f4d1 100644
--- a/libguile/numbers.c
+++ b/libguile/numbers.c
@@ -45,6 +45,8 @@
 #  include <config.h>
 #endif
 
+#include <verify.h>
+
 #include <math.h>
 #include <string.h>
 #include <unicase.h>
@@ -68,6 +70,9 @@
 
 #include "libguile/eq.h"
 
+/* GMP's `mpz_t' must fit into a double cell.  */
+verify (sizeof (mpz_t) <= (2 * sizeof (scm_t_bits)));
+
 /* values per glibc, if not already defined */
 #ifndef M_LOG10E
 #define M_LOG10E   0.43429448190325182765
diff --git a/libguile/posix.c b/libguile/posix.c
index bfcefae..15b38e7 100644
--- a/libguile/posix.c
+++ b/libguile/posix.c
@@ -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
-
 
 #if HAVE_GETPASS
 SCM_DEFINE (scm_getpass, "getpass", 1, 0, 0, 
diff --git a/libguile/posix.h b/libguile/posix.h
index e2e19dd..92f8b35 100644
--- a/libguile/posix.h
+++ b/libguile/posix.h
@@ -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;
diff --git a/libguile/threads.c b/libguile/threads.c
index 4de8193..f49696b 100644
--- a/libguile/threads.c
+++ b/libguile/threads.c
@@ -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
+
+
+
+
 static scm_i_pthread_cond_t wake_up_cond;
 static int threads_initialized_p = 0;
 
diff --git a/libguile/threads.h b/libguile/threads.h
index 9e44684..609262a 100644
--- a/libguile/threads.h
+++ b/libguile/threads.h
@@ -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 */
 
 /*
diff --git a/test-suite/tests/posix.test b/test-suite/tests/posix.test
index 79f3a92..9679042 100644
--- a/test-suite/tests/posix.test
+++ b/test-suite/tests/posix.test
@@ -198,16 +198,3 @@
           (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)))))
diff --git a/test-suite/tests/threads.test b/test-suite/tests/threads.test
index 1166247..db002f2 100644
--- a/test-suite/tests/threads.test
+++ b/test-suite/tests/threads.test
@@ -463,3 +463,17 @@
                   (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)))))


hooks/post-receive
-- 
GNU Guile



reply via email to

[Prev in Thread] Current Thread [Next in Thread]