Rev 2948 | Rev 3153 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 2948 | Rev 3009 | ||
---|---|---|---|
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. |
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; |
78 | static futex_t used_futex = FUTEX_INITIALIZER; |
87 | 79 | ||
88 | /** |
80 | /** |
89 | * Global hash table of all used fat_idx_t structures. |
81 | * Global hash table of all used fat_idx_t structures. |
90 | * The index structures are hashed by the dev_handle, parent node's first |
82 | * The index structures are hashed by the dev_handle, parent node's first |
Line 350... | Line 342... | ||
350 | [UPH_PDI_KEY] = pdi, |
342 | [UPH_PDI_KEY] = pdi, |
351 | }; |
343 | }; |
352 | 344 | ||
353 | futex_down(&used_futex); |
345 | futex_down(&used_futex); |
354 | l = hash_table_find(&up_hash, pkey); |
346 | l = hash_table_find(&up_hash, pkey); |
355 | futex_up(&used_futex); |
- | |
356 | if (l) { |
347 | if (l) { |
357 | fidx = hash_table_get_instance(l, fat_idx_t, uph_link); |
348 | fidx = hash_table_get_instance(l, fat_idx_t, uph_link); |
358 | } else { |
349 | } else { |
359 | fidx = (fat_idx_t *) malloc(sizeof(fat_idx_t)); |
350 | fidx = (fat_idx_t *) malloc(sizeof(fat_idx_t)); |
360 | if (!fidx) { |
351 | if (!fidx) { |
- | 352 | futex_up(&used_futex); |
|
361 | return NULL; |
353 | return NULL; |
362 | } |
354 | } |
363 | if (!fat_idx_alloc(dev_handle, &fidx->index)) { |
355 | if (!fat_idx_alloc(dev_handle, &fidx->index)) { |
364 | free(fidx); |
356 | free(fidx); |
- | 357 | futex_up(&used_futex); |
|
365 | return NULL; |
358 | return NULL; |
366 | } |
359 | } |
367 | 360 | ||
368 | unsigned long ikey[] = { |
361 | unsigned long ikey[] = { |
369 | [UIH_DH_KEY] = dev_handle, |
362 | [UIH_DH_KEY] = dev_handle, |
370 | [UIH_INDEX_KEY] = fidx->index, |
363 | [UIH_INDEX_KEY] = fidx->index, |
371 | }; |
364 | }; |
372 | 365 | ||
373 | link_initialize(&fidx->uph_link); |
366 | link_initialize(&fidx->uph_link); |
374 | link_initialize(&fidx->uih_link); |
367 | link_initialize(&fidx->uih_link); |
- | 368 | futex_initialize(&fidx->lock, 1); |
|
375 | fidx->dev_handle = dev_handle; |
369 | fidx->dev_handle = dev_handle; |
376 | fidx->pfc = pfc; |
370 | fidx->pfc = pfc; |
377 | fidx->pdi = pdi; |
371 | fidx->pdi = pdi; |
378 | fidx->nodep = NULL; |
372 | fidx->nodep = NULL; |
379 | 373 | ||
380 | futex_down(&used_futex); |
- | |
381 | hash_table_insert(&up_hash, pkey, &fidx->uph_link); |
374 | hash_table_insert(&up_hash, pkey, &fidx->uph_link); |
382 | hash_table_insert(&ui_hash, ikey, &fidx->uih_link); |
375 | hash_table_insert(&ui_hash, ikey, &fidx->uih_link); |
383 | futex_up(&used_futex); |
- | |
384 | } |
376 | } |
- | 377 | futex_down(&fidx->lock); |
|
- | 378 | futex_up(&used_futex); |
|
385 | 379 | ||
386 | return fidx; |
380 | return fidx; |
387 | } |
381 | } |
388 | 382 | ||
389 | fat_idx_t * |
383 | fat_idx_t * |
Line 396... | Line 390... | ||
396 | [UIH_INDEX_KEY] = index, |
390 | [UIH_INDEX_KEY] = index, |
397 | }; |
391 | }; |
398 | 392 | ||
399 | futex_down(&used_futex); |
393 | futex_down(&used_futex); |
400 | l = hash_table_find(&ui_hash, ikey); |
394 | l = hash_table_find(&ui_hash, ikey); |
401 | futex_up(&used_futex); |
- | |
402 | if (l) { |
395 | if (l) { |
403 | fidx = hash_table_get_instance(l, fat_idx_t, uih_link); |
396 | fidx = hash_table_get_instance(l, fat_idx_t, uih_link); |
- | 397 | futex_down(&fidx->lock); |
|
404 | } |
398 | } |
- | 399 | futex_up(&used_futex); |
|
405 | 400 | ||
406 | return fidx; |
401 | return fidx; |
407 | } |
402 | } |
408 | 403 |