[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: checkin of glthread/glcond modules
From: |
Bruno Haible |
Subject: |
Re: checkin of glthread/glcond modules |
Date: |
Sun, 17 Aug 2008 19:29:42 +0200 |
User-agent: |
KMail/1.5.4 |
Yoann Vandoorselaere wrote:
> Here is an updated patch, that fixes several naming issue and implement
> the yield module.
Thanks. I added the 'thread' module, with a few modifications (attached):
- Changed the module description to say "Creating threads".
- Added some documentation of the 6 facilities.
- glthread_self or gl_thread_self? Since I find it more important that the
easy API (the one which calls abort()) be consistent, rather than the API
with control of error handling, I renamed glthread_self to gl_thread_self,
and likewise glthread_exit to gl_thread_exit.
- When pthread_self is defined as a macro, don't use #pragma weak on it.
(Taken from lock.h.)
- [POSIX] When glthread_create fails, return ENOSYS, not 0.
- [Pth] When pth_spawn fails, return errno, not -1. I checked the source code
of pth_spawn; it does set errno.
- [Pth] Fix syntax error in glthread_sigmask.
- Changed a few macro argument names for consistency and clarity.
- In thread.m4, use AC_CHECK_FUNCS not AC_CHECK_FUNC (because AC_CHECK_FUNC
does not define any HAVE_* macro).
Bruno
2008-08-17 Yoann Vandoorselaere <address@hidden>
New module 'thread'.
* modules/thread: New file.
* lib/glthread/thread.h: New file.
* m4/thread.m4: New file.
*** modules/thread 2008-08-17 17:11:17.000000000 +0200
--- /packages/GNULIB/gnulib-git/modules/thread 2008-08-17 18:00:33.000000000
+0200
***************
*** 1,12 ****
Description:
! Locking in multithreaded situations.
Files:
lib/glthread/thread.h
m4/thread.m4
Depends-on:
! lock
configure.ac:
gl_THREAD
--- 1,12 ----
Description:
! Creating and controlling threads.
Files:
lib/glthread/thread.h
m4/thread.m4
Depends-on:
! threadlib
configure.ac:
gl_THREAD
***************
*** 17,22 ****
--- 17,25 ----
Include:
"glthread/thread.h"
+ Link:
+ $(LTLIBTHREAD) when linking with libtool, $(LIBTHREAD) otherwise
+
License:
LGPLv2+
*** lib/glthread/thread.h 2008-08-17 17:11:16.000000000 +0200
--- /packages/GNULIB/gnulib-git/lib/glthread/thread.h 2008-08-17
19:14:08.000000000 +0200
***************
*** 1,4 ****
! /* Locking in multithreaded situations.
Copyright (C) 2005-2008 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
--- 1,4 ----
! /* Creating and controlling threads.
Copyright (C) 2005-2008 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
***************
*** 19,27 ****
Based on GCC's gthr-posix.h, gthr-posix95.h, gthr-solaris.h,
gthr-win32.h. */
! /* This file contains locking primitives for use with a given thread library.
! It does not contain primitives for creating threads or for other
! synchronization primitives.
*/
--- 19,67 ----
Based on GCC's gthr-posix.h, gthr-posix95.h, gthr-solaris.h,
gthr-win32.h. */
! /* This file contains primitives for creating and controlling threads.
!
! Thread data type: gl_thread_t.
!
! Creating a thread:
! gl_thread_create (thread, func, arg);
! Or with control of error handling:
! err = glthread_create (&thread, func, arg);
! extern int glthread_create (gl_thread_t *result,
! void *(*func) (void *), void *arg);
!
! Querying and changing the signal mask of a thread (not supported on all
! platforms):
! gl_thread_sigmask (how, newmask, oldmask);
! Or with control of error handling:
! err = glthread_sigmask (how, newmask, oldmask);
! extern int glthread_sigmask (int how, const sigset_t *newmask,
sigset_t *oldmask);
!
! Waiting for termination of another thread:
! gl_thread_join (thread, &return_value);
! Or with control of error handling:
! err = glthread_join (thread, &return_value);
! extern int glthread_join (gl_thread_t thread, void **return_value_ptr);
!
! Getting a reference to the current thread:
! current = gl_thread_self ();
! extern gl_thread_t gl_thread_self (void);
!
! Terminating the current thread:
! gl_thread_exit (return_value);
! extern void gl_thread_exit (void *return_value) __attribute__
((noreturn));
!
! Requesting custom code to be executed at fork() time(not supported on all
! platforms):
! gl_thread_atfork (prepare_func, parent_func, child_func);
! Or with control of error handling:
! err = glthread_atfork (prepare_func, parent_func, child_func);
! extern int glthread_atfork (void (*prepare_func) (void),
! void (*parent_func) (void),
! void (*child_func) (void));
! Note that even on platforms where this is supported, use of fork() and
! threads together is problematic, see
! <http://lists.gnu.org/archive/html/bug-gnulib/2008-08/msg00062.html>
*/
***************
*** 29,34 ****
--- 69,75 ----
#define _GLTHREAD_THREAD_H
#include <errno.h>
+ #include <stdlib.h>
/* =========================================================================
*/
***************
*** 37,43 ****
/* Use the POSIX threads library. */
# include <pthread.h>
- # include <stdlib.h>
# ifdef __cplusplus
extern "C" {
--- 78,83 ----
***************
*** 72,83 ****
address of a function in libpthread that we don't use. */
# pragma weak pthread_create
# pragma weak pthread_join
# pragma weak pthread_self
# pragma weak pthread_exit
! # pragma weak pthread_sigmask
!
! # ifdef HAVE_PTHREAD_ATFORK
# pragma weak pthread_atfork
# endif
--- 112,124 ----
address of a function in libpthread that we don't use. */
# pragma weak pthread_create
+ # pragma weak pthread_sigmask
# pragma weak pthread_join
+ # ifndef pthread_self
# pragma weak pthread_self
+ # endif
# pragma weak pthread_exit
! # if HAVE_PTHREAD_ATFORK
# pragma weak pthread_atfork
# endif
***************
*** 94,119 ****
# endif
-
/* -------------------------- gl_thread_t datatype --------------------------
*/
typedef pthread_t gl_thread_t;
! # define glthread_create(THREAD, FUNC, ARG) \
! (pthread_in_use () ? pthread_create (THREAD, NULL, FUNC, ARG) : 0)
# define glthread_sigmask(HOW, SET, OSET) \
(pthread_in_use () ? pthread_sigmask (HOW, SET, OSET) : 0)
! # define glthread_join(THREAD, VALPTR) \
! (pthread_in_use () ? pthread_join (THREAD, VALPTR) : 0)
! # define glthread_self() \
! (pthread_in_use () ? (void *) pthread_self () : 0)
! # define glthread_exit(VALPTR) \
! (pthread_in_use () ? pthread_exit (VALPTR) : 0)
!
! # ifdef HAVE_PTHREAD_ATFORK
! # define glthread_atfork(PREPARE, PARENT, CHILD) \
! (pthread_in_use () ? pthread_atfork (PREPARE, PARENT, CHILD) : 0)
# else
! # define glthread_atfork(PREPARE, PARENT, CHILD) 0
# endif
#endif
--- 135,159 ----
# endif
/* -------------------------- gl_thread_t datatype --------------------------
*/
typedef pthread_t gl_thread_t;
! # define glthread_create(THREADP, FUNC, ARG) \
! (pthread_in_use () ? pthread_create (THREADP, NULL, FUNC, ARG) : ENOSYS)
# define glthread_sigmask(HOW, SET, OSET) \
(pthread_in_use () ? pthread_sigmask (HOW, SET, OSET) : 0)
! # define glthread_join(THREAD, RETVALP) \
! (pthread_in_use () ? pthread_join (THREAD, RETVALP) : 0)
! # define gl_thread_self() \
! (pthread_in_use () ? (void *) pthread_self () : NULL)
! # define gl_thread_exit(RETVAL) \
! (pthread_in_use () ? pthread_exit (RETVAL) : 0)
!
! # if HAVE_PTHREAD_ATFORK
! # define glthread_atfork(PREPARE_FUNC, PARENT_FUNC, CHILD_FUNC) \
! (pthread_in_use () ? pthread_atfork (PREPARE_FUNC, PARENT_FUNC,
CHILD_FUNC) : 0)
# else
! # define glthread_atfork(PREPARE_FUNC, PARENT_FUNC, CHILD_FUNC) 0
# endif
#endif
***************
*** 125,131 ****
/* Use the GNU Pth threads library. */
# include <pth.h>
- # include <stdlib.h>
# ifdef __cplusplus
extern "C" {
--- 165,170 ----
***************
*** 140,145 ****
--- 179,185 ----
# pragma weak pth_join
# pragma weak pth_self
# pragma weak pth_exit
+
# pragma weak pth_cancel
# define pth_in_use() (pth_cancel != NULL)
***************
*** 151,167 ****
/* -------------------------- gl_thread_t datatype --------------------------
*/
typedef pth_t gl_thread_t;
! # define glthread_create(THREAD, FUNC, ARG) \
! (pth_in_use () ? ((*(THREAD) = pth_spawn (NULL, FUNC, ARG)) ? 0 : -1) : 0)
# define glthread_sigmask(HOW, SET, OSET) \
! (pth_in_use && !pth_sigmask (HOW, SET, OSET) ? errno : 0)
! # define glthread_join(THREAD, VALPTR) \
! (pth_in_use () && !pth_join (THREAD, VALPTR) ? errno : 0)
! # define glthread_self() \
(pth_in_use () ? (void *) pth_self () : 0)
! # define glthread_exit(VALPTR) \
! (pth_in_use () ? pth_exit (VALPTR) : 0)
! # define glthread_atfork(PREPARE, PARENT, CHILD) 0
#endif
--- 191,207 ----
/* -------------------------- gl_thread_t datatype --------------------------
*/
typedef pth_t gl_thread_t;
! # define glthread_create(THREADP, FUNC, ARG) \
! (pth_in_use () ? ((*(THREADP) = pth_spawn (NULL, FUNC, ARG)) ? 0 : errno)
: 0)
# define glthread_sigmask(HOW, SET, OSET) \
! (pth_in_use () && !pth_sigmask (HOW, SET, OSET) ? errno : 0)
! # define glthread_join(THREAD, RETVALP) \
! (pth_in_use () && !pth_join (THREAD, RETVALP) ? errno : 0)
! # define gl_thread_self() \
(pth_in_use () ? (void *) pth_self () : 0)
! # define gl_thread_exit(RETVAL) \
! (pth_in_use () ? pth_exit (RETVAL) : 0)
! # define glthread_atfork(PREPARE_FUNC, PARENT_FUNC, CHILD_FUNC) 0
#endif
***************
*** 173,179 ****
# include <thread.h>
# include <synch.h>
- # include <stdlib.h>
# ifdef __cplusplus
extern "C" {
--- 213,218 ----
***************
*** 187,192 ****
--- 226,232 ----
# pragma weak thr_join
# pragma weak thr_self
# pragma weak thr_exit
+
# pragma weak thr_suspend
# define thread_in_use() (thr_suspend != NULL)
***************
*** 199,215 ****
/* -------------------------- gl_thread_t datatype --------------------------
*/
typedef thread_t gl_thread_t;
! # define glthread_create(THREAD, FUNC, ARG) \
! (thread_in_use () ? thr_create (NULL, 0, FUNC, ARG, 0, THREAD) : 0)
# define glthread_sigmask(HOW, SET, OSET) \
(pthread_in_use () ? sigprocmask (HOW, SET, OSET) : 0)
! # define glthread_join(THREAD, RETVAL) \
! (pthread_in_use () ? thr_join (THREAD, NULL, RETVAL) : 0)
! # define glthread_self() \
(pthread_in_use () ? (void *) thr_self () : 0)
! # define glthread_exit(VALPTR) \
! (pthread_in_use () ? thr_exit (VALPTR) : 0)
! # define glthread_atfork(PREPARE, PARENT, CHILD) 0
#endif
--- 239,255 ----
/* -------------------------- gl_thread_t datatype --------------------------
*/
typedef thread_t gl_thread_t;
! # define glthread_create(THREADP, FUNC, ARG) \
! (thread_in_use () ? thr_create (NULL, 0, FUNC, ARG, 0, THREADP) : 0)
# define glthread_sigmask(HOW, SET, OSET) \
(pthread_in_use () ? sigprocmask (HOW, SET, OSET) : 0)
! # define glthread_join(THREAD, RETVALP) \
! (pthread_in_use () ? thr_join (THREAD, NULL, RETVALP) : 0)
! # define gl_thread_self() \
(pthread_in_use () ? (void *) thr_self () : 0)
! # define gl_thread_exit(RETVAL) \
! (pthread_in_use () ? thr_exit (RETVAL) : 0)
! # define glthread_atfork(PREPARE_FUNC, PARENT_FUNC, CHILD_FUNC) 0
#endif
***************
*** 220,231 ****
/* Provide dummy implementation if threads are not supported. */
typedef int gl_thread_t;
! # define glthread_create(THREAD, FUNC, ARG) 0
# define glthread_sigmask(HOW, SET, OSET) 0
! # define glthread_join(THREAD, RETVAL) 0
! # define glthread_self() NULL
! # define glthread_exit(VALPTR) 0
! # define glthread_atfork(PREPARE, PARENT, CHILD) 0
#endif
--- 260,271 ----
/* Provide dummy implementation if threads are not supported. */
typedef int gl_thread_t;
! # define glthread_create(THREADP, FUNC, ARG) 0
# define glthread_sigmask(HOW, SET, OSET) 0
! # define glthread_join(THREAD, RETVALP) 0
! # define gl_thread_self() NULL
! # define gl_thread_exit(RETVAL) 0
! # define glthread_atfork(PREPARE_FUNC, PARENT_FUNC, CHILD_FUNC) 0
#endif
***************
*** 242,256 ****
int ret;
ret = glthread_create (thread, func, arg);
! if (ret)
abort ();
-
return ret;
}
-
#define gl_thread_create(THREAD, FUNC, ARG) \
gl_thread_create_func(&THREAD, FUNC, ARG)
-
#define gl_thread_sigmask(HOW, SET, OSET) \
do \
{ \
--- 282,293 ----
int ret;
ret = glthread_create (thread, func, arg);
! if (ret != 0)
abort ();
return ret;
}
#define gl_thread_create(THREAD, FUNC, ARG) \
gl_thread_create_func (&THREAD, FUNC, ARG)
#define gl_thread_sigmask(HOW, SET, OSET) \
do \
{ \
*** m4/thread.m4 2008-08-17 17:11:16.000000000 +0200
--- /packages/GNULIB/gnulib-git/m4/thread.m4 2008-08-17 18:01:35.000000000
+0200
***************
*** 1,15 ****
! # glcond.m4 serial 1 (gettext-0.15)
! dnl Copyright (C) 2005 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_THREAD],
[
! AC_C_INLINE()
! AC_REQUIRE([gl_LOCK])
if test $gl_threads_api = posix; then
! AC_CHECK_FUNC(pthread_atfork)
fi
])
--- 1,15 ----
! # thread.m4 serial 1
! dnl Copyright (C) 2008 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_THREAD],
[
! AC_REQUIRE([gl_THREADLIB])
! AC_REQUIRE([AC_C_INLINE])
if test $gl_threads_api = posix; then
! AC_CHECK_FUNCS([pthread_atfork])
fi
])
- Re: checkin of glthread/glcond modules, Bruno Haible, 2008/08/13
- Re: checkin of glthread/glcond modules, Yoann Vandoorselaere, 2008/08/13
- Re: checkin of glthread/glcond modules, Bruno Haible, 2008/08/14
- Re: checkin of glthread/glcond modules, Bruno Haible, 2008/08/17
- Re: checkin of glthread/glcond modules,
Bruno Haible <=
- Re: checkin of glthread/glcond modules, Bruno Haible, 2008/08/17
- Re: checkin of glthread/glcond modules, Bruno Haible, 2008/08/17
- Re: checkin of glthread/glcond modules, Bruno Haible, 2008/08/17
- Re: checkin of glthread/glcond modules, Bruno Haible, 2008/08/18
- Re: checkin of glthread/glcond modules, Bruno Haible, 2008/08/17
- Re: checkin of glthread/glcond modules, Bruno Haible, 2008/08/17
- Re: checkin of glthread/glcond modules, Bruno Haible, 2008/08/17