From 4cc93d2296593047de7a0c84455855832596bde9 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Wed, 25 Mar 2009 13:01:24 -0700 Subject: [PATCH] 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. --- ChangeLog | 12 ++++++++++++ MODULES.html.sh | 4 +++- lib/nproc.c | 38 ++++++++++++++++++++++++++++++++++++++ lib/nproc.h | 21 +++++++++++++++++++++ lib/pthread.in.h | 46 ++++++++++++++++++++++++++++++++++++++++++++++ m4/pthread.m4 | 27 +++++++++++++++++++++++++++ modules/nproc | 23 +++++++++++++++++++++++ modules/pthread | 29 +++++++++++++++++++++++++++++ 8 files changed, 199 insertions(+), 1 deletion(-) create mode 100644 lib/nproc.c create mode 100644 lib/nproc.h create mode 100644 lib/pthread.in.h create mode 100644 m4/pthread.m4 create mode 100644 modules/nproc create mode 100644 modules/pthread diff --git a/ChangeLog b/ChangeLog index 1b9cc0cde..169842273 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,15 @@ +2009-03-25 Paul Eggert + + 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 * modules/unicase/locale-language-tests (test_locale_language_LDADD): diff --git a/MODULES.html.sh b/MODULES.html.sh index 614523476..a5efaeb3b 100755 --- 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_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 index 000000000..9a6e23a44 --- /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 +#include "nproc.h" + +#include + +/* 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 index 000000000..fe5b57e95 --- /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); diff --git a/lib/pthread.in.h b/lib/pthread.in.h new file mode 100644 index 000000000..ae91ed2e2 --- /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 +# include + +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 index 000000000..2a383076b --- /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]) +]) diff --git a/modules/nproc b/modules/nproc new file mode 100644 index 000000000..9a9861513 --- /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 diff --git a/modules/pthread b/modules/pthread new file mode 100644 index 000000000..b79af69fb --- /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 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 + +License: +LGPLv2+ + +Maintainer: +Glen Lenker and Paul Eggert -- 2.11.0