Beispiel #1
0
Ob Carrier::try_insert () const
{
    SharedLock lock(m_mutex);

    while (item_count() < item_dim()) {
        for (Ob ob = 1, end = item_dim(); ob <= end; ++ob) {
            Ob zero = 0;
            // This could be optimized using m_support iteration.
            // See DenseSet::try_insert for example low-level code.
            bool inserted = m_reps[ob].compare_exchange_strong(
                    zero,
                    ob,
                    std::memory_order_acq_rel,
                    std::memory_order_acquire);
            if (unlikely(inserted)) {
                m_support.insert(ob, std::memory_order_release);
                ++m_item_count;
                ++m_rep_count;
                if (m_insert_callback) {
                    m_insert_callback(ob);
                }
                // The following triggers a weird gcc bug or something
                // error: invalid memory model for ‘__atomic_load
                //POMAGMA_DEBUG1(m_item_count.load() << " obs after insert()");
                return ob;
            }
        }
    }

    return 0;
}
Beispiel #2
0
inline void SymmetricFunction::insert(Ob lhs, Ob rhs, Ob val) const {
    SharedLock lock(m_mutex);

    POMAGMA_ASSERT5(support().contains(lhs), "unsupported lhs: " << lhs);
    POMAGMA_ASSERT5(support().contains(rhs), "unsupported rhs: " << rhs);
    POMAGMA_ASSERT5(support().contains(val), "unsupported val: " << val);

    if (carrier().set_or_merge(value(lhs, rhs), val)) {
        m_lines.Lx(lhs, rhs).one();
        m_lines.Rx(lhs, rhs).one();
        m_Vlr_table.insert(lhs, rhs, val);
        m_Vlr_table.insert(rhs, lhs, val);
        m_VLr_table.insert(lhs, rhs, val);
        m_VLr_table.insert(rhs, lhs, val);
        m_insert_callback(this, lhs, rhs);
    }
}
Beispiel #3
0
inline void BinaryRelation::insert_Rx(Ob i, Ob j) {
    if (not m_lines.Rx(i, j).fetch_one()) {
        _insert_Lx(i, j);
        m_insert_callback(i, j);
    }
}