Rev 2944 | Rev 2951 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
| Rev 2944 | Rev 2945 | ||
|---|---|---|---|
| Line 72... | Line 72... | ||
| 72 | static futex_t unused_futex = FUTEX_INITIALIZER; |
72 | static futex_t unused_futex = FUTEX_INITIALIZER; |
| 73 | 73 | ||
| 74 | /** List of unused structures. */ |
74 | /** List of unused structures. */ |
| 75 | static LIST_INITIALIZE(unused_head); |
75 | static LIST_INITIALIZE(unused_head); |
| 76 | 76 | ||
| - | 77 | /** Futex protecting the up_hash and ui_hash. |
|
| - | 78 | * |
|
| - | 79 | * The locking strategy assumes that there will be at most one fibril for each |
|
| - | 80 | * dev_handle. Therefore it will be sufficient to hold the futex for shorter |
|
| - | 81 | * times (i.e. only during hash table operations as opposed to holding it the |
|
| - | 82 | * whole time between an unsuccessful find and the following insert). Should the |
|
| - | 83 | * assumption break, the locking strategy for this futex will have to be |
|
| - | 84 | * reconsidered. |
|
| - | 85 | */ |
|
| - | 86 | static futex_t used_futex = FUTEX_INITIALIZER; |
|
| - | 87 | ||
| 77 | /** |
88 | /** |
| 78 | * Global hash table of all used fat_idx_t structures. |
89 | * Global hash table of all used fat_idx_t structures. |
| 79 | * The index structures are hashed by the dev_handle, parent node's first |
90 | * The index structures are hashed by the dev_handle, parent node's first |
| 80 | * cluster and index within the parent directory. |
91 | * cluster and index within the parent directory. |
| 81 | */ |
92 | */ |
| Line 337... | Line 348... | ||
| 337 | [UPH_DH_KEY] = dev_handle, |
348 | [UPH_DH_KEY] = dev_handle, |
| 338 | [UPH_PFC_KEY] = pfc, |
349 | [UPH_PFC_KEY] = pfc, |
| 339 | [UPH_PDI_KEY] = pdi, |
350 | [UPH_PDI_KEY] = pdi, |
| 340 | }; |
351 | }; |
| 341 | 352 | ||
| - | 353 | futex_down(&used_futex); |
|
| 342 | l = hash_table_find(&up_hash, pkey); |
354 | l = hash_table_find(&up_hash, pkey); |
| - | 355 | futex_up(&used_futex); |
|
| 343 | if (l) { |
356 | if (l) { |
| 344 | fidx = hash_table_get_instance(l, fat_idx_t, uph_link); |
357 | fidx = hash_table_get_instance(l, fat_idx_t, uph_link); |
| 345 | } else { |
358 | } else { |
| 346 | fidx = (fat_idx_t *) malloc(sizeof(fat_idx_t)); |
359 | fidx = (fat_idx_t *) malloc(sizeof(fat_idx_t)); |
| 347 | if (!fidx) { |
360 | if (!fidx) { |
| Line 362... | Line 375... | ||
| 362 | fidx->dev_handle = dev_handle; |
375 | fidx->dev_handle = dev_handle; |
| 363 | fidx->pfc = pfc; |
376 | fidx->pfc = pfc; |
| 364 | fidx->pdi = pdi; |
377 | fidx->pdi = pdi; |
| 365 | fidx->nodep = NULL; |
378 | fidx->nodep = NULL; |
| 366 | 379 | ||
| - | 380 | futex_down(&used_futex); |
|
| 367 | hash_table_insert(&up_hash, pkey, &fidx->uph_link); |
381 | hash_table_insert(&up_hash, pkey, &fidx->uph_link); |
| 368 | hash_table_insert(&ui_hash, ikey, &fidx->uih_link); |
382 | hash_table_insert(&ui_hash, ikey, &fidx->uih_link); |
| - | 383 | futex_up(&used_futex); |
|
| 369 | } |
384 | } |
| 370 | 385 | ||
| 371 | return fidx; |
386 | return fidx; |
| 372 | } |
387 | } |
| 373 | 388 | ||
| Line 379... | Line 394... | ||
| 379 | unsigned long ikey[] = { |
394 | unsigned long ikey[] = { |
| 380 | [UIH_DH_KEY] = dev_handle, |
395 | [UIH_DH_KEY] = dev_handle, |
| 381 | [UIH_INDEX_KEY] = index, |
396 | [UIH_INDEX_KEY] = index, |
| 382 | }; |
397 | }; |
| 383 | 398 | ||
| - | 399 | futex_down(&used_futex); |
|
| 384 | l = hash_table_find(&ui_hash, ikey); |
400 | l = hash_table_find(&ui_hash, ikey); |
| - | 401 | futex_up(&used_futex); |
|
| 385 | if (l) { |
402 | if (l) { |
| 386 | fidx = hash_table_get_instance(l, fat_idx_t, uih_link); |
403 | fidx = hash_table_get_instance(l, fat_idx_t, uih_link); |
| 387 | } |
404 | } |
| 388 | 405 | ||
| 389 | return fidx; |
406 | return fidx; |