X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=lib%2Fglthread%2Fthread.h;h=3d7f7601d100f5faf5eef721b46043a2d73a9346;hb=368777cd04f76f7a3b242006fdf6c1e6b77381de;hp=5d72040734be55a55394d2fd32e9049c5a1bf10a;hpb=d60f3b0c6b0f93a601acd1cfd3923f94ca05abb0;p=gnulib.git diff --git a/lib/glthread/thread.h b/lib/glthread/thread.h index 5d7204073..3d7f7601d 100644 --- a/lib/glthread/thread.h +++ b/lib/glthread/thread.h @@ -47,9 +47,13 @@ current = gl_thread_self (); extern gl_thread_t gl_thread_self (void); + Getting a reference to the current thread as a pointer, for debugging: + ptr = gl_thread_self_pointer (); + extern void * gl_thread_self_pointer (void); + Terminating the current thread: gl_thread_exit (return_value); - extern void gl_thread_exit (void *return_value) __attribute__ ((noreturn)); + extern _Noreturn void gl_thread_exit (void *return_value); Requesting custom code to be executed at fork() time(not supported on all platforms): @@ -147,8 +151,20 @@ typedef pthread_t gl_thread_t; (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) +# ifdef PTW32_VERSION + /* In pthreads-win32, pthread_t is a struct with a pointer field 'p' and + other fields. */ +# define gl_thread_self() \ + (pthread_in_use () ? pthread_self () : gl_null_thread) +# define gl_thread_self_pointer() \ + (pthread_in_use () ? pthread_self ().p : NULL) +extern const gl_thread_t gl_null_thread; +# else +# define gl_thread_self() \ + (pthread_in_use () ? pthread_self () : (pthread_t) NULL) +# define gl_thread_self_pointer() \ + (pthread_in_use () ? (void *) pthread_self () : NULL) +# endif # define gl_thread_exit(RETVAL) \ (pthread_in_use () ? pthread_exit (RETVAL) : 0) @@ -205,7 +221,9 @@ typedef pth_t gl_thread_t; # 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) + (pth_in_use () ? (void *) pth_self () : NULL) +# define gl_thread_self_pointer() \ + gl_thread_self () # define gl_thread_exit(RETVAL) \ (pth_in_use () ? pth_exit (RETVAL) : 0) # define glthread_atfork(PREPARE_FUNC, PARENT_FUNC, CHILD_FUNC) 0 @@ -257,7 +275,9 @@ typedef thread_t gl_thread_t; # define glthread_join(THREAD, RETVALP) \ (thread_in_use () ? thr_join (THREAD, NULL, RETVALP) : 0) # define gl_thread_self() \ - (thread_in_use () ? (void *) thr_self () : 0) + (thread_in_use () ? (void *) thr_self () : NULL) +# define gl_thread_self_pointer() \ + gl_thread_self () # define gl_thread_exit(RETVAL) \ (thread_in_use () ? thr_exit (RETVAL) : 0) # define glthread_atfork(PREPARE_FUNC, PARENT_FUNC, CHILD_FUNC) 0 @@ -298,6 +318,8 @@ typedef struct gl_thread_struct *gl_thread_t; glthread_join_func (THREAD, RETVALP) # define gl_thread_self() \ gl_thread_self_func () +# define gl_thread_self_pointer() \ + gl_thread_self () # define gl_thread_exit(RETVAL) \ gl_thread_exit_func (RETVAL) # define glthread_atfork(PREPARE_FUNC, PARENT_FUNC, CHILD_FUNC) 0 @@ -322,7 +344,9 @@ typedef int gl_thread_t; # define glthread_create(THREADP, FUNC, ARG) ENOSYS # define glthread_sigmask(HOW, SET, OSET) 0 # define glthread_join(THREAD, RETVALP) 0 -# define gl_thread_self() NULL +# define gl_thread_self() 0 +# define gl_thread_self_pointer() \ + ((void *) gl_thread_self ()) # define gl_thread_exit(RETVAL) 0 # define glthread_atfork(PREPARE_FUNC, PARENT_FUNC, CHILD_FUNC) 0