예제 #1
0
파일: cache.cpp 프로젝트: gadomski/entwine
void Cache::unrefHierarchy(
        const std::string& name,
        const HierarchyReader::Slots& touched)
{
    if (touched.empty()) return;

    std::lock_guard<std::mutex> topLock(m_hierarchyMutex);
    HierarchyCache& selected(m_hierarchyCache[name]);
    std::lock_guard<std::mutex> selectedLock(selected.mutex);

    auto& slots(selected.slots);
    auto& order(selected.order);
    auto& refs(selected.refs);

    for (const HierarchyReader::Slot* s : touched)
    {
        assert(refs.at(s) >= 1);
        --refs.at(s);

        if (slots.count(s))
        {
            order.splice(order.begin(), order, slots.at(s));
        }
        else
        {
            auto it(slots.insert(std::make_pair(s, order.end())).first);
            order.push_front(s);
            it->second = order.begin();

            m_hierarchyBytes += s->t->size();
        }
    }

    const auto begin(m_hierarchyBytes);
    while (
            m_hierarchyBytes > m_maxHierarchyBytes &&
            order.size() &&
            !refs[order.back()])
    {
        const HierarchyReader::Slot* s(order.back());
        order.pop_back();

        SpinGuard spinLock(s->spinner);
        m_hierarchyBytes -= s->t->size();
        s->t.reset();
        slots.erase(s);
    }
    const auto end(m_hierarchyBytes);

    if (begin != end)
    {
        std::cout <<
            "\tHB " << begin << " -> " << end <<
            "\tHier: " << (m_hierarchyBytes / 1024 / 1024) << "MB" <<
            "\tFetches: " << touched.size() << std::endl;
    }

    assert(order.size() == slots.size());
}
예제 #2
0
파일: cache.cpp 프로젝트: gadomski/entwine
void Cache::refHierarchySlot(
        const std::string& name,
        const HierarchyReader::Slot* slot)
{
    std::lock_guard<std::mutex> topLock(m_hierarchyMutex);
    HierarchyCache& selected(m_hierarchyCache[name]);
    std::lock_guard<std::mutex> selectedLock(selected.mutex);

    if (selected.refs.count(slot)) ++selected.refs[slot];
    else selected.refs[slot] = 1;
}
예제 #3
0
void LuaValue::clear() {
    if (data_) {
        if (data_->type_==Type_NIL) { return; }
        std::shared_ptr<lua_State> ls_=data_->luaState_.lock();
        if (ls_) {
            lua_State * L=ls_.get();
            __cct::__private::TopLock topLock(L);

            __cct::__private::PointerSet * _ts_=
                reinterpret_cast<__cct::__private::PointerSet *>(getTypeSet(L,data_->type_));

            _ts_->used.erase(data_->pointer_);
            _ts_->unused.insert(data_->pointer_);

            lua_rawgetp(L,LUA_REGISTRYINDEX,getTablePathPointer(data_->type_));
            if (lua_istable(L,-1)) {
                lua_pushnil(L);
                lua_rawseti(L,-2,data_->pointer_);
            }
            data_->type_=Type_NIL;
        }
    }
}