![]() |
Helixis 1.0
Task Programming API
|
00001 #include "freelist_internal.h" 00002 #if defined(HLX_BUILD_WITH_PARALLEL_THREADING) 00003 00004 00005 00006 00007 /****************************************************************************/ 00008 void freelist_query( struct freelist_state *fs, enum freelist_query_type query_type, void *query_input, void *query_output ) 00009 { 00010 /* TRD : query type can be any value in its range */ 00011 /* TRD : query_input can be 0 in some cases */ 00012 00013 switch( query_type ) 00014 { 00015 case FREELIST_QUERY_ELEMENT_COUNT: 00016 00017 *(atom_t *) query_output = fs->element_count; 00018 break; 00019 00020 case FREELIST_QUERY_VALIDATE: 00021 /* TRD : query_input can be 0 */ 00022 00023 freelist_internal_validate( fs, (struct validation_info *) query_input, (enum data_structure_validity *) query_output ); 00024 break; 00025 } 00026 00027 return; 00028 } 00029 00030 00031 00032 00033 00034 /****************************************************************************/ 00035 void freelist_internal_validate( struct freelist_state *fs, struct validation_info *vi, enum data_structure_validity *freelist_validity ) 00036 { 00037 struct freelist_element 00038 *fe, 00039 *fe_slow, 00040 *fe_fast; 00041 00042 atom_t 00043 element_count = 0; 00044 00045 /* TRD : vi can be 0 */ 00046 00047 *freelist_validity = VALIDITY_VALID; 00048 00049 fe_slow = fe_fast = (struct freelist_element *) fs->top[FREELIST_POINTER]; 00050 00051 /* TRD : first, check for a loop 00052 we have two pointers 00053 both of which start at the top of the freelist 00054 we enter a loop 00055 and on each iteration 00056 we advance one pointer by one element 00057 and the other by two 00058 00059 we exit the loop when both pointers are 0 00060 (have reached the end of the freelist) 00061 00062 or 00063 00064 if we fast pointer 'sees' the slow pointer 00065 which means we have a loop 00066 */ 00067 00068 if( fe_slow != 0 ) 00069 do 00070 { 00071 fe_slow = fe_slow->next[FREELIST_POINTER]; 00072 00073 if( fe_fast != 0 ) 00074 fe_fast = fe_fast->next[FREELIST_POINTER]; 00075 00076 if( fe_fast != 0 ) 00077 fe_fast = fe_fast->next[FREELIST_POINTER]; 00078 } 00079 while( fe_slow != 0 and fe_fast != fe_slow ); 00080 00081 if( fe_fast != 0 and fe_slow != 0 and fe_fast == fe_slow ) 00082 *freelist_validity = VALIDITY_INVALID_LOOP; 00083 00084 /* TRD : now check for expected number of elements 00085 vi can be 0, in which case we do not check 00086 we know we don't have a loop from our earlier check 00087 */ 00088 00089 if( *freelist_validity == VALIDITY_VALID and vi != 0 ) 00090 { 00091 fe = (struct freelist_element *) fs->top[FREELIST_POINTER]; 00092 00093 while( fe != 0 ) 00094 { 00095 element_count++; 00096 fe = (struct freelist_element *) fe->next[FREELIST_POINTER]; 00097 } 00098 00099 if( element_count < vi->min_elements ) 00100 *freelist_validity = VALIDITY_INVALID_MISSING_ELEMENTS; 00101 00102 if( element_count > vi->max_elements ) 00103 *freelist_validity = VALIDITY_INVALID_ADDITIONAL_ELEMENTS; 00104 } 00105 00106 return; 00107 } 00108 00109 #endif /* !HLX_BUILD_WITH_PARALLEL_THREADING */