1/*
2 * Copyright (c) 2002, Intel Corporation. All rights reserved.
3 * This file is licensed under the GPL license.  For the full content
4 * of this license, see the COPYING file at the top level of this
5 * source tree.
6
7 * Test that pthread_rwlock_rdlock(pthread_rwlock_t *rwlock)
8 *
9 *	A thread may hold multiple concurrent read locks on 'rwlock' and the application shall
10 *	ensure that the thread will perform matching unlocks for each read lock.
11 *
12 * Steps:
13 * 1.  Initialize a pthread_rwlock_t object 'rwlock' with pthread_rwlock_init()
14 * 2.  Main read locks 'rwlock' 10 times
15 * 3.  Main unlocks 'rwlock' 10 times.
16 *
17 */
18#define _XOPEN_SOURCE 600
19#include <pthread.h>
20#include <stdio.h>
21#include <stdlib.h>
22#include <unistd.h>
23#include "posixtest.h"
24
25#define COUNT 10
26
27int main()
28{
29
30	static pthread_rwlock_t rwlock;
31	int i;
32
33	if(pthread_rwlock_init(&rwlock, NULL) != 0)
34	{
35		printf("main: Error at pthread_rwlock_init()\n");
36		return PTS_UNRESOLVED;
37	}
38
39	for(i=0;i < COUNT;i++)
40	{
41		if(pthread_rwlock_rdlock(&rwlock) != 0)
42		{
43			printf("Test FAILED: main cannot get read-lock rwlock number: %d\n", i);
44			return PTS_FAIL;
45		}
46	}
47
48	for(i = 0;i < COUNT;i++)
49	{
50		if(pthread_rwlock_unlock(&rwlock) != 0)
51		{
52			printf("Test FAILED: main cannot unlock rwlock number %d", i);
53			return PTS_FAIL;
54		}
55	}
56
57
58	if(pthread_rwlock_destroy(&rwlock) != 0)
59	{
60		printf("Error at pthread_rwlockattr_destroy()");
61		return PTS_UNRESOLVED;
62	}
63
64	printf("Test PASSED\n");
65	return PTS_PASS;
66}
67