Esempio n. 1
0
int d() {
  __thread static int e;
  __thread static union {float a; int b;} f = {.b = 1};
  return 0;
}

__thread int g __attribute__((tls_model("global-dynamic")));
__thread int h __attribute__((tls_model("local-dynamic")));
__thread int i __attribute__((tls_model("initial-exec")));
__thread int j __attribute__((tls_model("local-exec")));

int f() {
  __thread static int a __attribute__((tls_model("initial-exec")));
  return a++;
}
Esempio n. 2
0
/*
 * Current context management and locking
 */

_X_HIDDEN pthread_mutex_t __glXmutex = PTHREAD_MUTEX_INITIALIZER;

# if defined( GLX_USE_TLS )

/**
 * Per-thread GLX context pointer.
 *
 * \c __glXSetCurrentContext is written is such a way that this pointer can
 * \b never be \c NULL.  This is important!  Because of this
 * \c __glXGetCurrentContext can be implemented as trivial macro.
 */
__thread void *__glX_tls_Context __attribute__ ((tls_model("initial-exec")))
   = &dummyContext;

_X_HIDDEN void
__glXSetCurrentContext(struct glx_context * c)
{
   __glX_tls_Context = (c != NULL) ? c : &dummyContext;
}

# else

static pthread_once_t once_control = PTHREAD_ONCE_INIT;

/**
 * Per-thread data key.
 *
Esempio n. 3
0
File: run-ld.c Progetto: 0day-ci/gcc
/* { dg-do run } */
/* { dg-require-effective-target tls_runtime } */
/* { dg-add-options tls } */

extern void abort (void);

__thread int tls_ld __attribute__((tls_model("local-dynamic"))) = 1;
__thread int tls_ld2 __attribute__((tls_model("local-dynamic"))) = 2;

int get_ld (void)
{
  return tls_ld + tls_ld2;
}

int *get_ldp (void)
{
  return &tls_ld;
}

