changeset 11431:4a2a6b0eadea

New modules nproc, pthread. * 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.
author Paul Eggert <eggert@cs.ucla.edu>
date Wed, 25 Mar 2009 13:01:24 -0700
parents 960a5f2974d0
children 663f24a97f1f
files ChangeLog MODULES.html.sh lib/nproc.c lib/nproc.h lib/pthread.in.h m4/pthread.m4 modules/nproc modules/pthread
diffstat 8 files changed, 199 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- 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):
--- a/MODULES.html.sh
+++ b/MODULES.html.sh
@@ -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_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_module getloadavg
   func_module getpagesize
   func_module getusershell
+  func_module nproc
   func_module physmem
   func_module posixver
   func_module progname
new file mode 100644
--- /dev/null
+++ b/lib/nproc.c
@@ -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;
+}
new file mode 100644
--- /dev/null
+++ b/lib/nproc.h
@@ -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);
new file mode 100644
--- /dev/null
+++ b/lib/pthread.in.h
@@ -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_ */
new file mode 100644
--- /dev/null
+++ b/m4/pthread.m4
@@ -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])
+])
new file mode 100644
--- /dev/null
+++ b/modules/nproc
@@ -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
new file mode 100644
--- /dev/null
+++ b/modules/pthread
@@ -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