Back to index

glibc  2.9
Defines | Functions | Variables
tst-cleanup4.c File Reference
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include "../test-skeleton.c"
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Defines

#define TEST_FUNCTION   do_test ()

Functions

void _pthread_cleanup_push (struct _pthread_cleanup_buffer *__buffer, void(*__routine)(void *), void *__arg)
void _pthread_cleanup_pop (struct _pthread_cleanup_buffer *__buffer, int __execute)
void fn5 (void)
void fn7 (void)
void fn9 (void)
void clh (void *arg)
static __attribute__ ((noinline))
static void * tf (void *a)
int do_test (void)

Variables

static int fds [2]
static pthread_barrier_t b2
static int global

Define Documentation

#define TEST_FUNCTION   do_test ()

Definition at line 197 of file tst-cleanup4.c.


Function Documentation

static __attribute__ ( (noinline)  ) [static]

Definition at line 53 of file tst-cleanup4.c.

{
  int r = pthread_barrier_wait (&b2);
  if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
    {
      printf ("%s: barrier_wait failed\n", __FUNCTION__);
      exit (1);
    }

  char c;
  read (fds[0], &c, 1);
}

Here is the call graph for this function:

void _pthread_cleanup_pop ( struct _pthread_cleanup_buffer __buffer,
int  __execute 
)

Definition at line 167 of file cancel.c.

{
  pthread_descr self = thread_self();
  if (execute) buffer->__routine(buffer->__arg);
  THREAD_SETMEM(self, p_cleanup, buffer->__prev);
}
void _pthread_cleanup_push ( struct _pthread_cleanup_buffer __buffer,
void(*)(void *)  __routine,
void *  __arg 
)

Definition at line 155 of file cancel.c.

{
  pthread_descr self = thread_self();
  buffer->__routine = routine;
  buffer->__arg = arg;
  buffer->__prev = THREAD_GETMEM(self, p_cleanup);
  if (buffer->__prev != NULL && FRAME_LEFT (buffer, buffer->__prev))
    buffer->__prev = NULL;
  THREAD_SETMEM(self, p_cleanup, buffer);
}
void clh ( void *  arg)

Definition at line 42 of file tst-cleanup4.c.

{
  int val = (long int) arg;

  printf ("clh (%d)\n", val);

  global *= val;
  global += val;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int do_test ( void  )

Definition at line 127 of file tst-cleanup4.c.

{
  int result = 0;

  if (pipe (fds) != 0)
    {
      puts ("pipe failed");
      exit (1);
    }

  if (pthread_barrier_init (&b2, NULL, 2) != 0)
    {
      puts ("b2 init failed");
      exit (1);
    }

  const int expect[] =
    {
      15,     /* 1 2 3 */
      276,    /* 1 4 5 6 */
      120,    /* 1 7 8 */
      460     /* 1 2 9 10 */
    };

  long i;
  for (i = 0; i < 4; ++i)
    {
      global = 0;

      printf ("test %ld\n", i);

      pthread_t th;
      if (pthread_create (&th, NULL, tf, (void *) i) != 0)
       {
         puts ("create failed");
         exit (1);
       }

      int e = pthread_barrier_wait (&b2);
      if (e != 0 && e != PTHREAD_BARRIER_SERIAL_THREAD)
       {
         printf ("%s: barrier_wait failed\n", __FUNCTION__);
         exit (1);
       }

      pthread_cancel (th);

      void *r;
      if ((e = pthread_join (th, &r)) != 0)
       {
         printf ("join failed: %d\n", e);
         _exit (1);
       }

      if (r != PTHREAD_CANCELED)
       {
         puts ("thread not canceled");
         exit (1);
       }

      if (global != expect[i])
       {
         printf ("global = %d, expected %d\n", global, expect[i]);
         result = 1;
       }
    }

  return result;
}

Here is the call graph for this function:

void fn5 ( void  )

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

{
  /* This is the old LinuxThreads pthread_cleanup_{push,pop}.  */
     struct _pthread_cleanup_buffer b;
  _pthread_cleanup_push (&b, clh, (void *) 6l);

  fn4 ();

  _pthread_cleanup_pop (&b, 1);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void fn7 ( void  )

Definition at line 88 of file tst-cleanup4aux.c.

{
  /* This is the old LinuxThreads pthread_cleanup_{push,pop}.  */
     struct _pthread_cleanup_buffer b;
  _pthread_cleanup_push (&b, clh, (void *) 8l);

  fn6 ();

  _pthread_cleanup_pop (&b, 1);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void fn9 ( void  )

Definition at line 112 of file tst-cleanup4aux.c.

{
  /* This is the old LinuxThreads pthread_cleanup_{push,pop}.  */
     struct _pthread_cleanup_buffer b;
  _pthread_cleanup_push (&b, clh, (void *) 10l);

  fn8 ();

  _pthread_cleanup_pop (&b, 1);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void* tf ( void *  a) [static]

Definition at line 104 of file tst-cleanup4.c.

{
  switch ((long) a)
    {
    case 0:
      fn2 ();
      break;
    case 1:
      fn5 ();
      break;
    case 2:
      fn7 ();
      break;
    case 3:
      fn9 ();
      break;
    }

  return NULL;
}

Here is the call graph for this function:


Variable Documentation

pthread_barrier_t b2 [static]

Definition at line 33 of file tst-cleanup4.c.

int fds[2] [static]

Definition at line 32 of file tst-cleanup4.c.

int global [static]

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