|
Packit Service |
82fcde |
/* Copyright (C) 2010-2018 Free Software Foundation, Inc.
|
|
Packit Service |
82fcde |
This file is part of the GNU C Library.
|
|
Packit Service |
82fcde |
Contributed by Andreas Schwab <schwab@redhat.com>, 2010.
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
The GNU C Library is free software; you can redistribute it and/or
|
|
Packit Service |
82fcde |
modify it under the terms of the GNU Lesser General Public
|
|
Packit Service |
82fcde |
License as published by the Free Software Foundation; either
|
|
Packit Service |
82fcde |
version 2.1 of the License, or (at your option) any later version.
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
The GNU C Library is distributed in the hope that it will be useful,
|
|
Packit Service |
82fcde |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit Service |
82fcde |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit Service |
82fcde |
Lesser General Public License for more details.
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
You should have received a copy of the GNU Lesser General Public
|
|
Packit Service |
82fcde |
License along with the GNU C Library; if not, see
|
|
Packit Service |
82fcde |
<http://www.gnu.org/licenses/>. */
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
#include <errno.h>
|
|
Packit Service |
82fcde |
#include <pthread.h>
|
|
Packit Service |
82fcde |
#include <semaphore.h>
|
|
Packit Service |
82fcde |
#include <stdio.h>
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
static pthread_cond_t c = PTHREAD_COND_INITIALIZER;
|
|
Packit Service |
82fcde |
static pthread_mutex_t m1 = PTHREAD_MUTEX_INITIALIZER;
|
|
Packit Service |
82fcde |
static pthread_mutex_t m2 = PTHREAD_MUTEX_INITIALIZER;
|
|
Packit Service |
82fcde |
static pthread_rwlock_t rw1 = PTHREAD_RWLOCK_INITIALIZER;
|
|
Packit Service |
82fcde |
static pthread_rwlock_t rw2 = PTHREAD_RWLOCK_INITIALIZER;
|
|
Packit Service |
82fcde |
static sem_t sem;
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
static void *
|
|
Packit Service |
82fcde |
th (void *arg)
|
|
Packit Service |
82fcde |
{
|
|
Packit Service |
82fcde |
long int res = 0;
|
|
Packit Service |
82fcde |
int r;
|
|
Packit Service |
82fcde |
struct timespec t = { -2, 0 };
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
r = pthread_mutex_timedlock (&m1, &t);
|
|
Packit Service |
82fcde |
if (r != ETIMEDOUT)
|
|
Packit Service |
82fcde |
{
|
|
Packit Service |
82fcde |
puts ("pthread_mutex_timedlock did not return ETIMEDOUT");
|
|
Packit Service |
82fcde |
res = 1;
|
|
Packit Service |
82fcde |
}
|
|
Packit Service |
82fcde |
r = pthread_rwlock_timedrdlock (&rw1, &t);
|
|
Packit Service |
82fcde |
if (r != ETIMEDOUT)
|
|
Packit Service |
82fcde |
{
|
|
Packit Service |
82fcde |
puts ("pthread_rwlock_timedrdlock did not return ETIMEDOUT");
|
|
Packit Service |
82fcde |
res = 1;
|
|
Packit Service |
82fcde |
}
|
|
Packit Service |
82fcde |
r = pthread_rwlock_timedwrlock (&rw2, &t);
|
|
Packit Service |
82fcde |
if (r != ETIMEDOUT)
|
|
Packit Service |
82fcde |
{
|
|
Packit Service |
82fcde |
puts ("pthread_rwlock_timedwrlock did not return ETIMEDOUT");
|
|
Packit Service |
82fcde |
res = 1;
|
|
Packit Service |
82fcde |
}
|
|
Packit Service |
82fcde |
return (void *) res;
|
|
Packit Service |
82fcde |
}
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
static int
|
|
Packit Service |
82fcde |
do_test (void)
|
|
Packit Service |
82fcde |
{
|
|
Packit Service |
82fcde |
int res = 0;
|
|
Packit Service |
82fcde |
int r;
|
|
Packit Service |
82fcde |
struct timespec t = { -2, 0 };
|
|
Packit Service |
82fcde |
pthread_t pth;
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
sem_init (&sem, 0, 0);
|
|
Packit Service |
82fcde |
r = sem_timedwait (&sem, &t);
|
|
Packit Service |
82fcde |
if (r != -1 || errno != ETIMEDOUT)
|
|
Packit Service |
82fcde |
{
|
|
Packit Service |
82fcde |
puts ("sem_timedwait did not fail with ETIMEDOUT");
|
|
Packit Service |
82fcde |
res = 1;
|
|
Packit Service |
82fcde |
}
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
pthread_mutex_lock (&m1;;
|
|
Packit Service |
82fcde |
pthread_rwlock_wrlock (&rw1);
|
|
Packit Service |
82fcde |
pthread_rwlock_rdlock (&rw2);
|
|
Packit Service |
82fcde |
pthread_mutex_lock (&m2;;
|
|
Packit Service |
82fcde |
if (pthread_create (&pth, 0, th, 0) != 0)
|
|
Packit Service |
82fcde |
{
|
|
Packit Service |
82fcde |
puts ("cannot create thread");
|
|
Packit Service |
82fcde |
return 1;
|
|
Packit Service |
82fcde |
}
|
|
Packit Service |
82fcde |
r = pthread_cond_timedwait (&c, &m2, &t);
|
|
Packit Service |
82fcde |
if (r != ETIMEDOUT)
|
|
Packit Service |
82fcde |
{
|
|
Packit Service |
82fcde |
puts ("pthread_cond_timedwait did not return ETIMEDOUT");
|
|
Packit Service |
82fcde |
res = 1;
|
|
Packit Service |
82fcde |
}
|
|
Packit Service |
82fcde |
void *thres;
|
|
Packit Service |
82fcde |
pthread_join (pth, &thres);
|
|
Packit Service |
82fcde |
return res | (thres != NULL);
|
|
Packit Service |
82fcde |
}
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
#define TEST_FUNCTION do_test ()
|
|
Packit Service |
82fcde |
#include "../test-skeleton.c"
|