int main (void)
{
  int val;

  val = get_ld ();
  if (val != 1 + 2)
    abort ();

  val = *get_ldp ();
  if (val != 1)
    abort ();
Esempio n. 4
0
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Lesser General Public License for more details.

   You should have received a copy of the GNU Lesser General Public
   License along with the GNU C Library; if not, see
   <http://www.gnu.org/licenses/>.  */

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <tls.h>


static __thread unsigned char foo [32]
  __attribute__ ((tls_model ("initial-exec"), aligned (sizeof (void *))));

void
test1 (void)
{
  size_t s;

  for (s = 0; s < sizeof (foo); ++s)
    {
      if (foo [s])
	abort ();
      foo [s] = s;
    }
}

void
#include <tls.h>

#if defined HAVE___THREAD && defined HAVE_TLS_MODEL_ATTRIBUTE
extern __thread int tlsvar __attribute__((tls_model("initial-exec")));
#else
extern int tlsvar;
#endif

void *
in_dso (void)
{
  return &tlsvar;
}
Esempio n. 6
0
#include "tst-tls10.h"

__thread int mod15b_var __attribute__((tls_model("initial-exec")));

int
in_dso (void)
{
  return mod15b_var;
}
Esempio n. 7
0
File: opt-5.c Progetto: 0day-ci/gcc
/* { dg-do compile } */
/* { dg-options "-O2" } */
/* { dg-require-effective-target tls } */
/* Sched1 moved {load_tp} pattern between strlen call and the copy
   of the hard return value to its pseudo.  This resulted in a
   reload abort, since the hard register was not spillable.  */

extern __thread int __libc_errno __attribute__ ((tls_model ("initial-exec")));

struct stat64
  {
    long dummy[4];
  };
typedef __SIZE_TYPE__ size_t;
typedef unsigned long long uint64_t;
typedef int __mode_t;

extern size_t strlen (__const char *__s) __attribute__ ((__pure__));
extern int strcmp (__const char *__s1, __const char *__s2)
     __attribute__ ((__pure__));

extern int __open64 (__const char *__file, int __oflag, ...);
extern int __open (__const char *__file, int __oflag, ...);
extern int __mkdir (__const char *__path, __mode_t __mode);
extern int __lxstat64 (int __ver, __const char *__filename,
                       struct stat64 *__stat_buf) ;

static const char letters[] =
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";

int
Esempio n. 8
0
#include <memory.h>
#include <malloc.h>
#include <unistd.h>
#include <pthread.h>
#include <signal.h>
#include <limits.h>
#include <pthread.h>
#include <native/syscall.h>
#include <native/task.h>
#include <asm-generic/bits/sigshadow.h>
#include <asm-generic/bits/current.h>
#include <asm-generic/stack.h>
#include "wrappers.h"

#ifdef HAVE___THREAD
__thread RT_TASK __native_self __attribute__ ((tls_model ("initial-exec"))) = {
	.opaque = XN_NO_HANDLE,
	.opaque2 = 0
};
#else /* !HAVE___THREAD */
extern pthread_key_t __native_tskey;
#endif /* !HAVE___THREAD */

extern int __native_muxid;

/* Public Xenomai interface. */

struct rt_task_iargs {
	RT_TASK *task;
	const char *name;
	int prio;
Esempio n. 9
0
#define	JEMALLOC_TCACHE_C_
#include "jemalloc/internal/jemalloc_internal.h"
#ifdef JEMALLOC_TCACHE
/******************************************************************************/
/* Data. */

bool	opt_tcache = true;
ssize_t	opt_lg_tcache_max = LG_TCACHE_MAXCLASS_DEFAULT;
ssize_t	opt_lg_tcache_gc_sweep = LG_TCACHE_GC_SWEEP_DEFAULT;

/* Map of thread-specific caches. */
#ifndef NO_TLS
__thread tcache_t	*tcache_tls JEMALLOC_ATTR(tls_model("initial-exec"));
#endif

/*
 * Same contents as tcache, but initialized such that the TSD destructor is
 * called when a thread exits, so that the cache can be cleaned up.
 */
pthread_key_t		tcache_tsd;

size_t				nhbins;
size_t				tcache_maxclass;
unsigned			tcache_gc_incr;

/******************************************************************************/
/* Function prototypes for non-inline static functions. */

static void	tcache_thread_cleanup(void *arg);

/******************************************************************************/
Esempio n. 10
0
   Author(s): Ryan S. Arnold <*****@*****.**>

   The Decimal Floating Point C Library is free software; you can
   redistribute it and/or modify it under the terms of the GNU Lesser
   General Public License version 2.1.

   The Decimal Floating Point C Library 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 Lesser General Public License version 2.1 for more details.

   You should have received a copy of the GNU Lesser General Public
   License version 2.1 along with the Decimal Floating Point C Library;
   if not, write to the Free Software Foundation, Inc., 59 Temple Place,
   Suite 330, Boston, MA 02111-1307 USA.

   Please see libdfp/COPYING.txt for more information.  */

/*#include <tls.h>*/
#include <pthread.h>
#include <fenv.h>
#include "decroundtls.h"

__thread int __dec_round_mode __attribute__ ((tls_model ("initial-exec"))) = FE_DEC_TONEAREST;

int *__decrm_location (void)
{
  return &__dec_round_mode;
}
hidden_def (__decrm_location)
Esempio n. 11
0
CB (1)
CB (2)
CB (3)
CB (4)
CB (5)
CB (6)
CB (7)
CB (8)
CB (9)
static void (*cbs[]) (void) =
{
  cb0, cb1, cb2, cb3, cb4, cb5, cb6, cb7, cb8, cb9
};


static __thread void (*fp) (void) __attribute__ ((tls_model ("local-exec")));


static sem_t s;


#define THE_SIG SIGUSR1
static void
handler (int sig)
{
  if (sig != THE_SIG)
    {
      write (STDOUT_FILENO, "wrong signal\n", 13);
      _exit (1);
    }
Esempio n. 12
0
#include <unistd.h>
#include <stdlib.h>
#include <pthread.h>
#include <semaphore.h>
#include <signal.h>
#include <errno.h>
#include <limits.h>
#include <nucleus/sched.h>
#include <vrtx/vrtx.h>
#include <asm-generic/sigshadow.h>
#include <asm-generic/current.h>
#include <asm-generic/stack.h>
#include "wrappers.h"

#ifdef HAVE___THREAD
__thread TCB __vrtx_tcb __attribute__ ((tls_model ("initial-exec")));
#else /* !HAVE___THREAD */
extern pthread_key_t __vrtx_tskey;
#endif /* !HAVE___THREAD */

extern int __vrtx_muxid;

/* Public Xenomai interface. */

struct vrtx_task_iargs {
	int tid;
	int prio;
	int mode;
	void (*entry) (void *);
	void *param;
	sem_t sync;
Esempio n. 13
0
static int __thread tbar __attribute__ ((tls_model ("initial-exec"))) = 666;

void
setter (int a)
{
    tbar = a;
}

int
bar (void)
{
    return tbar;
}
Esempio n. 14
0
#define	JEMALLOC_CHUNK_MMAP_C_
#include "jemalloc/internal/jemalloc_internal.h"

/******************************************************************************/
/* Data. */

/*
 * Used by chunk_alloc_mmap() to decide whether to attempt the fast path and
 * potentially avoid some system calls.
 */
#ifndef NO_TLS
static __thread bool	mmap_unaligned_tls
    JEMALLOC_ATTR(tls_model("initial-exec"));
#define	MMAP_UNALIGNED_GET()	mmap_unaligned_tls
#define	MMAP_UNALIGNED_SET(v)	do {					\
	mmap_unaligned_tls = (v);					\
} while (0)
#else
static pthread_key_t	mmap_unaligned_tsd;
#define	MMAP_UNALIGNED_GET()	((bool)pthread_getspecific(mmap_unaligned_tsd))
#define	MMAP_UNALIGNED_SET(v)	do {					\
	pthread_setspecific(mmap_unaligned_tsd, (void *)(v));		\
} while (0)
#endif

/******************************************************************************/
/* Function prototypes for non-inline static functions. */

static void	*pages_map(void *addr, size_t size, bool noreserve);
static void	pages_unmap(void *addr, size_t size);
static void	*chunk_alloc_mmap_slow(size_t size, bool unaligned,
 * modification, are permitted provided that the following conditions
 * are met:
 *  * Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 *  * Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in
 *    the documentation and/or other materials provided with the
 *    distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 */

// Accessing a symbol in libtest_elftls_shared_var.so using an IE access should
// work iff the solib is part of static TLS.
__attribute__((tls_model("initial-exec"))) extern "C" __thread int elftls_shared_var;

extern "C" int bump_shared_var() {
  return ++elftls_shared_var;
}
Esempio n. 16
0
#include <tls.h>

__thread int b[2] __attribute__ ((tls_model ("initial-exec")));

extern int foo (void);

int
bar (void)
{
  return foo () + b[0];
}
Esempio n. 17
0
 * possible for the original thread to be setting it at the same instant a new
 * thread, perhaps running on a different processor, is clearing it.  Because
 * of that, \c ThreadSafe, which can only ever be changed to \c GL_TRUE, is
 * used to determine whether or not the application is multithreaded.
 * 
 * In the TLS case, the variables \c _glapi_Dispatch and \c _glapi_Context are
 * hardcoded to \c NULL.  Instead the TLS variables \c _glapi_tls_Dispatch and
 * \c _glapi_tls_Context are used.  Having \c _glapi_Dispatch and
 * \c _glapi_Context be hardcoded to \c NULL maintains binary compatability
 * between TLS enabled loaders and non-TLS DRI drivers.
 */
/*@{*/
#if defined(GLX_USE_TLS)

__thread struct mapi_table *u_current_table
    __attribute__((tls_model("initial-exec")))
    = (struct mapi_table *) table_noop_array;

__thread void *u_current_user
    __attribute__((tls_model("initial-exec")));

#else

struct mapi_table *u_current_table =
   (struct mapi_table *) table_noop_array;
void *u_current_user;

#ifdef THREADS
struct u_tsd u_current_table_tsd;
static struct u_tsd u_current_user_tsd;
static int ThreadSafe;
Esempio n. 18
0
#include <stdio.h>

static int __thread tbaz __attribute__ ((tls_model ("local-dynamic"))) = 42;

void
setter2 (int a)
{
  tbaz = a;
}

int
baz (void)
{
  printf ("&tbaz=%p\n", &tbaz);
  return tbaz;
}
Esempio n. 19
0
#include "tst-tls10.h"

__thread int dummy __attribute__((visibility ("hidden"))) = 12;
__thread struct A a1 = { 4, 5, 6 };
__thread struct A a2 = { 7, 8, 9 };
__thread struct A a3 __attribute__((tls_model("initial-exec")))
  = { 10, 11, 12 };
__thread struct A a4 __attribute__((tls_model("initial-exec")))
  = { 13, 14, 15 };
static __thread struct A local1 = { 16, 17, 18 };
static __thread struct A local2 __attribute__((tls_model("initial-exec")))
  = { 19, 20, 21 };

void
check1 (void)
{
  if (a1.a != 4 || a1.b != 5 || a1.c != 6)
    abort ();
  if (a2.a != 22 || a2.b != 23 || a2.c != 24)
    abort ();
  if (a3.a != 10 || a3.b != 11 || a3.c != 12)
    abort ();
  if (a4.a != 25 || a4.b != 26 || a4.c != 27)
    abort ();
  if (local1.a != 16 || local1.b != 17 || local1.c != 18)
    abort ();
  if (local2.a != 19 || local2.b != 20 || local2.c != 21)
    abort ();
}

struct A *
Esempio n. 20
0
#include <sched.h>

#include "config.h"
#include "client.h"

#include "caching_client.h"
#include "caching_client_private.h"
#include "command.h"
#include "name_handler.h"

#include <sys/prctl.h>
#include <sys/types.h>
#include <unistd.h>

__thread client_t* thread_local_client
    __attribute__(( tls_model ("initial-exec"))) = NULL;

__thread bool client_thread
    __attribute__(( tls_model ("initial-exec"))) = true;

__thread bool initializing_client
    __attribute__(( tls_model ("initial-exec"))) = false;

__thread bool initialized
    __attribute__(( tls_model ("initial-exec"))) = false;

mutex_static_init (client_thread_mutex);

static void
client_fill_dispatch_table (dispatch_table_t *client);