Changeset 63e27ef in mainline for kernel/generic/src/adt/cht.c


Ignore:
Timestamp:
2017-06-19T21:47:42Z (7 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
deacc58d
Parents:
7354b5e
Message:

ASSERT → assert

File:
1 edited

Legend:

Unmodified
Added
Removed
  • kernel/generic/src/adt/cht.c

    r7354b5e r63e27ef  
    290290#include <adt/cht.h>
    291291#include <adt/hash.h>
    292 #include <debug.h>
     292#include <assert.h>
    293293#include <mm/slab.h>
    294294#include <arch/barrier.h>
     
    522522        bool can_block, cht_ops_t *op)
    523523{
    524         ASSERT(h);
    525         ASSERT(op && op->hash && op->key_hash && op->equal && op->key_equal);
     524        assert(h);
     525        assert(op && op->hash && op->key_hash && op->equal && op->key_equal);
    526526        /* Memoized hashes are stored in the rcu_link.func function pointer. */
    527         STATIC_ASSERT(sizeof(size_t) == sizeof(rcu_func_t));
    528         ASSERT(sentinel.hash == (uintptr_t)sentinel.rcu_link.func);
     527        static_assert(sizeof(size_t) == sizeof(rcu_func_t), "");
     528        assert(sentinel.hash == (uintptr_t)sentinel.rcu_link.func);
    529529
    530530        /* All operations are compulsory. */
     
    625625       
    626626        /* You must clear the table of items. Otherwise cht_destroy will leak. */
    627         ASSERT(atomic_get(&h->item_cnt) == 0);
     627        assert(atomic_get(&h->item_cnt) == 0);
    628628}
    629629
     
    685685static inline cht_link_t *find_lazy(cht_t *h, void *key)
    686686{
    687         ASSERT(h);
     687        assert(h);
    688688        /* See docs to cht_find() and cht_find_lazy(). */
    689         ASSERT(rcu_read_locked());
     689        assert(rcu_read_locked());
    690690       
    691691        size_t hash = calc_key_hash(h, key);
     
    731731cht_link_t *cht_find_next_lazy(cht_t *h, const cht_link_t *item)
    732732{
    733         ASSERT(h);
    734         ASSERT(rcu_read_locked());
    735         ASSERT(item);
     733        assert(h);
     734        assert(rcu_read_locked());
     735        assert(item);
    736736       
    737737        return find_duplicate(h, item, calc_node_hash(h, item), get_next(item->link));
     
    755755        do {
    756756                cur = get_next(prev);
    757                 ASSERT(cur);
     757                assert(cur);
    758758                prev = cur->link;
    759759        } while (node_hash(h, cur) < search_hash);
     
    770770               
    771771                cur = get_next(cur->link);
    772                 ASSERT(cur);
     772                assert(cur);
    773773        }
    774774       
     
    790790        marked_ptr_t old_head, size_t old_idx)
    791791{
    792         ASSERT(N_INVALID == get_mark(old_head));
    793         ASSERT(h->new_b);
     792        assert(N_INVALID == get_mark(old_head));
     793        assert(h->new_b);
    794794       
    795795        size_t new_idx = calc_bucket_idx(hash, h->new_b->order);
     
    903903                         * traversing search_head.
    904904                         */
    905                         ASSERT(N_JOIN & get_mark(get_next(old_head)->link));
     905                        assert(N_JOIN & get_mark(get_next(old_head)->link));
    906906                        return search_bucket(h, old_head, key, hash);
    907907                }
     
    913913                 * sure all cpus see that the new table replaced the old one.
    914914                 */
    915                 ASSERT(h->b->order == h->new_b->order);
     915                assert(h->b->order == h->new_b->order);
    916916                /*
    917917                 * The resizer must ensure all new bucket heads are visible before
    918918                 * replacing the old table.
    919919                 */
    920                 ASSERT(N_NORMAL == get_mark(new_head));
     920                assert(N_NORMAL == get_mark(new_head));
    921921                return search_bucket(h, new_head, key, hash);
    922922        }
     
    961961bool cht_insert_unique(cht_t *h, cht_link_t *item, cht_link_t **dup_item)
    962962{
    963         ASSERT(rcu_read_locked());
    964         ASSERT(dup_item);
     963        assert(rcu_read_locked());
     964        assert(dup_item);
    965965        return insert_impl(h, item, dup_item);
    966966}
     
    10601060                return ret == make_link(wnd->cur, jf_mark);
    10611061        } else {
    1062                 ASSERT(walk_mode == WM_LEAVE_JOIN);
     1062                assert(walk_mode == WM_LEAVE_JOIN);
    10631063
    10641064                item->link = make_link(wnd->cur, N_NORMAL);
     
    10871087        cht_link_t *cur, cht_link_t **dup_item)
    10881088{
    1089         ASSERT(cur);
    1090         ASSERT(cur == &sentinel || hash <= node_hash(h, cur)
     1089        assert(cur);
     1090        assert(cur == &sentinel || hash <= node_hash(h, cur)
    10911091                || node_hash(h, cur) == h->invalid_hash);
    10921092       
     
    11101110        cht_link_t *start)
    11111111{
    1112         ASSERT(hash <= node_hash(h, start) || h->invalid_hash == node_hash(h, start));
     1112        assert(hash <= node_hash(h, start) || h->invalid_hash == node_hash(h, start));
    11131113
    11141114        cht_link_t *cur = start;
    11151115       
    11161116try_again:     
    1117         ASSERT(cur);
     1117        assert(cur);
    11181118
    11191119        while (node_hash(h, cur) == hash) {
    1120                 ASSERT(cur != &sentinel);
     1120                assert(cur != &sentinel);
    11211121               
    11221122                bool deleted = (N_DELETED & get_mark(cur->link));
     
    11271127               
    11281128                cur = get_next(cur->link);
    1129                 ASSERT(cur);
     1129                assert(cur);
    11301130        }
    11311131
     
    11421142size_t cht_remove_key(cht_t *h, void *key)
    11431143{
    1144         ASSERT(h);
     1144        assert(h);
    11451145       
    11461146        size_t hash = calc_key_hash(h, key);
     
    11631163bool cht_remove_item(cht_t *h, cht_link_t *item)
    11641164{
    1165         ASSERT(h);
    1166         ASSERT(item);
     1165        assert(h);
     1166        assert(item);
    11671167        /* Otherwise a concurrent cht_remove_key might free the item. */
    1168         ASSERT(rcu_read_locked());
     1168        assert(rcu_read_locked());
    11691169
    11701170        /*
     
    12621262        bool *deleted_but_gc, bool *resizing)
    12631263{
    1264         ASSERT(wnd->cur && wnd->cur != &sentinel);
     1264        assert(wnd->cur && wnd->cur != &sentinel);
    12651265       
    12661266        *deleted_but_gc = false;
     
    12921292        bool *resizing)
    12931293{
    1294         ASSERT(cur && cur != &sentinel);
     1294        assert(cur && cur != &sentinel);
    12951295       
    12961296        /*
     
    13101310                }
    13111311        } else {
    1312                 STATIC_ASSERT(N_JOIN == N_JOIN_FOLLOWS);
     1312                static_assert(N_JOIN == N_JOIN_FOLLOWS, "");
    13131313               
    13141314                /* Keep the N_JOIN/N_JOIN_FOLLOWS mark but strip N_DELETED. */
     
    13291329        bool *resizing)
    13301330{
    1331         ASSERT(wnd->cur != &sentinel);
    1332         ASSERT(wnd->cur && (N_DELETED & get_mark(wnd->cur->link)));
     1331        assert(wnd->cur != &sentinel);
     1332        assert(wnd->cur && (N_DELETED & get_mark(wnd->cur->link)));
    13331333       
    13341334        cht_link_t *next = get_next(wnd->cur->link);
     
    13361336        if (walk_mode == WM_LEAVE_JOIN) {
    13371337                /* Never try to unlink join nodes. */
    1338                 ASSERT(!(N_JOIN & get_mark(wnd->cur->link)));
     1338                assert(!(N_JOIN & get_mark(wnd->cur->link)));
    13391339
    13401340                mark_t pred_mark = get_mark(*wnd->ppred);
     
    13481348                        return false;
    13491349        } else {
    1350                 ASSERT(walk_mode == WM_MOVE_JOIN_FOLLOWS || walk_mode == WM_NORMAL);
     1350                assert(walk_mode == WM_MOVE_JOIN_FOLLOWS || walk_mode == WM_NORMAL);
    13511351                /* Move the JF mark if set. Clear DEL mark. */
    13521352                mark_t cur_mark = N_JOIN_FOLLOWS & get_mark(wnd->cur->link);
     
    13981398        equal_pred_t pred, void *pred_arg, wnd_t *wnd, bool *resizing)
    13991399{
    1400         ASSERT(wnd->cur);
     1400        assert(wnd->cur);
    14011401       
    14021402        if (wnd->cur == &sentinel)
     
    14151415               
    14161416        while (cur_hash <= hash) {
    1417                 ASSERT(wnd->cur && wnd->cur != &sentinel);
     1417                assert(wnd->cur && wnd->cur != &sentinel);
    14181418               
    14191419                /* GC any deleted nodes on the way. */
     
    14361436        if (cur_hash == h->invalid_hash) {
    14371437                next_wnd(wnd);
    1438                 ASSERT(wnd->cur);
     1438                assert(wnd->cur);
    14391439                goto try_again;
    14401440        }
     
    14691469{
    14701470try_again:
    1471         ASSERT(wnd->cur);
     1471        assert(wnd->cur);
    14721472
    14731473        while (node_hash(h, wnd->cur) < hash) {
     
    14821482                }
    14831483               
    1484                 ASSERT(wnd->cur);
     1484                assert(wnd->cur);
    14851485        }
    14861486       
     
    14981498        bool *resizing)
    14991499{
    1500         ASSERT(N_DELETED & get_mark(wnd->cur->link));
     1500        assert(N_DELETED & get_mark(wnd->cur->link));
    15011501
    15021502        /* Skip deleted JOIN nodes. */
     
    15051505        } else {
    15061506                /* Ordinary deleted node or a deleted JOIN_FOLLOWS. */
    1507                 ASSERT(walk_mode != WM_LEAVE_JOIN
     1507                assert(walk_mode != WM_LEAVE_JOIN
    15081508                        || !((N_JOIN | N_JOIN_FOLLOWS) & get_mark(wnd->cur->link)));
    15091509
     
    15461546         * it
    15471547         */
    1548         ASSERT(h->b->order > h->new_b->order);
    1549         ASSERT(wnd->cur);
     1548        assert(h->b->order > h->new_b->order);
     1549        assert(wnd->cur);
    15501550       
    15511551        /* Either we did not need the joining link or we have already followed it.*/
     
    16201620                /* The hash belongs to the moved bucket. */
    16211621                if (move_dest_idx == new_idx) {
    1622                         ASSERT(pmoved_head == pnew_head);
     1622                        assert(pmoved_head == pnew_head);
    16231623                        /*
    16241624                         * move_head() makes the new head of the moved bucket visible.
    16251625                         * The new head may be marked with a JOIN_FOLLOWS
    16261626                         */
    1627                         ASSERT(!(N_CONST & get_mark(*pmoved_head)));
     1627                        assert(!(N_CONST & get_mark(*pmoved_head)));
    16281628                        *walk_mode = WM_MOVE_JOIN_FOLLOWS;
    16291629                } else {
    1630                         ASSERT(pmoved_head != pnew_head);
     1630                        assert(pmoved_head != pnew_head);
    16311631                        /*
    16321632                         * The hash belongs to the bucket that is the result of splitting
     
    16431643                                 * JOIN_FOLLOWS in this part of split bucket.
    16441644                                 */
    1645                                 ASSERT(N_NORMAL == get_mark(*pnew_head));
     1645                                assert(N_NORMAL == get_mark(*pnew_head));
    16461646                        }
    16471647                       
     
    16751675               
    16761676                /* move_head() or join_buckets() makes it so or makes the mark visible.*/
    1677                 ASSERT(N_INVALID == get_mark(*pold_head));
     1677                assert(N_INVALID == get_mark(*pold_head));
    16781678                /* move_head() makes it visible. No JOIN_FOLLOWS used when shrinking. */
    1679                 ASSERT(N_NORMAL == get_mark(*pnew_head));
     1679                assert(N_NORMAL == get_mark(*pnew_head));
    16801680
    16811681                *walk_mode = WM_LEAVE_JOIN;
     
    16851685                 * readers to notice that the old table had been replaced.
    16861686                 */
    1687                 ASSERT(b == h->new_b);
     1687                assert(b == h->new_b);
    16881688                *walk_mode = WM_NORMAL;
    16891689        }
     
    17121712{
    17131713        /* Head move has to in progress already when calling this func. */
    1714         ASSERT(N_CONST & get_mark(*psrc_head));
     1714        assert(N_CONST & get_mark(*psrc_head));
    17151715       
    17161716        /* Head already moved. */
     
    17251725        }
    17261726       
    1727         ASSERT(!(N_CONST & get_mark(*pdest_head)));
     1727        assert(!(N_CONST & get_mark(*pdest_head)));
    17281728}
    17291729
     
    17561756static void complete_head_move(marked_ptr_t *psrc_head, marked_ptr_t *pdest_head)
    17571757{
    1758         ASSERT(N_JOIN_FOLLOWS != get_mark(*psrc_head));
    1759         ASSERT(N_CONST & get_mark(*psrc_head));
     1758        assert(N_JOIN_FOLLOWS != get_mark(*psrc_head));
     1759        assert(N_CONST & get_mark(*psrc_head));
    17601760       
    17611761        cht_link_t *next = get_next(*psrc_head);
     
    17631763        DBG(marked_ptr_t ret = )
    17641764                cas_link(pdest_head, &sentinel, N_INVALID, next, N_NORMAL);
    1765         ASSERT(ret == make_link(&sentinel, N_INVALID) || (N_NORMAL == get_mark(ret)));
     1765        assert(ret == make_link(&sentinel, N_INVALID) || (N_NORMAL == get_mark(ret)));
    17661766        cas_order_barrier();
    17671767       
    17681768        DBG(ret = )
    17691769                cas_link(psrc_head, next, N_CONST, next, N_INVALID);   
    1770         ASSERT(ret == make_link(next, N_CONST) || (N_INVALID == get_mark(ret)));
     1770        assert(ret == make_link(next, N_CONST) || (N_INVALID == get_mark(ret)));
    17711771        cas_order_barrier();
    17721772}
     
    18611861        DBG(marked_ptr_t ret = )
    18621862                cas_link(pdest_head, &sentinel, N_INVALID, wnd.cur, N_NORMAL);
    1863         ASSERT(ret == make_link(&sentinel, N_INVALID) || (N_NORMAL == get_mark(ret)));
     1863        assert(ret == make_link(&sentinel, N_INVALID) || (N_NORMAL == get_mark(ret)));
    18641864        cas_order_barrier();
    18651865       
     
    19051905               
    19061906                /* Must not report that the table is resizing if WM_MOVE_JOIN_FOLLOWS.*/
    1907                 ASSERT(!resizing);
     1907                assert(!resizing);
    19081908                /*
    19091909                 * Mark the last node of the first half of the split bucket
     
    20422042        DBG(marked_ptr_t ret = )
    20432043                cas_link(psrc_head, join_node, N_CONST, join_node, N_INVALID);
    2044         ASSERT(ret == make_link(join_node, N_CONST) || (N_INVALID == get_mark(ret)));
     2044        assert(ret == make_link(join_node, N_CONST) || (N_INVALID == get_mark(ret)));
    20452045        cas_order_barrier();
    20462046       
     
    20732073                        continue;
    20742074
    2075                 ASSERT(!resizing);
     2075                assert(!resizing);
    20762076               
    20772077                if (wnd.cur != &sentinel) {
    20782078                        /* Must be from the new appended bucket. */
    2079                         ASSERT(split_hash <= node_hash(h, wnd.cur)
     2079                        assert(split_hash <= node_hash(h, wnd.cur)
    20802080                                || h->invalid_hash == node_hash(h, wnd.cur));
    20812081                        return;
     
    20962096static void free_later(cht_t *h, cht_link_t *item)
    20972097{
    2098         ASSERT(item != &sentinel);
     2098        assert(item != &sentinel);
    20992099       
    21002100        /*
     
    21562156       
    21572157#ifdef CONFIG_DEBUG
    2158         ASSERT(h->b);
     2158        assert(h->b);
    21592159        /* Make resize_reqs visible. */
    21602160        read_barrier();
    2161         ASSERT(0 < atomic_get(&h->resize_reqs));
     2161        assert(0 < atomic_get(&h->resize_reqs));
    21622162#endif
    21632163
     
    23362336                /* Set the invalid joinee head to NULL. */
    23372337                if (old_idx != move_src_idx) {
    2338                         ASSERT(N_INVALID == get_mark(h->b->head[old_idx]));
     2338                        assert(N_INVALID == get_mark(h->b->head[old_idx]));
    23392339                       
    23402340                        if (&sentinel != get_next(h->b->head[old_idx]))
     
    23922392        marked_ptr_t *new_head)
    23932393{
    2394         ASSERT(join_node != &sentinel);
    2395         ASSERT(join_node && (N_JOIN & get_mark(join_node->link)));
     2394        assert(join_node != &sentinel);
     2395        assert(join_node && (N_JOIN & get_mark(join_node->link)));
    23962396       
    23972397        bool done;
     
    24092409                /* Done if the mark was cleared. Retry if a new node was inserted. */
    24102410                done = (ret == jn_link);
    2411                 ASSERT(ret == jn_link || (get_mark(ret) & N_JOIN));
     2411                assert(ret == jn_link || (get_mark(ret) & N_JOIN));
    24122412        } while (!done);
    24132413       
     
    24322432                        join_node, &wnd, &resizing);
    24332433               
    2434                 ASSERT(!resizing);
     2434                assert(!resizing);
    24352435        } while (!done);
    24362436}
     
    24392439static void cleanup_join_follows(cht_t *h, marked_ptr_t *new_head)
    24402440{
    2441         ASSERT(new_head);
     2441        assert(new_head);
    24422442       
    24432443        rcu_read_lock();
     
    24642464                /* GC any deleted nodes on the way - even deleted JOIN_FOLLOWS. */
    24652465                if (N_DELETED & get_mark(*cur_link)) {
    2466                         ASSERT(cur_link != new_head);
    2467                         ASSERT(wnd.ppred && wnd.cur && wnd.cur != &sentinel);
    2468                         ASSERT(cur_link == &wnd.cur->link);
     2466                        assert(cur_link != new_head);
     2467                        assert(wnd.ppred && wnd.cur && wnd.cur != &sentinel);
     2468                        assert(cur_link == &wnd.cur->link);
    24692469
    24702470                        bool dummy;
     
    24842484                                        cas_link(cur_link, next, N_JOIN_FOLLOWS, &sentinel, N_NORMAL);
    24852485                               
    2486                                 ASSERT(next == &sentinel
     2486                                assert(next == &sentinel
    24872487                                        || ((N_JOIN | N_JOIN_FOLLOWS) & get_mark(ret)));
    24882488
     
    25052505
    25062506                /* We must encounter a JF node before we reach the end of the bucket. */
    2507                 ASSERT(wnd.cur && wnd.cur != &sentinel);
     2507                assert(wnd.cur && wnd.cur != &sentinel);
    25082508                cur_link = &wnd.cur->link;
    25092509        }
     
    25192519static inline size_t calc_split_hash(size_t split_idx, size_t order)
    25202520{
    2521         ASSERT(1 <= order && order <= 8 * sizeof(size_t));
     2521        assert(1 <= order && order <= 8 * sizeof(size_t));
    25222522        return split_idx << (8 * sizeof(size_t) - order);
    25232523}
     
    25262526static inline size_t calc_bucket_idx(size_t hash, size_t order)
    25272527{
    2528         ASSERT(1 <= order && order <= 8 * sizeof(size_t));
     2528        assert(1 <= order && order <= 8 * sizeof(size_t));
    25292529        return hash >> (8 * sizeof(size_t) - order);
    25302530}
     
    25582558static inline size_t node_hash(cht_t *h, const cht_link_t *item)
    25592559{
    2560         ASSERT(item->hash == h->invalid_hash
     2560        assert(item->hash == h->invalid_hash
    25612561                || item->hash == sentinel.hash
    25622562                || item->hash == calc_node_hash(h, item));
     
    25682568static inline size_t calc_node_hash(cht_t *h, const cht_link_t *item)
    25692569{
    2570         ASSERT(item != &sentinel);
     2570        assert(item != &sentinel);
    25712571        /*
    25722572         * Clear the lowest order bit in order for sentinel's node hash
     
    25872587        marked_ptr_t ptr = (marked_ptr_t) next;
    25882588       
    2589         ASSERT(!(ptr & N_MARK_MASK));
    2590         ASSERT(!((unsigned)mark & ~N_MARK_MASK));
     2589        assert(!(ptr & N_MARK_MASK));
     2590        assert(!((unsigned)mark & ~N_MARK_MASK));
    25912591       
    25922592        return ptr | mark;
     
    26082608static inline void next_wnd(wnd_t *wnd)
    26092609{
    2610         ASSERT(wnd);
    2611         ASSERT(wnd->cur);
     2610        assert(wnd);
     2611        assert(wnd->cur);
    26122612
    26132613        wnd->last = wnd->cur;
     
    26352635        marked_ptr_t new)
    26362636{
    2637         ASSERT(link != &sentinel.link);
     2637        assert(link != &sentinel.link);
    26382638        /*
    26392639         * cas(x) on the same location x on one cpu must be ordered, but do not
Note: See TracChangeset for help on using the changeset viewer.