File: verify_queue.c

package info (click to toggle)
fis-gtm 6.2-000-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 30,784 kB
  • ctags: 42,554
  • sloc: ansic: 358,483; asm: 4,847; csh: 4,574; sh: 2,261; awk: 200; makefile: 86; sed: 13
file content (120 lines) | stat: -rw-r--r-- 3,105 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
/****************************************************************
 *								*
 *	Copyright 2001, 2005 Fidelity Information Services, Inc	*
 *								*
 *	This source code contains the intellectual property	*
 *	of its copyright holder(s), and is made available	*
 *	under a license.  If you do not know the terms of	*
 *	the license, please stop and do not read further.	*
 *								*
 ****************************************************************/

/* Routines to verify a simple double-linked queue.

   If we fail any of these tests, we will gtmassert in case a call to
   this routine is made from "pro" code. No messages are produced by
   this code since they would be useful only in the context of the
   dumped data and would scare the hell out of the user anyway.

   Two versions of this test are supplied. The first will lock the queue
   header first. The second assumes the queue is already locked.

   Most(All?) calls to this routine are compiled in by specifying the compile
   flag DEBUG_QUEUE.

*/

#include "mdef.h"


#ifdef UNIX
#include "aswp.h"
#endif
#include "gtm_facility.h"
#include "gdsroot.h"
#include "fileinfo.h"
#include "gdsbt.h"
#include "gdsbml.h"
#include "gdsblk.h"
#include "gdsfhead.h"
#include "filestruct.h"
#include "lockconst.h"
#include "interlock.h"
#include "wcs_backoff.h"

#ifdef QI_STARVATION
# undef QI_STARVATION
# undef QI_RETRY
#endif

#define QI_STARVATION 1000
#define QI_RETRY 256

GBLREF	volatile int4	fast_lock_count;
GBLREF	pid_t		process_id;
VMS_ONLY(GBLREF	uint4	image_count;)	/* Needed for GET/RELEASE_SWAPLOCK */

void verify_queue_lock(que_head_ptr_t qhdr)
{
	que_ent_ptr_t	qe, last_qe;
	int		i, k;
	boolean_t		got_lock;

	++fast_lock_count;

	/* Before we can play with the queue, we have to lock it
	   to prevent it from being changed out from underneath us */
	for (got_lock = FALSE, k = 0; k < QI_STARVATION; ++k)
	{
		for (i = 0; got_lock == FALSE && i < QI_RETRY; ++i)
			got_lock = GET_SWAPLOCK(&qhdr->latch);
		if (got_lock)
			break;
		if (0 != k)
			wcs_backoff(k);
	}

	if (!got_lock)			/* We gotta have our lock */
		GTMASSERT;

	/* Now run through queue. Verify the fwd and backward chain ptrs */
	last_qe = (que_ent_ptr_t)qhdr;
	for (qe = (que_ent_ptr_t)((sm_uc_ptr_t)qhdr + qhdr->fl);
	     qe != (que_ent_ptr_t)qhdr;
	     qe = (que_ent_ptr_t)((sm_uc_ptr_t)qe + qe->fl))
	{

		if ((que_ent_ptr_t)((sm_uc_ptr_t)qe + qe->bl) != last_qe)	/* Back pointer works good? */
		{
/*                      ASWP(&qhdr->latch, LOCK_AVAILABLE, latch); */
			GTMASSERT;
		}
		last_qe = qe;
	}

	/* Release locks */
	RELEASE_SWAPLOCK(&qhdr->latch);
	--fast_lock_count;

	return;
}


void verify_queue(que_head_ptr_t qhdr)
{
	que_ent_ptr_t	qe, last_qe;

	/* Now run through queue. Verify the fwd and backward chain ptrs */
	last_qe = (que_ent_ptr_t)qhdr;
	for (qe = (que_ent_ptr_t)((sm_uc_ptr_t)qhdr + qhdr->fl);
	     qe != (que_ent_ptr_t)qhdr;
	     qe = (que_ent_ptr_t)((sm_uc_ptr_t)qe + qe->fl))
	{

		if ((que_ent_ptr_t)((sm_uc_ptr_t)qe + qe->bl) != last_qe)	/* Back pointer works good? */
			GTMASSERT;
		last_qe = qe;
	}

	return;
}