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 pthread_spin_destroy(pthread_spinlock_t * lock)
8 *
9 * pthread_spin_destroy( ) function shall destroy the spin lock
10 * referenced by lock and release any resources used by the lock.
11 *
12 * Steps:
13 * 1.  Initialize a pthread_spinlock_t object 'spinlock' with
14 *     pthread_spin_init()
15 * 2.  Main thread lock 'spinlock', should get the lock
16 * 3.  Main thread unlock 'spinlock'
17 * 4.  Main thread destroy the 'spinlock'
18 */
19
20#define _XOPEN_SOURCE 600
21#include <pthread.h>
22#include <stdio.h>
23#include <stdlib.h>
24#include <unistd.h>
25#include <signal.h>
26#include "posixtest.h"
27
28static pthread_spinlock_t spinlock;
29
30int main()
31{
32	int rc = 0;
33
34	printf("main: initialize spin lock\n");
35	if(pthread_spin_init(&spinlock, PTHREAD_PROCESS_PRIVATE) != 0)
36	{
37		printf("main: Error at pthread_spin_init()\n");
38		return PTS_UNRESOLVED;
39	}
40
41	printf("main: attempt spin lock\n");
42
43	/* We should get the lock */
44	if(pthread_spin_lock(&spinlock) != 0)
45	{
46		printf("Unresolved: main cannot get spin lock when no one owns the lock\n");
47		return PTS_UNRESOLVED;
48	}
49
50	printf("main: acquired spin lock\n");
51
52	printf("main: unlock spin lock\n");
53	if(pthread_spin_unlock(&spinlock) != 0)
54	{
55		printf("main: Error at pthread_spin_unlock()\n");
56		return PTS_UNRESOLVED;
57	}
58
59	printf("main: destroy spin lock\n");
60	rc = pthread_spin_destroy(&spinlock);
61	if(rc != 0)
62	{
63		printf("Test FAILED: Error at pthread_spin_destroy()"
64			"Return code : %d\n", rc);
65		return PTS_FAIL;
66	}
67
68	printf("Test PASSED\n");
69	return PTS_PASS;
70}
71