X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=lib%2Fglthread%2Fthread.h;h=456d397901fe00ad25b77d2df29902ac334d789d;hb=3c65a6806b208533f681855712e0febf4bb0ed67;hp=bd8575f11b3c7aae6ff08c5ee10061dcceb2ad8c;hpb=eee77e6bd0eb54a896974b11ca352e9020149d70;p=gnulib.git diff --git a/lib/glthread/thread.h b/lib/glthread/thread.h index bd8575f11..456d39790 100644 --- a/lib/glthread/thread.h +++ b/lib/glthread/thread.h @@ -1,5 +1,5 @@ /* Creating and controlling threads. - Copyright (C) 2005-2008 Free Software Foundation, Inc. + Copyright (C) 2005-2010 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 @@ -137,6 +137,9 @@ extern int glthread_in_use (void); /* -------------------------- gl_thread_t datatype -------------------------- */ +/* This choice of gl_thread_t assumes that + pthread_equal (a, b) is equivalent to ((a) == (b)). + This is the case on all platforms in use in 2008. */ typedef pthread_t gl_thread_t; # define glthread_create(THREADP, FUNC, ARG) \ (pthread_in_use () ? pthread_create (THREADP, NULL, FUNC, ARG) : ENOSYS) @@ -156,6 +159,10 @@ typedef pthread_t gl_thread_t; # define glthread_atfork(PREPARE_FUNC, PARENT_FUNC, CHILD_FUNC) 0 # endif +# ifdef __cplusplus +} +# endif + #endif /* ========================================================================= */ @@ -203,6 +210,10 @@ typedef pth_t gl_thread_t; (pth_in_use () ? pth_exit (RETVAL) : 0) # define glthread_atfork(PREPARE_FUNC, PARENT_FUNC, CHILD_FUNC) 0 +# ifdef __cplusplus +} +# endif + #endif /* ========================================================================= */ @@ -242,16 +253,64 @@ 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) + (thread_in_use () ? sigprocmask (HOW, SET, OSET) : 0) # define glthread_join(THREAD, RETVALP) \ - (pthread_in_use () ? thr_join (THREAD, NULL, RETVALP) : 0) + (thread_in_use () ? thr_join (THREAD, NULL, RETVALP) : 0) # define gl_thread_self() \ - (pthread_in_use () ? (void *) thr_self () : 0) + (thread_in_use () ? (void *) thr_self () : 0) # define gl_thread_exit(RETVAL) \ - (pthread_in_use () ? thr_exit (RETVAL) : 0) + (thread_in_use () ? thr_exit (RETVAL) : 0) # define glthread_atfork(PREPARE_FUNC, PARENT_FUNC, CHILD_FUNC) 0 + +# ifdef __cplusplus +} +# endif + #endif +/* ========================================================================= */ + +#if USE_WIN32_THREADS + +# include + +# ifdef __cplusplus +extern "C" { +# endif + +/* -------------------------- gl_thread_t datatype -------------------------- */ + +/* The gl_thread_t is a pointer to a structure in memory. + Why not the thread handle? If it were the thread handle, it would be hard + to implement gl_thread_self() (since GetCurrentThread () returns a pseudo- + handle, DuplicateHandle (GetCurrentThread ()) returns a handle that must be + closed afterwards, and there is no function for quickly retrieving a thread + handle from its id). + Why not the thread id? I tried it. It did not work: Sometimes ids appeared + that did not belong to running threads, and glthread_join failed with ESRCH. + */ +typedef struct gl_thread_struct *gl_thread_t; +# define glthread_create(THREADP, FUNC, ARG) \ + glthread_create_func (THREADP, FUNC, ARG) +# define glthread_sigmask(HOW, SET, OSET) \ + /* unsupported */ 0 +# define glthread_join(THREAD, RETVALP) \ + glthread_join_func (THREAD, RETVALP) +# define gl_thread_self() \ + gl_thread_self_func () +# define gl_thread_exit(RETVAL) \ + gl_thread_exit_func (RETVAL) +# define glthread_atfork(PREPARE_FUNC, PARENT_FUNC, CHILD_FUNC) 0 +extern int glthread_create_func (gl_thread_t *threadp, void * (*func) (void *), void *arg); +extern int glthread_join_func (gl_thread_t thread, void **retvalp); +extern gl_thread_t gl_thread_self_func (void); +extern int gl_thread_exit_func (void *retval); + +# ifdef __cplusplus +} +# endif + +#endif /* ========================================================================= */ @@ -269,11 +328,14 @@ typedef int gl_thread_t; #endif - /* ========================================================================= */ /* Macros with built-in error handling. */ +#ifdef __cplusplus +extern "C" { +#endif + static inline gl_thread_t gl_thread_create (void *(*func) (void *arg), void *arg) { @@ -307,4 +369,8 @@ gl_thread_create (void *(*func) (void *arg), void *arg) } \ while (0) +#ifdef __cplusplus +} +#endif + #endif /* _GLTHREAD_THREAD_H */