Changeset 657 for trunk/kernel/libk/xhtab.c
- Timestamp:
- Mar 18, 2020, 11:16:59 PM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/kernel/libk/xhtab.c
r635 r657 53 53 54 54 return (name[0] % XHASHTAB_SIZE); 55 /*56 uint32_t index = 0;57 while( *name )58 {59 index = index + (*(name++) ^ index);60 }61 return index % XHASHTAB_SIZE;62 */63 64 55 } 65 56 … … 128 119 //////////////////////////////////////////////////////////////////////////////////////// 129 120 130 ////////////////////////////////////////// 131 void xhtab_init( x htab_t * xhtab,121 ///////////////////////////////////////////// 122 void xhtab_init( xptr_t xhtab_xp, 132 123 xhtab_item_type_t type ) 133 124 { 134 uint32_t i; 125 uint32_t i; 126 127 // get cluster and local pointer 128 xhtab_t * ptr = GET_PTR( xhtab_xp ); 129 cxy_t cxy = GET_CXY( xhtab_xp ); 135 130 136 131 // initialize lock 137 remote_busylock_init( XPTR( local_cxy , &xhtab->lock), LOCK_XHTAB_STATE ); 138 139 xhtab->items = 0; 140 xhtab->current_index = 0; 141 xhtab->current_xlist_xp = XPTR_NULL; 142 132 remote_busylock_init( XPTR( cxy , &ptr->lock), LOCK_XHTAB_STATE ); 133 134 // initialise various fiels 135 hal_remote_s32( XPTR( cxy , &ptr->items ) , 0 ); 136 hal_remote_s32( XPTR( cxy , &ptr->current_index ) , 0 ); 137 hal_remote_s64( XPTR( cxy , &ptr->current_xlist_xp ) , XPTR_NULL ); 138 139 // initialize functions pointers 143 140 if( type == XHTAB_DENTRY_TYPE ) 144 141 { 145 xhtab->item_match_key = &xhtab_dentry_item_match_key;146 xhtab->index_from_key = &xhtab_dentry_index_from_key;147 xhtab->item_from_xlist = &xhtab_dentry_item_from_xlist;148 xhtab->item_print_key = &xhtab_dentry_item_print_key;142 hal_remote_spt( XPTR( cxy , &ptr->item_match_key ) , &xhtab_dentry_item_match_key ); 143 hal_remote_spt( XPTR( cxy , &ptr->index_from_key ) , &xhtab_dentry_index_from_key ); 144 hal_remote_spt( XPTR( cxy , &ptr->item_from_xlist ) , &xhtab_dentry_item_from_xlist ); 145 hal_remote_spt( XPTR( cxy , &ptr->item_print_key ) , &xhtab_dentry_item_print_key ); 149 146 } 150 147 else … … 153 150 } 154 151 152 // initialize all lists 153 for( i=0 ; i < XHASHTAB_SIZE ; i++ ) 154 { 155 xlist_root_init( XPTR( cxy , &ptr->roots[i] ) ); 156 } 157 155 158 #if DEBUG_XHTAB 156 159 printk("\n[%s] for xhtab (%x,%x)\n" 157 " - index_from_key = %x (@ %x)\n" 158 " - item_match_key = %x (@ %x)\n" 159 " - item_from_xlist = %x (@ %x)\n", 160 __FUNCTION__, local_cxy, xhtab, 161 xhtab->index_from_key , &xhtab->index_from_key, 162 xhtab->item_match_key , &xhtab->item_match_key, 163 xhtab->item_from_xlist, &xhtab->item_from_xlist ); 164 #endif 165 166 for( i=0 ; i < XHASHTAB_SIZE ; i++ ) 167 { 168 xlist_root_init( XPTR( local_cxy , &xhtab->roots[i] ) ); 169 170 #if (DEBUG_XHTAB & 1) 171 printk("\n - initialize root[%d] / %x\n", i , &xhtab->roots[i] ); 172 #endif 173 174 } 160 " - index_from_key = %x\n" 161 " - item_match_key = %x\n" 162 " - item_from_xlist = %x\n", 163 __FUNCTION__, cxy, ptr, 164 hal_remote_lpt( XPTR( cxy , &ptr->index_from_key ) ), 165 hal_remote_lpt( XPTR( cxy , &ptr->item_match_key ) ), 166 hal_remote_lpt( XPTR( cxy , &ptr->item_from_xlist ) ) ); 167 #endif 175 168 176 169 } // end xhtab_init() … … 200 193 xhtab_ptr = GET_PTR( xhtab_xp ); 201 194 195 #if DEBUG_XHTAB 196 printk("\n[%s] enter : index = %d / key = %s\n", __FUNCTION__ , index , key ); 197 #endif 198 202 199 // get pointer on "item_from_xlist" function 203 200 item_from_xlist = (item_from_xlist_t *)hal_remote_lpt( XPTR( xhtab_cxy , … … 206 203 item_match_key = (item_match_key_t *)hal_remote_lpt( XPTR( xhtab_cxy , 207 204 &xhtab_ptr->item_match_key ) ); 208 209 205 // scan sub-list[index] 210 206 XLIST_FOREACH( XPTR( xhtab_cxy , &xhtab_ptr->roots[index] ) , xlist_xp ) … … 216 212 if( item_match_key( item_xp , key ) ) return item_xp; 217 213 } 214 215 #if DEBUG_XHTAB 216 printk("\n[%s] exit\n", __FUNCTION__ ); 217 #endif 218 218 219 219 220 // No matching item found … … 248 249 index_from_key = (index_from_key_t *)hal_remote_lpt( XPTR( xhtab_cxy , 249 250 &xhtab_ptr->index_from_key ) ); 250 #if DEBUG_XHTAB251 printk("\n[%s] remote = %x / direct = %x / @ = %x\n",252 __FUNCTION__, index_from_key, xhtab_ptr->index_from_key, &xhtab_ptr->index_from_key );253 #endif254 255 251 // compute index from key 256 252 index = index_from_key( key ); 257 258 #if DEBUG_XHTAB259 printk("\n[%s] index = %x\n", __FUNCTION__, index );260 #endif261 253 262 254 // take the lock protecting hash table … … 285 277 286 278 #if DEBUG_XHTAB 287 printk("\n[%s] success /<%s>\n", __FUNCTION__, key );279 printk("\n[%s] success for <%s>\n", __FUNCTION__, key ); 288 280 #endif 289 281 … … 362 354 363 355 #if DEBUG_XHTAB 364 printk("\n[%s] enter / %s\n", __FUNCTION__, key);356 printk("\n[%s] enter\n", __FUNCTION__ ); 365 357 #endif 366 358 … … 368 360 remote_busylock_acquire( XPTR( xhtab_cxy , &xhtab_ptr->lock ) ); 369 361 370 #if DEBUG_XHTAB371 printk("\n[%s] after lock acquire / %s\n", __FUNCTION__, key );372 #endif373 374 362 // scan sub-list 375 363 item_xp = xhtab_scan( xhtab_xp , index , key ); 376 364 377 #if DEBUG_XHTAB378 printk("\n[%s] after xhtab scan / %s\n", __FUNCTION__, key );379 #endif380 381 365 // release the lock protecting hash table 382 366 remote_busylock_release( XPTR( xhtab_cxy , &xhtab_ptr->lock ) ); 383 367 384 368 #if DEBUG_XHTAB 385 printk("\n[%s] after lock release / %s\n", __FUNCTION__, key);369 printk("\n[%s] exit\n", __FUNCTION__ ); 386 370 #endif 387 371
Note: See TracChangeset
for help on using the changeset viewer.