Back to index

glibc  2.9
Defines | Functions | Variables
tst-tls3.c File Reference
#include <dlfcn.h>
#include <errno.h>
#include <pthread.h>
#include <signal.h>
#include <semaphore.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <pthreaddef.h>
#include "../test-skeleton.c"

Go to the source code of this file.

Defines

#define THE_SIG   SIGUSR1
#define N   10
#define CB(n)
#define TOTAL_SIGS   1000
#define TIMEOUT   5
#define TEST_FUNCTION   do_test ()

Functions

int do_test (void)

Variables

static pthread_t th [N]
static void(* cbs [])(void)
sem_t s
pthread_barrier_t b
int nsigs

Define Documentation

#define CB (   n)
Value:
static void                                                          \
cb##n (void)                                                         \
{                                                                    \
  if (th[n] != pthread_self ())                                             \
    {                                                                \
      write (STDOUT_FILENO, "wrong callback\n", 15);                        \
      _exit (1);                                                     \
    }                                                                \
}

Definition at line 38 of file tst-tls3.c.

#define N   10

Definition at line 34 of file tst-tls3.c.

#define TEST_FUNCTION   do_test ()

Definition at line 214 of file tst-tls3.c.

#define THE_SIG   SIGUSR1

Definition at line 31 of file tst-tls3.c.

#define TIMEOUT   5

Definition at line 213 of file tst-tls3.c.

#define TOTAL_SIGS   1000

Definition at line 69 of file tst-tls3.c.


Function Documentation

int do_test ( void  )

Definition at line 74 of file tst-tls3.c.

{
#if !HAVE___THREAD

  puts ("No __thread support in compiler, test skipped.");

  return 0;
#else

  if ((uintptr_t) pthread_self () & (TCB_ALIGNMENT - 1))
    {
      puts ("initial thread's struct pthread not aligned enough");
      exit (1);
    }

  if (pthread_barrier_init (&b, NULL, N + 1) != 0)
    {
      puts ("barrier_init failed");
      exit (1);
    }

  if (sem_init (&s, 0, 0) != 0)
    {
      puts ("sem_init failed");
      exit (1);
    }

  void *h = dlopen ("tst-tls3mod.so", RTLD_LAZY);
  if (h == NULL)
    {
      puts ("dlopen failed");
      exit (1);
    }

  void *(*tf) (void *) = dlsym (h, "tf");
  if (tf == NULL)
    {
      puts ("dlsym for tf failed");
      exit (1);
    }

  struct sigaction sa;
  sa.sa_handler = dlsym (h, "handler");
  if (sa.sa_handler == NULL)
    {
      puts ("dlsym for handler failed");
      exit (1);
    }
  sigemptyset (&sa.sa_mask);
  sa.sa_flags = 0;
  if (sigaction (THE_SIG, &sa, NULL) != 0)
    {
      puts ("sigaction failed");
      exit (1);
    }

  pthread_attr_t a;

  if (pthread_attr_init (&a) != 0)
    {
      puts ("attr_init failed");
      exit (1);
    }

  if (pthread_attr_setstacksize (&a, 1 * 1024 * 1024) != 0)
    {
      puts ("attr_setstacksize failed");
      return 1;
    }

  int r;
  for (r = 0; r < 10; ++r)
    {
      int i;
      for (i = 0; i < N; ++i)
       if (pthread_create (&th[i], &a, tf, cbs[i]) != 0)
         {
           puts ("pthread_create failed");
           exit (1);
         }

      nsigs = 0;

      pthread_barrier_wait (&b);

      sigset_t ss;
      sigemptyset (&ss);
      sigaddset (&ss, THE_SIG);
      if (pthread_sigmask (SIG_BLOCK, &ss, NULL) != 0)
       {
         puts ("pthread_sigmask failed");
         exit (1);
       }

      /* Start sending signals.  */
      for (i = 0; i < TOTAL_SIGS; ++i)
       {
         if (kill (getpid (), THE_SIG) != 0)
           {
             puts ("kill failed");
             exit (1);
           }

         if (TEMP_FAILURE_RETRY (sem_wait (&s)) != 0)
           {
             puts ("sem_wait failed");
             exit (1);
           }

         ++nsigs;
       }

      pthread_barrier_wait (&b);

      if (pthread_sigmask (SIG_UNBLOCK, &ss, NULL) != 0)
       {
         puts ("pthread_sigmask failed");
         exit (1);
       }

      for (i = 0; i < N; ++i)
       if (pthread_join (th[i], NULL) != 0)
         {
           puts ("join failed");
           exit (1);
         }
    }

  if (pthread_attr_destroy (&a) != 0)
    {
      puts ("attr_destroy failed");
      exit (1);
    }

  return 0;
#endif
}

Here is the call graph for this function:


Variable Documentation

pthread_barrier_t b

Definition at line 67 of file tst-tls3.c.

void(* cbs[])(void) [static]
Initial value:
{
  cb0, cb1, cb2, cb3, cb4, cb5, cb6, cb7, cb8, cb9
}

Definition at line 58 of file tst-tls3.c.

Definition at line 70 of file tst-tls3.c.

Definition at line 64 of file tst-tls3.c.

pthread_t th[N] [static]

Definition at line 35 of file tst-tls3.c.