New modules nproc, pthread.
authorPaul Eggert <eggert@cs.ucla.edu>
Wed, 25 Mar 2009 20:01:24 +0000 (13:01 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Wed, 25 Mar 2009 20:01:24 +0000 (13:01 -0700)
* MODULES.html.sh: Add pthread, nproc.
* lib/nproc.c: New file.
* lib/nproc.h: New file.
* lib/pthread.in.h: New file.
* m4/pthread.m4: New file.
* modules/nproc: New file.
* modules/pthread: New file.

ChangeLog
MODULES.html.sh
lib/nproc.c [new file with mode: 0644]
lib/nproc.h [new file with mode: 0644]
lib/pthread.in.h [new file with mode: 0644]
m4/pthread.m4 [new file with mode: 0644]
modules/nproc [new file with mode: 0644]
modules/pthread [new file with mode: 0644]

index 1b9cc0c..1698422 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+2009-03-25  Paul Eggert  <eggert@cs.ucla.edu>
+
+       New modules nproc, pthread, contributed by Glen Lenker.
+
+       * MODULES.html.sh: Add pthread, nproc.
+       * lib/nproc.c: New file.
+       * lib/nproc.h: New file.
+       * lib/pthread.in.h: New file.
+       * m4/pthread.m4: New file.
+       * modules/nproc: New file.
+       * modules/pthread: New file.
+
 2009-03-24  Simon Josefsson  <simon@josefsson.org>
 
        * modules/unicase/locale-language-tests (test_locale_language_LDADD):
index 6145234..a5efaeb 100755 (executable)
@@ -1,6 +1,6 @@
 #!/bin/sh
 #
-# Copyright (C) 2002-2008 Free Software Foundation, Inc.
+# Copyright (C) 2002-2009 Free Software Foundation, Inc.
 #
 # This program is free software: you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -2301,6 +2301,7 @@ func_all_modules ()
   func_module posix_spawn-internal
   func_module posix_spawnp
   func_module printf-posix
+  func_module pthread
   func_module readlink
   func_module realloc-posix
   func_module recv
@@ -3101,6 +3102,7 @@ func_all_modules ()
   func_module getloadavg
   func_module getpagesize
   func_module getusershell
+  func_module nproc
   func_module physmem
   func_module posixver
   func_module progname
diff --git a/lib/nproc.c b/lib/nproc.c
new file mode 100644 (file)
index 0000000..9a6e23a
--- /dev/null
@@ -0,0 +1,38 @@
+/* Detect the number of processors.
+
+   Copyright (C) 2009 Free Software Foundation, Inc.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 2, or (at your option)
+   any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software Foundation,
+   Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
+
+/* Written by Glen Lenker.  */
+
+#include <config.h>
+#include "nproc.h"
+
+#include <unistd.h>
+
+/* Return the total number of processors.  The result is guaranteed to
+   be at least 1.  */
+unsigned long int
+num_processors (void)
+{
+#ifdef _SC_NPROCESSORS_ONLN
+  long int nprocs = sysconf (_SC_NPROCESSORS_ONLN);
+  if (0 < nprocs)
+    return nprocs;
+#endif
+
+  return 1;
+}
diff --git a/lib/nproc.h b/lib/nproc.h
new file mode 100644 (file)
index 0000000..fe5b57e
--- /dev/null
@@ -0,0 +1,21 @@
+/* Detect the number of processors.
+
+   Copyright (C) 2009 Free Software Foundation, Inc.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 2, or (at your option)
+   any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software Foundation,
+   Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
+
+/* Written by Glen Lenker.  */
+
+unsigned long int num_processors (void);
diff --git a/lib/pthread.in.h b/lib/pthread.in.h
new file mode 100644 (file)
index 0000000..ae91ed2
--- /dev/null
@@ -0,0 +1,46 @@
+/* Implement a trivial subset of the pthreads library.
+
+   Copyright (C) 2009 Free Software Foundation, Inc.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 2, or (at your option)
+   any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software Foundation,
+   Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
+
+/* Written by Glen Lenker.  */
+
+#ifndef PTHREAD_H_
+# define PTHREAD_H_
+
+# include <errno.h>
+# include <stdlib.h>
+
+typedef int pthread_t;
+typedef int pthread_attr_t;
+
+static int
+pthread_create (pthread_t *restrict thread,
+               const pthread_attr_t *restrict attr,
+               void *(*start_routine)(void*), void *restrict arg)
+{
+  errno = EAGAIN;
+  return -1;
+}
+
+static int
+pthread_join (pthread_t thread, void **value_ptr)
+{
+  abort ();
+  return -1;
+}
+
+#endif /* PTHREAD_H_ */
diff --git a/m4/pthread.m4 b/m4/pthread.m4
new file mode 100644 (file)
index 0000000..2a38307
--- /dev/null
@@ -0,0 +1,27 @@
+# pthread.m4
+dnl Copyright (C) 2009 Free Software Foundation, Inc.
+dnl This file is free software; the Free Software Foundation
+dnl gives unlimited permission to copy and/or distribute it,
+dnl with or without modifications, as long as this notice is preserved.
+
+AC_DEFUN([gl_PTHREAD_CHECK],
+  [AC_CHECK_HEADERS_ONCE([pthread.h])
+
+   LIB_PTHREAD=
+   PTHREAD_H=
+   if test "$ac_cv_header_pthread_h" = yes; then
+     gl_saved_libs=$LIBS
+     AC_SEARCH_LIBS([pthread_create], [pthread],
+       [if test "$ac_cv_search_pthread_create" != "none required"; then
+         LIB_PTHREAD="$ac_cv_search_pthread_create"
+       fi])
+     LIBS="$gl_saved_libs"
+   else
+     PTHREAD_H='pthread.h'
+   fi
+
+   AC_SUBST([LIB_PTHREAD])
+   AC_SUBST([PTHREAD_H])
+
+   AC_REQUIRE([AC_C_RESTRICT])
+])
diff --git a/modules/nproc b/modules/nproc
new file mode 100644 (file)
index 0000000..9a98615
--- /dev/null
@@ -0,0 +1,23 @@
+Description:
+Detect the number of processors
+
+Files:
+lib/nproc.h
+lib/nproc.c
+
+Depends-on:
+unistd
+
+configure.ac:
+AC_LIBOBJ([nproc])
+
+Makefile.am:
+
+Include:
+#include "nproc.h"
+
+License:
+GPL
+
+Maintainer:
+Glen Lenker and Paul Eggert
diff --git a/modules/pthread b/modules/pthread
new file mode 100644 (file)
index 0000000..b79af69
--- /dev/null
@@ -0,0 +1,29 @@
+Description:
+Implement a trivial subset of the pthreads library.
+
+Files:
+lib/pthread.in.h
+m4/pthread.m4
+
+Depends-on:
+
+configure.ac:
+gl_PTHREAD_CHECK
+
+Makefile.am:
+BUILT_SOURCES += $(PTHREAD_H)
+
+# We need the following in order to create <pthread.h> when the system
+# doesn't have one that works with the given compiler.
+pthread.h: pthread.in.h
+       ln -f pthread.in.h $@ || cp pthread.in.h $@
+MOSTLYCLEANFILES += pthread.h
+
+Include:
+#include <pthread.h>
+
+License:
+LGPLv2+
+
+Maintainer:
+Glen Lenker and Paul Eggert