Changeset 563 for trunk/kernel/libk/xhtab.c
- Timestamp:
- Oct 4, 2018, 11:16:13 PM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/kernel/libk/xhtab.c
r492 r563 27 27 #include <hal_remote.h> 28 28 #include <xlist.h> 29 #include <remote_ rwlock.h>29 #include <remote_busylock.h> 30 30 #include <string.h> 31 31 #include <printk.h> … … 35 35 36 36 /////////////////////////////////////////////////////////////////////////////////////////// 37 // Item type specific functions (three functions for each item type). 38 /////////////////////////////////////////////////////////////////////////////////////////// 39 40 /////////////////////////////////////////////////////////////////////////////////////////// 41 // This functions compute the hash index from the key when item is a vfs_dentry_t. 42 // The key is the directory entry name. 37 // Item type specific functions (four functions for each item type). 38 // Example below is for <vfs_dentry_t> where the identifier is the dentry name. 39 /////////////////////////////////////////////////////////////////////////////////////////// 40 41 /////////////////////////////////////////////////////////////////////////////////////////// 42 // vfs_dentry_t 43 // This functions compute the hash index from the key, that is the directory entry name. 43 44 /////////////////////////////////////////////////////////////////////////////////////////// 44 45 // @ key : local pointer on name. … … 57 58 58 59 /////////////////////////////////////////////////////////////////////////////////////////// 60 // vfs_dentry_t 59 61 // This functions returns the extended pointer on the item, from the extended pointer 60 // on xlist contained in the item , when the item is a vfs_entry_t.62 // on xlist contained in the item. 61 63 /////////////////////////////////////////////////////////////////////////////////////////// 62 64 // @ xlist_xp : extended pointer on embedded xlist entry. … … 69 71 70 72 //////////////////////////////////////////////////////////////////////////////////////////// 71 // This function compare the identifier of an item to a given <key>. For a vfs_entry_t, 73 // vfs_dentry_t 74 // This function compares the identifier of an item to a given <key>. 72 75 // it returns true when the directory name matches the name pointed by the <key> argument. 73 76 //////////////////////////////////////////////////////////////////////////////////////////// … … 83 86 // get dentry cluster and local pointer 84 87 cxy_t dentry_cxy = GET_CXY( item_xp ); 85 vfs_dentry_t * dentry_ptr = (vfs_dentry_t *)GET_PTR( item_xp );88 vfs_dentry_t * dentry_ptr = GET_PTR( item_xp ); 86 89 87 90 // make a local copy of directory entry name … … 93 96 94 97 //////////////////////////////////////////////////////////////////////////////////////////// 95 // This function print the item key, that is the name for a vfs_entry_t, 98 // vfs_dentry_t 99 // This function print the item key, that is the name for a vfs_dentry_t. 96 100 //////////////////////////////////////////////////////////////////////////////////////////// 97 101 // @ item_xp : extended pointer on item. … … 103 107 // get dentry cluster and local pointer 104 108 cxy_t dentry_cxy = GET_CXY( item_xp ); 105 vfs_dentry_t * dentry_ptr = (vfs_dentry_t *)GET_PTR( item_xp );109 vfs_dentry_t * dentry_ptr = GET_PTR( item_xp ); 106 110 107 111 // make a local copy of directory entry name … … 124 128 125 129 // initialize readlock 126 remote_ rwlock_init( XPTR( local_cxy , &xhtab->lock));130 remote_busylock_init( XPTR( local_cxy , &xhtab->lock), LOCK_XHTAB_STATE ); 127 131 128 132 xhtab->items = 0; … … 163 167 // get hash table cluster and local pointer 164 168 xhtab_cxy = GET_CXY( xhtab_xp ); 165 xhtab_ptr = (xhtab_t *)GET_PTR( xhtab_xp );169 xhtab_ptr = GET_PTR( xhtab_xp ); 166 170 167 171 // get pointer on "item_from_xlist" function … … 198 202 index_from_key_t * index_from_key; // function pointer 199 203 200 // get xhtab cluster and local pointer 201 xhtab_cxy = GET_CXY( xhtab_xp ); 202 xhtab_ptr = (xhtab_t *)GET_PTR( xhtab_xp ); 204 #if DEBUG_XHTAB 205 printk("\n[DBG] %s : enter / %s\n", __FUNCTION__, key ); 206 #endif 207 208 // get xhtab cluster and local pointer 209 xhtab_cxy = GET_CXY( xhtab_xp ); 210 xhtab_ptr = GET_PTR( xhtab_xp ); 203 211 204 212 // get pointer on "index_from_key" function … … 209 217 210 218 // take the lock protecting hash table 211 remote_ rwlock_wr_lock( XPTR( xhtab_cxy , &xhtab_ptr->lock ) );219 remote_busylock_acquire( XPTR( xhtab_cxy , &xhtab_ptr->lock ) ); 212 220 213 221 // search a matching item … … 217 225 { 218 226 // release the lock protecting hash table 219 remote_ rwlock_wr_unlock( XPTR( xhtab_cxy , &xhtab_ptr->lock ) );227 remote_busylock_release( XPTR( xhtab_cxy , &xhtab_ptr->lock ) ); 220 228 221 229 return EINVAL; … … 230 238 231 239 // release the lock protecting hash table 232 remote_rwlock_wr_unlock( XPTR( xhtab_cxy , &xhtab_ptr->lock ) ); 240 remote_busylock_release( XPTR( xhtab_cxy , &xhtab_ptr->lock ) ); 241 242 #if DEBUG_XHTAB 243 printk("\n[DBG] %s : success / %s\n", __FUNCTION__, key ); 244 #endif 233 245 234 246 return 0; … … 249 261 // get xhtab cluster and local pointer 250 262 xhtab_cxy = GET_CXY( xhtab_xp ); 251 xhtab_ptr = (xhtab_t *)GET_PTR( xhtab_xp );263 xhtab_ptr = GET_PTR( xhtab_xp ); 252 264 253 265 // get pointer on "index_from_key" function … … 258 270 259 271 // take the lock protecting hash table 260 remote_ rwlock_wr_lock( XPTR( xhtab_cxy , &xhtab_ptr->lock ) );272 remote_busylock_acquire( XPTR( xhtab_cxy , &xhtab_ptr->lock ) ); 261 273 262 274 // get extended pointer on item to remove … … 266 278 { 267 279 // release the lock protecting hash table 268 remote_ rwlock_wr_unlock( XPTR( xhtab_cxy , &xhtab_ptr->lock ) );280 remote_busylock_release( XPTR( xhtab_cxy , &xhtab_ptr->lock ) ); 269 281 270 282 return EINVAL; … … 279 291 280 292 // release the lock protecting hash table 281 remote_ rwlock_wr_unlock( XPTR( xhtab_cxy , &xhtab_ptr->lock ) );293 remote_busylock_release( XPTR( xhtab_cxy , &xhtab_ptr->lock ) ); 282 294 283 295 return 0; … … 297 309 // get xhtab cluster and local pointer 298 310 xhtab_cxy = GET_CXY( xhtab_xp ); 299 xhtab_ptr = (xhtab_t *)GET_PTR( xhtab_xp );311 xhtab_ptr = GET_PTR( xhtab_xp ); 300 312 301 313 // get pointer on "index_from_key" function … … 304 316 // compute index from key 305 317 index = index_from_key( key ); 318 319 #if DEBUG_XHTAB 320 printk("\n[DBG] %s : enter / %s\n", __FUNCTION__, key ); 321 #endif 306 322 307 323 // take the lock protecting hash table 308 remote_rwlock_rd_lock( XPTR( xhtab_cxy , &xhtab_ptr->lock ) ); 324 remote_busylock_acquire( XPTR( xhtab_cxy , &xhtab_ptr->lock ) ); 325 326 #if DEBUG_XHTAB 327 printk("\n[DBG] %s : after lock acquire / %s\n", __FUNCTION__, key ); 328 #endif 309 329 310 330 // scan sub-list 311 331 item_xp = xhtab_scan( xhtab_xp , index , key ); 312 332 333 #if DEBUG_XHTAB 334 printk("\n[DBG] %s : after xhtab scan / %s\n", __FUNCTION__, key ); 335 #endif 336 313 337 // release the lock protecting hash table 314 remote_rwlock_rd_unlock( XPTR( xhtab_cxy , &xhtab_ptr->lock ) ); 338 remote_busylock_release( XPTR( xhtab_cxy , &xhtab_ptr->lock ) ); 339 340 #if DEBUG_XHTAB 341 printk("\n[DBG] %s : after lock release / %s\n", __FUNCTION__, key ); 342 #endif 315 343 316 344 return item_xp; … … 318 346 } // end xhtab_lookup() 319 347 320 ////////////////////////////////// /////321 void xhtab_ read_lock( xptr_t xhtab_xp )348 ////////////////////////////////// 349 void xhtab_lock( xptr_t xhtab_xp ) 322 350 { 323 351 // get xhtab cluster and local pointer 324 352 cxy_t xhtab_cxy = GET_CXY( xhtab_xp ); 325 xhtab_t * xhtab_ptr = (xhtab_t *)GET_PTR( xhtab_xp );353 xhtab_t * xhtab_ptr = GET_PTR( xhtab_xp ); 326 354 327 355 // take the lock protecting hash table 328 remote_ rwlock_rd_lock( XPTR( xhtab_cxy , &xhtab_ptr->lock ) );356 remote_busylock_acquire( XPTR( xhtab_cxy , &xhtab_ptr->lock ) ); 329 357 } 330 358 331 //////////////////////////////////// /////332 void xhtab_ read_unlock( xptr_t xhtab_xp )359 //////////////////////////////////// 360 void xhtab_unlock( xptr_t xhtab_xp ) 333 361 { 334 362 // get xhtab cluster and local pointer 335 363 cxy_t xhtab_cxy = GET_CXY( xhtab_xp ); 336 xhtab_t * xhtab_ptr = (xhtab_t *)GET_PTR( xhtab_xp );364 xhtab_t * xhtab_ptr = GET_PTR( xhtab_xp ); 337 365 338 366 // release the lock protecting hash table 339 remote_ rwlock_rd_unlock( XPTR( xhtab_cxy , &xhtab_ptr->lock ) );367 remote_busylock_release( XPTR( xhtab_cxy , &xhtab_ptr->lock ) ); 340 368 } 341 369 … … 353 381 // get xhtab cluster and local pointer 354 382 xhtab_cxy = GET_CXY( xhtab_xp ); 355 xhtab_ptr = (xhtab_t *)GET_PTR( xhtab_xp );383 xhtab_ptr = GET_PTR( xhtab_xp ); 356 384 357 385 // get pointer on "item_from_xlist" function … … 373 401 374 402 // register item in hash table header 375 hal_remote_s w( XPTR( xhtab_cxy , &xhtab_ptr->current_index ) , index );376 hal_remote_s wd( XPTR( xhtab_cxy , &xhtab_ptr->current_xlist_xp ) , xlist_xp );403 hal_remote_s32 ( XPTR( xhtab_cxy , &xhtab_ptr->current_index ) , index ); 404 hal_remote_s64( XPTR( xhtab_cxy , &xhtab_ptr->current_xlist_xp ) , xlist_xp ); 377 405 378 406 return item_xp; … … 401 429 // get xhtab cluster and local pointer 402 430 xhtab_cxy = GET_CXY( xhtab_xp ); 403 xhtab_ptr = (xhtab_t *)GET_PTR( xhtab_xp );431 xhtab_ptr = GET_PTR( xhtab_xp ); 404 432 405 433 // get current item pointers 406 current_index = hal_remote_l w( XPTR( xhtab_cxy , &xhtab_ptr->current_index ) );407 current_xlist_xp = hal_remote_l wd( XPTR( xhtab_cxy , &xhtab_ptr->current_xlist_xp ) );434 current_index = hal_remote_l32 ( XPTR( xhtab_cxy , &xhtab_ptr->current_index ) ); 435 current_xlist_xp = hal_remote_l64( XPTR( xhtab_cxy , &xhtab_ptr->current_xlist_xp ) ); 408 436 409 437 // get pointer on "item_from_xlist" function … … 426 454 427 455 // register item in hash table header 428 hal_remote_s w( XPTR( xhtab_cxy , &xhtab_ptr->current_index ) , index );429 hal_remote_s wd( XPTR( xhtab_cxy , &xhtab_ptr->current_xlist_xp ) , xlist_xp );456 hal_remote_s32 ( XPTR( xhtab_cxy , &xhtab_ptr->current_index ) , index ); 457 hal_remote_s64( XPTR( xhtab_cxy , &xhtab_ptr->current_xlist_xp ) , xlist_xp ); 430 458 431 459 return item_xp; … … 452 480 // get xhtab cluster and local pointer 453 481 xhtab_cxy = GET_CXY( xhtab_xp ); 454 xhtab_ptr = (xhtab_t *)GET_PTR( xhtab_xp );482 xhtab_ptr = GET_PTR( xhtab_xp ); 455 483 456 484 // get pointer on "item_from_xlist" function
Note: See TracChangeset
for help on using the changeset viewer.