Back to index

glibc  2.9
tls.h
Go to the documentation of this file.
00001 /* Definitions for thread-local data handling.  linuxthreads/Alpha version.
00002    Copyright (C) 2002, 2003, 2005 Free Software Foundation, Inc.
00003    This file is part of the GNU C Library.
00004 
00005    The GNU C Library is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Lesser General Public
00007    License as published by the Free Software Foundation; either
00008    version 2.1 of the License, or (at your option) any later version.
00009 
00010    The GNU C Library is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Lesser General Public License for more details.
00014 
00015    You should have received a copy of the GNU Lesser General Public
00016    License along with the GNU C Library; if not, write to the Free
00017    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00018    02111-1307 USA.  */
00019 
00020 #ifndef _TLS_H
00021 #define _TLS_H
00022 
00023 #ifndef __ASSEMBLER__
00024 
00025 # include <pt-machine.h>
00026 # include <stdbool.h>
00027 # include <stddef.h>
00028 
00029 /* Type for the dtv.  */
00030 typedef union dtv
00031 {
00032   size_t counter;
00033   struct
00034   {
00035     void *val;
00036     bool is_static;
00037   } pointer;
00038 } dtv_t;
00039 
00040 
00041 typedef struct
00042 {
00043   dtv_t *dtv;
00044 
00045   /* Reserved for the thread implementation.  Unused in LinuxThreads.  */
00046   void *private;
00047 } tcbhead_t;
00048 #endif
00049 
00050 
00051 #ifdef HAVE_TLS_SUPPORT
00052 
00053 /* Signal that TLS support is available.  */
00054 # define USE_TLS     1
00055 
00056 # ifndef __ASSEMBLER__
00057 /* Get system call information.  */
00058 #  include <sysdep.h>
00059 
00060 /* This is the size of the initial TCB.  */
00061 #  define TLS_INIT_TCB_SIZE sizeof (tcbhead_t)
00062 
00063 /* Alignment requirements for the initial TCB.  */
00064 #  define TLS_INIT_TCB_ALIGN       __alignof__ (tcbhead_t)
00065 
00066 /* This is the size of the TCB.  */
00067 #  define TLS_TCB_SIZE             sizeof (tcbhead_t)
00068 
00069 /* Alignment requirements for the TCB.  */
00070 #  define TLS_TCB_ALIGN            __alignof__ (tcbhead_t)
00071 
00072 /* This is the size we need before TCB.  */
00073 #  define TLS_PRE_TCB_SIZE  sizeof (struct _pthread_descr_struct)
00074 
00075 /* The DTV is allocated at the TP; the TCB is placed elsewhere.  */
00076 #  define TLS_DTV_AT_TP 1
00077 
00078 /* Install the dtv pointer.  The pointer passed is to the element with
00079    index -1 which contain the length.  */
00080 #  define INSTALL_DTV(TCBP, DTVP) \
00081   (((tcbhead_t *) (TCBP))->dtv = (DTVP) + 1)
00082 
00083 /* Install new dtv for current thread.  */
00084 #  define INSTALL_NEW_DTV(DTV) \
00085   (((tcbhead_t *)__builtin_thread_pointer ())->dtv = (DTV))
00086 
00087 /* Return dtv of given thread descriptor.  */
00088 #  define GET_DTV(TCBP) \
00089   (((tcbhead_t *) (TCBP))->dtv)
00090 
00091 /* Code to initially initialize the thread pointer.  This might need
00092    special attention since 'errno' is not yet available and if the
00093    operation can cause a failure 'errno' must not be touched.  */
00094 # define TLS_INIT_TP(TCBP, SECONDCALL) \
00095   (__builtin_set_thread_pointer (TCBP), 0)
00096 
00097 /* Return the address of the dtv for the current thread.  */
00098 #  define THREAD_DTV() \
00099   (((tcbhead_t *)__builtin_thread_pointer ())->dtv)
00100 
00101 /* Return the thread descriptor for the current thread.  */
00102 #  undef THREAD_SELF
00103 #  define THREAD_SELF \
00104   ((pthread_descr)__builtin_thread_pointer () - 1)
00105 
00106 #  undef INIT_THREAD_SELF
00107 #  define INIT_THREAD_SELF(DESCR, NR) \
00108   __builtin_set_thread_pointer ((struct _pthread_descr_struct *)(DESCR) + 1)
00109 
00110 /* Get the thread descriptor definition.  */
00111 #  include <linuxthreads/descr.h>
00112 
00113 /* ??? Generic bits of LinuxThreads may call these macros with
00114    DESCR set to NULL.  We are expected to be able to reference
00115    the "current" value.
00116 
00117    In our case, we'd really prefer to use DESCR, since lots of
00118    PAL_code calls would be expensive.  We can only trust that
00119    the compiler does its job and unifies the multiple
00120    __builtin_thread_pointer instances.  */
00121 
00122 #define THREAD_GETMEM(descr, member) \
00123   ((void) sizeof (descr), THREAD_SELF->member)
00124 #define THREAD_GETMEM_NC(descr, member) \
00125   ((void) sizeof (descr), THREAD_SELF->member)
00126 #define THREAD_SETMEM(descr, member, value) \
00127   ((void) sizeof (descr), THREAD_SELF->member = (value))
00128 #define THREAD_SETMEM_NC(descr, member, value) \
00129   ((void) sizeof (descr), THREAD_SELF->member = (value))
00130 
00131 # endif       /* HAVE_TLS_SUPPORT */
00132 #endif /* __ASSEMBLER__ */
00133 
00134 #endif /* tls.h */