Rev 2951 | Rev 3111 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 2951 | Rev 3110 | ||
---|---|---|---|
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 | static void unused_initialize(unused_t *u, dev_handle_t dev_handle) |
|
- | 78 | { |
|
- | 79 | link_initialize(&u->link); |
|
- | 80 | u->dev_handle = dev_handle; |
|
- | 81 | u->next = 0; |
|
- | 82 | u->remaining = ((uint64_t)((fs_index_t)-1)) + 1; |
|
- | 83 | list_initialize(&u->freed_head); |
|
- | 84 | } |
|
- | 85 | ||
77 | /** Futex protecting the up_hash and ui_hash. */ |
86 | /** Futex protecting the up_hash and ui_hash. */ |
78 | static futex_t used_futex = FUTEX_INITIALIZER; |
87 | static futex_t used_futex = FUTEX_INITIALIZER; |
79 | 88 | ||
80 | /** |
89 | /** |
81 | * Global hash table of all used fat_idx_t structures. |
90 | * Global hash table of all used fat_idx_t structures. |
Line 399... | Line 408... | ||
399 | futex_up(&used_futex); |
408 | futex_up(&used_futex); |
400 | 409 | ||
401 | return fidx; |
410 | return fidx; |
402 | } |
411 | } |
403 | 412 | ||
- | 413 | int fat_idx_init(void) |
|
- | 414 | { |
|
- | 415 | if (!hash_table_create(&up_hash, UPH_BUCKETS, 3, &uph_ops)) |
|
- | 416 | return ENOMEM; |
|
- | 417 | if (!hash_table_create(&ui_hash, UIH_BUCKETS, 2, &uih_ops)) { |
|
- | 418 | hash_table_destroy(&up_hash); |
|
- | 419 | return ENOMEM; |
|
- | 420 | } |
|
- | 421 | return EOK; |
|
- | 422 | } |
|
- | 423 | ||
- | 424 | void fat_idx_fini(void) |
|
- | 425 | { |
|
- | 426 | /* We assume the hash tables are empty. */ |
|
- | 427 | hash_table_destroy(&up_hash); |
|
- | 428 | hash_table_destroy(&ui_hash); |
|
- | 429 | } |
|
- | 430 | ||
- | 431 | int fat_idx_init_by_dev_handle(dev_handle_t dev_handle) |
|
- | 432 | { |
|
- | 433 | unused_t *u = (unused_t *) malloc(sizeof(unused_t)); |
|
- | 434 | if (!u) |
|
- | 435 | return ENOMEM; |
|
- | 436 | unused_initialize(u, dev_handle); |
|
- | 437 | futex_down(&unused_futex); |
|
- | 438 | list_append(&u->link, &unused_head); |
|
- | 439 | futex_up(&unused_futex); |
|
- | 440 | return EOK; |
|
- | 441 | } |
|
- | 442 | ||
- | 443 | void fat_idx_fini_by_dev_handle(dev_handle_t dev_handle) |
|
- | 444 | { |
|
- | 445 | unused_t *u; |
|
- | 446 | link_t *l; |
|
- | 447 | ||
- | 448 | futex_down(&unused_futex); |
|
- | 449 | for (l = unused_head.next; l != &unused_head; l = l->next) { |
|
- | 450 | u = list_get_instance(l, unused_t, link); |
|
- | 451 | if (u->dev_handle == dev_handle) |
|
- | 452 | goto hit; |
|
- | 453 | } |
|
- | 454 | futex_up(&unused_futex); |
|
- | 455 | ||
- | 456 | assert(false); /* should not happen */ |
|
- | 457 | ||
- | 458 | hit: |
|
- | 459 | list_remove(&u->link); |
|
- | 460 | futex_up(&unused_futex); |
|
- | 461 | ||
- | 462 | while (!list_empty(&u->freed_head)) { |
|
- | 463 | freed_t *f; |
|
- | 464 | f = list_get_instance(u->freed_head.next, freed_t, link); |
|
- | 465 | list_remove(&f->link); |
|
- | 466 | free(f); |
|
- | 467 | } |
|
- | 468 | free(u); |
|
- | 469 | } |
|
- | 470 | ||
- | 471 | /** |
|
- | 472 | * @} |
|
- | 473 | */ |