X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=lib%2Ftls.h;h=7ee138c4d2814d27ca2cd0711019161e49eb5199;hb=a3a70ebafd7f2fdc069d43e8a26fc246dd7fe5bb;hp=ff36155c2ea5741659130b8bc10b4479ff69cb3d;hpb=37b09d7dc2c5956fbd70c211ed164a9ee1f7e349;p=gnulib.git diff --git a/lib/tls.h b/lib/tls.h index ff36155c2..7ee138c4d 100644 --- a/lib/tls.h +++ b/lib/tls.h @@ -1,20 +1,19 @@ /* Thread-local storage in multithreaded situations. Copyright (C) 2005 Free Software Foundation, Inc. - This program is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published - by the Free Software Foundation; either version 2, or (at your option) + 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 - Library General Public License for more details. + 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 Library 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. */ + 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 Bruno Haible , 2005. */ @@ -38,6 +37,9 @@ */ +#ifndef _TLS_H +#define _TLS_H + /* ========================================================================= */ #if USE_POSIX_THREADS @@ -90,25 +92,33 @@ typedef union } gl_tls_key_t; # define gl_tls_key_init(NAME, DESTRUCTOR) \ - if (pthread_in_use ()) \ - { \ - if (pthread_key_create (&(NAME).key, DESTRUCTOR) != 0) \ - abort (); \ - } \ - else \ - (NAME).singlethread_value = NULL + do \ + { \ + if (pthread_in_use ()) \ + { \ + if (pthread_key_create (&(NAME).key, DESTRUCTOR) != 0) \ + abort (); \ + } \ + else \ + (NAME).singlethread_value = NULL; \ + } \ + while (0) # define gl_tls_get(NAME) \ (pthread_in_use () \ ? pthread_getspecific ((NAME).key) \ : (NAME).singlethread_value) # define gl_tls_set(NAME, POINTER) \ - if (pthread_in_use ()) \ - { \ - if (pthread_setspecific ((NAME).key, (POINTER)) != 0) \ - abort (); \ - } \ - else \ - (NAME).singlethread_value = (POINTER) + do \ + { \ + if (pthread_in_use ()) \ + { \ + if (pthread_setspecific ((NAME).key, (POINTER)) != 0) \ + abort (); \ + } \ + else \ + (NAME).singlethread_value = (POINTER); \ + } \ + while (0) # define gl_tls_key_destroy(NAME) \ if (pthread_in_use () && pthread_key_delete ((NAME).key) != 0) \ abort () @@ -151,25 +161,33 @@ typedef union } gl_tls_key_t; # define gl_tls_key_init(NAME, DESTRUCTOR) \ - if (pth_in_use ()) \ - { \ - if (!pth_key_create (&(NAME).key, DESTRUCTOR)) \ - abort (); \ - } \ - else \ - (NAME).singlethread_value = NULL + do \ + { \ + if (pth_in_use ()) \ + { \ + if (!pth_key_create (&(NAME).key, DESTRUCTOR)) \ + abort (); \ + } \ + else \ + (NAME).singlethread_value = NULL; \ + } \ + while (0) # define gl_tls_get(NAME) \ (pth_in_use () \ ? pth_key_getdata ((NAME).key) \ : (NAME).singlethread_value) # define gl_tls_set(NAME, POINTER) \ - if (pth_in_use ()) \ - { \ - if (!pth_key_setdata ((NAME).key, (POINTER))) \ - abort (); \ - } \ - else \ - (NAME).singlethread_value = (POINTER) + do \ + { \ + if (pth_in_use ()) \ + { \ + if (!pth_key_setdata ((NAME).key, (POINTER))) \ + abort (); \ + } \ + else \ + (NAME).singlethread_value = (POINTER); \ + } \ + while (0) # define gl_tls_key_destroy(NAME) \ if (pth_in_use () && !pth_key_delete ((NAME).key)) \ abort () @@ -211,26 +229,34 @@ typedef union } gl_tls_key_t; # define gl_tls_key_init(NAME, DESTRUCTOR) \ - if (thread_in_use ()) \ - { \ - if (thr_keycreate (&(NAME).key, DESTRUCTOR) != 0) \ - abort (); \ - } \ - else \ - (NAME).singlethread_value = NULL + do \ + { \ + if (thread_in_use ()) \ + { \ + if (thr_keycreate (&(NAME).key, DESTRUCTOR) != 0) \ + abort (); \ + } \ + else \ + (NAME).singlethread_value = NULL; \ + } \ + while (0) # define gl_tls_get(NAME) \ (thread_in_use () \ ? glthread_tls_get ((NAME).key) \ : (NAME).singlethread_value) extern void *glthread_tls_get (thread_key_t key); # define gl_tls_set(NAME, POINTER) \ - if (thread_in_use ()) \ - { \ - if (thr_setspecific ((NAME).key, (POINTER)) != 0) \ - abort (); \ - } \ - else \ - (NAME).singlethread_value = (POINTER) + do \ + { \ + if (thread_in_use ()) \ + { \ + if (thr_setspecific ((NAME).key, (POINTER)) != 0) \ + abort (); \ + } \ + else \ + (NAME).singlethread_value = (POINTER); \ + } \ + while (0) # define gl_tls_key_destroy(NAME) \ /* Unsupported. */ \ (void)0 @@ -284,3 +310,7 @@ typedef struct (void)0 #endif + +/* ========================================================================= */ + +#endif /* _TLS_H */