Changeset 635 for trunk/kernel/libk/xhtab.c
- Timestamp:
- Jun 26, 2019, 11:42:37 AM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/kernel/libk/xhtab.c
r614 r635 2 2 * xhtab.c - Remote access embedded hash table implementation. 3 3 * 4 * Author Alain Greiner (2016,2017)4 * Author Alain Greiner (2016,2017,2018,2019) 5 5 * 6 6 * Copyright (c) UPMC Sorbonne Universites … … 134 134 uint32_t i; 135 135 136 // initialize readlock136 // initialize lock 137 137 remote_busylock_init( XPTR( local_cxy , &xhtab->lock), LOCK_XHTAB_STATE ); 138 138 … … 153 153 } 154 154 155 for( i=0 ; i < XHASHTAB_SIZE ; i++ ) 156 { 157 xlist_root_init( XPTR( local_cxy , &xhtab->roots[i] ) ); 158 } 159 160 #if DEBUG_XHTAB 161 printk("\n@@@ %s for xhtab (%x,%x)\n" 155 #if DEBUG_XHTAB 156 printk("\n[%s] for xhtab (%x,%x)\n" 162 157 " - index_from_key = %x (@ %x)\n" 163 158 " - item_match_key = %x (@ %x)\n" … … 169 164 #endif 170 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 } 175 171 176 } // end xhtab_init() 172 177 173 ////////////////////////////////////// 174 xptr_t xhtab_scan( xptr_t xhtab_xp, 175 uint32_t index, 176 void * key ) 178 ///////////////////////////////////////////////////////////////////////////////////////////// 179 // This static function traverse the subset identified by the <index> argument 180 // to find an item identified by the <key> argument. 181 ///////////////////////////////////////////////////////////////////////////////////////////// 182 // @ xhtab_xp : extended pointer on the xhtab descriptor. 183 // @ index : subset index. 184 // @ key : searched key value. 185 // @ return extended pointer on the found item if success / return XPTR_NULL if not found. 186 ///////////////////////////////////////////////////////////////////////////////////////////// 187 static xptr_t xhtab_scan( xptr_t xhtab_xp, 188 uint32_t index, 189 void * key ) 177 190 { 178 191 xptr_t xlist_xp; // xlist_entry_t (iterator) … … 220 233 index_from_key_t * index_from_key; // function pointer 221 234 222 #if DEBUG_XHTAB 223 printk("\n[%s] enter / key %s\n", __FUNCTION__, key ); 224 #endif 225 226 // get xhtab cluster and local pointer 227 xhtab_cxy = GET_CXY( xhtab_xp ); 228 xhtab_ptr = GET_PTR( xhtab_xp ); 235 // get xhtab cluster and local pointer 236 xhtab_cxy = GET_CXY( xhtab_xp ); 237 xhtab_ptr = GET_PTR( xhtab_xp ); 238 239 #if DEBUG_XHTAB 240 printk("\n[%s] enter / xhtab (%x,%x) / key = <%s> / cycle %d\n", 241 __FUNCTION__, xhtab_cxy, xhtab_ptr, key, (uint32_t)hal_get_cycles() ); 242 #endif 243 244 // build extended pointer on xhtab lock 245 xptr_t lock_xp = XPTR( xhtab_cxy , &xhtab_ptr->lock ); 229 246 230 247 // get pointer on "index_from_key" function 231 248 index_from_key = (index_from_key_t *)hal_remote_lpt( XPTR( xhtab_cxy , 232 249 &xhtab_ptr->index_from_key ) ); 250 #if DEBUG_XHTAB 251 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 #endif 254 233 255 // compute index from key 234 256 index = index_from_key( key ); 235 257 258 #if DEBUG_XHTAB 259 printk("\n[%s] index = %x\n", __FUNCTION__, index ); 260 #endif 261 236 262 // take the lock protecting hash table 237 remote_busylock_acquire( XPTR( xhtab_cxy , &xhtab_ptr->lock ));238 239 // search a matching item 263 remote_busylock_acquire( lock_xp ); 264 265 // search a matching item in subset 240 266 item_xp = xhtab_scan( xhtab_xp , index , key ); 241 267 242 if( item_xp != XPTR_NULL ) // error if found268 if( item_xp != XPTR_NULL ) // error if item already registered 243 269 { 244 270 // release the lock protecting hash table 245 remote_busylock_release( XPTR( xhtab_cxy , &xhtab_ptr->lock ));271 remote_busylock_release( lock_xp ); 246 272 247 273 return -1; … … 256 282 257 283 // release the lock protecting hash table 258 remote_busylock_release( XPTR( xhtab_cxy , &xhtab_ptr->lock ));284 remote_busylock_release( lock_xp ); 259 285 260 286 #if DEBUG_XHTAB 261 printk("\n[%s] success / %s\n", __FUNCTION__, key );287 printk("\n[%s] success / <%s>\n", __FUNCTION__, key ); 262 288 #endif 263 289
Note: See TracChangeset
for help on using the changeset viewer.