Changeset c28413a9 in mainline for kernel/generic/src/adt/cht.c
- Timestamp:
- 2012-11-20T18:50:04Z (12 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- ba368a6
- Parents:
- 669f3d32
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/generic/src/adt/cht.c
r669f3d32 rc28413a9 408 408 409 409 static size_t size_to_order(size_t bucket_cnt, size_t min_order); 410 static cht_buckets_t *alloc_buckets(size_t order, bool set_invalid); 410 static cht_buckets_t *alloc_buckets(size_t order, bool set_invalid, 411 bool can_block); 411 412 static inline cht_link_t *find_lazy(cht_t *h, void *key); 412 413 static cht_link_t *search_bucket(cht_t *h, marked_ptr_t head, void *key, … … 478 479 static void cas_order_barrier(void); 479 480 481 static void dummy_remove_callback(cht_link_t *item) 482 { 483 /* empty */ 484 } 485 486 /** Creates a concurrent hash table. 487 * 488 * @param h Valid pointer to a cht_t instance. 489 * @param op Item specific operations. All operations are compulsory. 490 * @return True if successfully created the table. False otherwise. 491 */ 492 bool cht_create_simple(cht_t *h, cht_ops_t *op) 493 { 494 return cht_create(h, 0, 0, 0, false, op); 495 } 496 480 497 /** Creates a concurrent hash table. 481 498 * … … 490 507 * @param max_load Maximum average number of items per bucket that allowed 491 508 * before the table grows. 509 * @param can_block If true creating the table blocks until enough memory 510 * is available (possibly indefinitely). Otherwise, 511 * table creation does not block and returns immediately 512 * even if not enough memory is available. 492 513 * @param op Item specific operations. All operations are compulsory. 493 514 * @return True if successfully created the table. False otherwise. 494 515 */ 495 516 bool cht_create(cht_t *h, size_t init_size, size_t min_size, size_t max_load, 496 cht_ops_t *op)517 bool can_block, cht_ops_t *op) 497 518 { 498 519 ASSERT(h); … … 509 530 size_t order = size_to_order(init_size, min_order); 510 531 511 h->b = alloc_buckets(order, false );532 h->b = alloc_buckets(order, false, can_block); 512 533 513 534 if (!h->b) … … 520 541 atomic_set(&h->item_cnt, 0); 521 542 atomic_set(&h->resize_reqs, 0); 543 544 if (NULL == op->remove_callback) { 545 h->op->remove_callback = dummy_remove_callback; 546 } 547 522 548 /* 523 549 * Cached item hashes are stored in item->rcu_link.func. Once the item … … 539 565 * @param set_invalid Bucket heads are marked invalid if true; otherwise 540 566 * they are marked N_NORMAL. 567 * @param can_block If true memory allocation blocks until enough memory 568 * is available (possibly indefinitely). Otherwise, 569 * memory allocation does not block. 541 570 * @return Newly allocated and initialized buckets or NULL if not enough memory. 542 571 */ 543 static cht_buckets_t *alloc_buckets(size_t order, bool set_invalid )572 static cht_buckets_t *alloc_buckets(size_t order, bool set_invalid, bool can_block) 544 573 { 545 574 size_t bucket_cnt = (1 << order); 546 575 size_t bytes = 547 576 sizeof(cht_buckets_t) + (bucket_cnt - 1) * sizeof(marked_ptr_t); 548 cht_buckets_t *b = malloc(bytes, FRAME_ATOMIC);577 cht_buckets_t *b = malloc(bytes, can_block ? 0 : FRAME_ATOMIC); 549 578 550 579 if (!b) … … 2145 2174 return; 2146 2175 2147 h->new_b = alloc_buckets(h->b->order + 1, true );2176 h->new_b = alloc_buckets(h->b->order + 1, true, false); 2148 2177 2149 2178 /* Failed to alloc a new table - try next time the resizer is run. */ … … 2231 2260 return; 2232 2261 2233 h->new_b = alloc_buckets(h->b->order - 1, true );2262 h->new_b = alloc_buckets(h->b->order - 1, true, false); 2234 2263 2235 2264 /* Failed to alloc a new table - try next time the resizer is run. */
Note:
See TracChangeset
for help on using the changeset viewer.