Back to index

glibc  2.9
Defines | Functions | Variables
tst-rwlock14.c File Reference
#include <errno.h>
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include "../test-skeleton.c"

Go to the source code of this file.

Defines

#define TEST_FUNCTION   do_test ()

Functions

static void * tf (void *arg)
static int do_test (void)

Variables

static pthread_barrier_t b
static pthread_rwlock_t r = PTHREAD_RWLOCK_INITIALIZER

Define Documentation

#define TEST_FUNCTION   do_test ()

Definition at line 168 of file tst-rwlock14.c.


Function Documentation

static int do_test ( void  ) [static]

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

{
  int result = 0;
  struct timespec ts;

  if (clock_gettime (CLOCK_REALTIME, &ts) != 0)
    {
      puts ("clock_gettime failed");
      return 1;
    }

  if (pthread_barrier_init (&b, NULL, 2) != 0)
    {
      puts ("barrier_init failed");
      return 1;
    }

  pthread_t me = pthread_self ();
  pthread_t th;
  if (pthread_create (&th, NULL, tf, &me) != 0)
    {
      puts ("create failed");
      return 1;
    }

  /* Wait until the rwlock is locked.  */
  pthread_barrier_wait (&b);

  ts.tv_nsec = -1;

  int e = pthread_rwlock_timedrdlock (&r, &ts);
  if (e == 0)
    {
      puts ("first rwlock_timedrdlock did not fail");
      result = 1;
    }
  else if (e != EINVAL)
    {
      puts ("first rwlock_timedrdlock did not return EINVAL");
      result = 1;
    }

  e = pthread_rwlock_timedwrlock (&r, &ts);
  if (e == 0)
    {
      puts ("first rwlock_timedwrlock did not fail");
      result = 1;
    }
  else if (e != EINVAL)
    {
      puts ("first rwlock_timedwrlock did not return EINVAL");
      result = 1;
    }

  ts.tv_nsec = 1000000000;

  e = pthread_rwlock_timedrdlock (&r, &ts);
  if (e == 0)
    {
      puts ("second rwlock_timedrdlock did not fail");
      result = 1;
    }
  else if (e != EINVAL)
    {
      puts ("second rwlock_timedrdlock did not return EINVAL");
      result = 1;
    }

  e = pthread_rwlock_timedrdlock (&r, &ts);
  if (e == 0)
    {
      puts ("second rwlock_timedrdlock did not fail");
      result = 1;
    }
  else if (e != EINVAL)
    {
      puts ("second rwlock_timedrdlock did not return EINVAL");
      result = 1;
    }

  ts.tv_nsec = (__typeof (ts.tv_nsec)) 0x100001000LL;
  if ((__typeof (ts.tv_nsec)) 0x100001000LL != 0x100001000LL)
    ts.tv_nsec = 2000000000;

  e = pthread_rwlock_timedrdlock (&r, &ts);
  if (e == 0)
    {
      puts ("third rwlock_timedrdlock did not fail");
      result = 1;
    }
  else if (e != EINVAL)
    {
      puts ("third rwlock_timedrdlock did not return EINVAL");
      result = 1;
    }

  e = pthread_rwlock_timedrdlock (&r, &ts);
  if (e == 0)
    {
      puts ("third rwlock_timedrdlock did not fail");
      result = 1;
    }
  else if (e != EINVAL)
    {
      puts ("third rwlock_timedrdlock did not return EINVAL");
      result = 1;
    }

  if (result == 0)
    puts ("no bugs");

  return result;
}

Here is the call graph for this function:

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

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

{
  /* Lock the read-write lock.  */
  if (pthread_rwlock_wrlock (&r) != 0)
    {
      puts ("tf: cannot lock rwlock");
      exit (EXIT_FAILURE);
    }

  pthread_t mt = *(pthread_t *) arg;

  pthread_barrier_wait (&b);

  /* This call will never return.  */
  pthread_join (mt, NULL);

  return NULL;
}

Here is the call graph for this function:


Variable Documentation

pthread_barrier_t b [static]

Definition at line 27 of file tst-rwlock14.c.

pthread_rwlock_t r = PTHREAD_RWLOCK_INITIALIZER [static]

Definition at line 28 of file tst-rwlock14.c.