win-pvdrivers

view liblfds.6/src/single_dir_for_windows_kernel/freelist_query.c @ 1025:aa2e51f67f7c

Fix hibernate under Win8. Change debugprints.
author James Harper <james.harper@bendigoit.com.au>
date Tue Feb 19 15:14:53 2013 +1100 (2013-02-19)
parents 6300617040e0
children
line source
1 #include "freelist_internal.h"
7 /****************************************************************************/
8 void freelist_query( struct freelist_state *fs, enum freelist_query_type query_type, void *query_input, void *query_output )
9 {
10 assert( fs != NULL );
11 // TRD : query type can be any value in its range
12 // TRD : query_input can be NULL in some cases
13 assert( query_output != NULL );
15 switch( query_type )
16 {
17 case FREELIST_QUERY_ELEMENT_COUNT:
18 assert( query_input == NULL );
20 *(atom_t *) query_output = fs->element_count;
21 break;
23 case FREELIST_QUERY_VALIDATE:
24 // TRD : query_input can be NULL
26 freelist_internal_validate( fs, (struct validation_info *) query_input, (enum data_structure_validity *) query_output );
27 break;
28 }
30 return;
31 }
37 /****************************************************************************/
38 void freelist_internal_validate( struct freelist_state *fs, struct validation_info *vi, enum data_structure_validity *freelist_validity )
39 {
40 struct freelist_element
41 *fe,
42 *fe_slow,
43 *fe_fast;
45 atom_t
46 element_count = 0;
48 assert( fs != NULL );
49 // TRD : vi can be NULL
50 assert( freelist_validity != NULL );
52 *freelist_validity = VALIDITY_VALID;
54 fe_slow = fe_fast = (struct freelist_element *) fs->top[FREELIST_POINTER];
56 /* TRD : first, check for a loop
57 we have two pointers
58 both of which start at the top of the freelist
59 we enter a loop
60 and on each iteration
61 we advance one pointer by one element
62 and the other by two
64 we exit the loop when both pointers are NULL
65 (have reached the end of the freelist)
67 or
69 if we fast pointer 'sees' the slow pointer
70 which means we have a loop
71 */
73 if( fe_slow != NULL )
74 do
75 {
76 fe_slow = fe_slow->next[FREELIST_POINTER];
78 if( fe_fast != NULL )
79 fe_fast = fe_fast->next[FREELIST_POINTER];
81 if( fe_fast != NULL )
82 fe_fast = fe_fast->next[FREELIST_POINTER];
83 }
84 while( fe_slow != NULL and fe_fast != fe_slow );
86 if( fe_fast != NULL and fe_slow != NULL and fe_fast == fe_slow )
87 *freelist_validity = VALIDITY_INVALID_LOOP;
89 /* TRD : now check for expected number of elements
90 vi can be NULL, in which case we do not check
91 we know we don't have a loop from our earlier check
92 */
94 if( *freelist_validity == VALIDITY_VALID and vi != NULL )
95 {
96 fe = (struct freelist_element *) fs->top[FREELIST_POINTER];
98 while( fe != NULL )
99 {
100 element_count++;
101 fe = (struct freelist_element *) fe->next[FREELIST_POINTER];
102 }
104 if( element_count < vi->min_elements )
105 *freelist_validity = VALIDITY_INVALID_MISSING_ELEMENTS;
107 if( element_count > vi->max_elements )
108 *freelist_validity = VALIDITY_INVALID_ADDITIONAL_ELEMENTS;
109 }
111 return;
112 }