Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/parser.tmpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,8 @@ void parser<C, T>::complete(const item& i, container_t& t, container_t& c,
// Predictor may have been evicted from S; it can still drive
// completion only if conjunction-cascade machinery kept it in U.
bool in_S = S[it->set].find(*it) != S[it->set].end();
bool in_U = any_conj && it->set < U.size()
const size_t predictor_set = it->set;
bool in_U = any_conj && predictor_set < U.size()
&& U[it->set].find(*it) != U[it->set].end();
if (!in_S && !in_U) continue;
DBGP(print(std::cout << " ? checking \t\t\t\t", *it) << "\n";)
Expand Down
10 changes: 8 additions & 2 deletions src/utility/tree.h
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,10 @@ struct bintree {
*/
inline static std::atomic<bool> gc_enabled{true};
// Protects M() and gc_callbacks; shared for reads, exclusive for writes/gc.
inline static std::shared_mutex mtx_{};
static std::shared_mutex& mutex() {
static std::shared_mutex value;
return value;
}

/**
* @brief Garbage collect tree nodes
Expand Down Expand Up @@ -891,7 +894,10 @@ struct lcrs_tree : public bintree<T> {
= std::function<tref(const T&, const tref*, size_t, tref)>;
inline static hook_function hook = nullptr;
// Protects hook and use_hooks (shared for reads, exclusive for set/reset).
inline static std::shared_mutex hook_mtx_{};
static std::shared_mutex& hook_mutex() {
static std::shared_mutex value;
return value;
}
inline static void set_hook(hook_function h);
inline static void reset_hook();
inline static bool is_hooked();
Expand Down
20 changes: 10 additions & 10 deletions src/utility/tree.tmpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ tref bintree<T>::get() const { return reinterpret_cast<tref>(this); }
template <typename T>
const htref bintree<T>::geth(tref h) {
if (h == NULL) return htree::null();
std::unique_lock lock(mtx_);
std::unique_lock lock(mutex());
auto res = M().find(*reinterpret_cast<const bintree*>(h));
if (auto sp = res->second.lock()) return sp;
htref ret(new htree(h));
Expand All @@ -129,13 +129,13 @@ tref bintree<T>::get(const T& v, tref l, tref r) {
bintree bn(v, l, r);
// Fast path: shared lock for the common case where the node already exists.
{
std::shared_lock lock(mtx_);
std::shared_lock lock(mutex());
auto it = M().find(bn);
if (it != M().end())
return reinterpret_cast<tref>(std::addressof(it->first));
}
// Slow path: exclusive lock to insert (double-check after acquiring).
std::unique_lock lock(mtx_);
std::unique_lock lock(mutex());
auto res = M().emplace(bn, htree::wp());
return reinterpret_cast<tref>(std::addressof(res.first->first));
}
Expand Down Expand Up @@ -164,7 +164,7 @@ void bintree<T>::gc() {
template <typename T>
void bintree<T>::gc(std::unordered_set<tref>& keep) {
if (!gc_enabled.load(std::memory_order_relaxed)) return;
std::unique_lock lock(mtx_);
std::unique_lock lock(mutex());
// DBG(dump();)
//DBG(htree::dump();)

Expand Down Expand Up @@ -260,7 +260,7 @@ template <CacheType cache_t>
cache_t& bintree<T>::create_cache(const cache_t& init) {
static std::deque<cache_t> caches;
// Protect both caches and the gc callback lists under the exclusive lock.
std::unique_lock lock(mtx_);
std::unique_lock lock(mutex());
cache_t& cache = caches.emplace_back(init);

// Pre-sweep: once this entry's key is fully reachable, its value's
Expand Down Expand Up @@ -525,10 +525,10 @@ tref lcrs_tree<T>::get_raw(const T& v, const tref* ch, size_t len, tref r) {
template <typename T>
tref lcrs_tree<T>::get(const T& v, const tref* ch, size_t len, tref r) {
// Snapshot hook under shared lock; call it after releasing the lock
// to avoid holding hook_mtx_ while bintree::get() acquires mtx_.
// to avoid holding hook_mutex() while bintree::get() acquires mutex().
hook_function h;
{
std::shared_lock lock(hook_mtx_);
std::shared_lock lock(hook_mutex());
if (!use_hooks || !hook) return get_raw(v, ch, len, r);
h = hook;
}
Expand Down Expand Up @@ -993,19 +993,19 @@ std::string dump_to_str(const subtree_map<node, tref>& m, bool subtree) {

template <typename node>
void lcrs_tree<node>::set_hook(hook_function h) {
std::unique_lock lock(hook_mtx_);
std::unique_lock lock(hook_mutex());
hook = h;
}

template <typename node>
void lcrs_tree<node>::reset_hook() {
std::unique_lock lock(hook_mtx_);
std::unique_lock lock(hook_mutex());
hook = nullptr;
}

template <typename node>
bool lcrs_tree<node>::is_hooked() {
std::shared_lock lock(hook_mtx_);
std::shared_lock lock(hook_mutex());
return hook != nullptr;
}

Expand Down