1 #include "lfds611_queue_internal.h"
\r
7 /****************************************************************************/
\r
8 #pragma warning( disable : 4100 )
\r
10 void lfds611_queue_query( struct lfds611_queue_state *qs, enum lfds611_queue_query_type query_type, void *query_input, void *query_output )
\r
12 assert( qs != NULL );
\r
13 // TRD : query_type can be any value in its range
\r
14 // TRD : query_input can be NULL
\r
15 assert( query_output != NULL );
\r
17 switch( query_type )
\r
19 case LFDS611_QUEUE_QUERY_ELEMENT_COUNT:
\r
20 assert( query_input == NULL );
\r
22 lfds611_freelist_query( qs->fs, LFDS611_FREELIST_QUERY_ELEMENT_COUNT, NULL, query_output );
\r
25 case LFDS611_QUEUE_QUERY_VALIDATE:
\r
26 // TRD : query_input can be NULL
\r
28 lfds611_queue_internal_validate( qs, (struct lfds611_validation_info *) query_input, (enum lfds611_data_structure_validity *) query_output, ((enum lfds611_data_structure_validity *) query_output)+1 );
\r
35 #pragma warning( default : 4100 )
\r
41 /****************************************************************************/
\r
42 void lfds611_queue_internal_validate( struct lfds611_queue_state *qs, struct lfds611_validation_info *vi, enum lfds611_data_structure_validity *lfds611_queue_validity, enum lfds611_data_structure_validity *lfds611_freelist_validity )
\r
44 struct lfds611_queue_element
\r
53 struct lfds611_validation_info
\r
54 lfds611_freelist_vi;
\r
56 assert( qs != NULL );
\r
57 // TRD : vi can be NULL
\r
58 assert( lfds611_queue_validity != NULL );
\r
59 assert( lfds611_freelist_validity != NULL );
\r
61 *lfds611_queue_validity = LFDS611_VALIDITY_VALID;
\r
63 LFDS611_BARRIER_LOAD;
\r
65 qe_slow = qe_fast = (struct lfds611_queue_element *) qs->dequeue[LFDS611_QUEUE_POINTER];
\r
67 /* TRD : first, check for a loop
\r
68 we have two pointers
\r
69 both of which start at the dequeue end of the lfds611_queue
\r
71 and on each iteration
\r
72 we advance one pointer by one element
\r
73 and the other by two
\r
75 we exit the loop when both pointers are NULL
\r
76 (have reached the end of the lfds611_queue)
\r
80 if we fast pointer 'sees' the slow pointer
\r
81 which means we have a loop
\r
84 if( qe_slow != NULL )
\r
87 qe_slow = qe_slow->next[LFDS611_QUEUE_POINTER];
\r
89 if( qe_fast != NULL )
\r
90 qe_fast = qe_fast->next[LFDS611_QUEUE_POINTER];
\r
92 if( qe_fast != NULL )
\r
93 qe_fast = qe_fast->next[LFDS611_QUEUE_POINTER];
\r
95 while( qe_slow != NULL and qe_fast != qe_slow );
\r
97 if( qe_fast != NULL and qe_slow != NULL and qe_fast == qe_slow )
\r
98 *lfds611_queue_validity = LFDS611_VALIDITY_INVALID_LOOP;
\r
100 /* TRD : now check for expected number of elements
\r
101 vi can be NULL, in which case we do not check
\r
102 we know we don't have a loop from our earlier check
\r
105 if( *lfds611_queue_validity == LFDS611_VALIDITY_VALID and vi != NULL )
\r
107 qe = (struct lfds611_queue_element *) qs->dequeue[LFDS611_QUEUE_POINTER];
\r
109 while( qe != NULL )
\r
112 qe = (struct lfds611_queue_element *) qe->next[LFDS611_QUEUE_POINTER];
\r
115 /* TRD : remember there is a dummy element in the lfds611_queue */
\r
118 if( element_count < vi->min_elements )
\r
119 *lfds611_queue_validity = LFDS611_VALIDITY_INVALID_MISSING_ELEMENTS;
\r
121 if( element_count > vi->max_elements )
\r
122 *lfds611_queue_validity = LFDS611_VALIDITY_INVALID_ADDITIONAL_ELEMENTS;
\r
125 /* TRD : now we validate the lfds611_freelist
\r
127 we may be able to check for the expected number of
\r
128 elements in the lfds611_freelist
\r
130 if the caller has given us an expected min and max
\r
131 number of elements in the lfds611_queue, then the total number
\r
132 of elements in the lfds611_freelist, minus that min and max,
\r
133 gives us the expected number of elements in the
\r
139 lfds611_freelist_query( qs->fs, LFDS611_FREELIST_QUERY_ELEMENT_COUNT, NULL, (void *) &total_elements );
\r
141 /* TRD : remember there is a dummy element in the lfds611_queue */
\r
144 lfds611_freelist_vi.min_elements = total_elements - vi->max_elements;
\r
145 lfds611_freelist_vi.max_elements = total_elements - vi->min_elements;
\r
147 lfds611_freelist_query( qs->fs, LFDS611_FREELIST_QUERY_VALIDATE, (void *) &lfds611_freelist_vi, (void *) lfds611_freelist_validity );
\r
151 lfds611_freelist_query( qs->fs, LFDS611_FREELIST_QUERY_VALIDATE, NULL, (void *) lfds611_freelist_validity );
\r