Changeset 0b7bcb8 in mainline
- Timestamp:
- 2012-08-03T16:08:39Z (12 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 5e5cef3
- Parents:
- fbe17545
- Location:
- kernel
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/generic/include/adt/cht.h
rfbe17545 r0b7bcb8 75 75 cht_buckets_t *new_b; 76 76 77 size_t max_load; 77 78 work_t resize_work; 78 79 atomic_t resize_reqs; … … 88 89 #define cht_read_unlock() rcu_read_unlock() 89 90 90 extern bool cht_create(cht_t *h, size_t init_size, size_t min_size, cht_ops_t *op); 91 extern bool cht_create(cht_t *h, size_t init_size, size_t min_size, 92 size_t max_load, cht_ops_t *op); 91 93 extern void cht_destroy(cht_t *h); 92 94 -
kernel/generic/src/adt/cht.c
rfbe17545 r0b7bcb8 49 49 50 50 51 /* Logarithm of the min bucket count. 2^6 == 64 buckets. */51 /* Logarithm of the min bucket count. Must be at least 3. 2^6 == 64 buckets. */ 52 52 #define CHT_MIN_ORDER 6 53 53 /* Logarithm of the max bucket count. */ … … 55 55 /* Minimum number of hash table buckets. */ 56 56 #define CHT_MIN_BUCKET_CNT (1 << CHT_MIN_ORDER) 57 /* Mustbe a power of 2. */57 /* Does not have to be a power of 2. */ 58 58 #define CHT_MAX_LOAD 2 59 59 … … 83 83 } wnd_t; 84 84 85 /* Fwd decl. */ 85 86 86 static size_t size_to_order(size_t bucket_cnt, size_t min_order); 87 87 static cht_buckets_t *alloc_buckets(size_t order, bool set_invalid); … … 153 153 154 154 155 bool cht_create(cht_t *h, size_t init_size, size_t min_size, cht_ops_t *op) 155 bool cht_create(cht_t *h, size_t init_size, size_t min_size, size_t max_load, 156 cht_ops_t *op) 156 157 { 157 158 ASSERT(h); … … 170 171 return false; 171 172 173 h->max_load = (max_load == 0) ? CHT_MAX_LOAD : max_load; 172 174 h->min_order = min_order; 173 175 h->new_b = 0; … … 1360 1362 size_t bucket_cnt = (1 << h->b->order); 1361 1363 1362 bool need_shrink = (items == CHT_MAX_LOAD* bucket_cnt / 4);1363 bool missed_shrink = (items == CHT_MAX_LOAD* bucket_cnt / 8);1364 bool need_shrink = (items == h->max_load * bucket_cnt / 4); 1365 bool missed_shrink = (items == h->max_load * bucket_cnt / 8); 1364 1366 1365 1367 if ((need_shrink || missed_shrink) && h->b->order > h->min_order) { … … 1377 1379 size_t bucket_cnt = (1 << h->b->order); 1378 1380 1379 bool need_grow = (items == CHT_MAX_LOAD* bucket_cnt);1380 bool missed_grow = (items == 2 * CHT_MAX_LOAD* bucket_cnt);1381 bool need_grow = (items == h->max_load * bucket_cnt); 1382 bool missed_grow = (items == 2 * h->max_load * bucket_cnt); 1381 1383 1382 1384 if ((need_grow || missed_grow) && h->b->order < CHT_MAX_ORDER) { … … 1406 1408 size_t cur_items = (size_t) atomic_get(&h->item_cnt); 1407 1409 size_t bucket_cnt = (1 << h->b->order); 1408 size_t max_items = CHT_MAX_LOAD* bucket_cnt;1410 size_t max_items = h->max_load * bucket_cnt; 1409 1411 1410 1412 if (cur_items >= max_items && h->b->order < CHT_MAX_ORDER) { -
kernel/test/cht/cht1.c
rfbe17545 r0b7bcb8 235 235 { 236 236 cht_t h; 237 if (!cht_create(&h, 5, 0, &val_ops))237 if (!cht_create(&h, 5, 0, 0, &val_ops)) 238 238 return "Could not create the table."; 239 239 … … 445 445 cht_t h; 446 446 447 if (!cht_create(&h, 0, 0, &stress_ops)) {447 if (!cht_create(&h, 0, 0, 0, &stress_ops)) { 448 448 TPRINTF("Failed to create the table\n"); 449 449 return false;
Note:
See TracChangeset
for help on using the changeset viewer.