Skip to content

Commit

Permalink
[Minor] Add delayed condition method
Browse files Browse the repository at this point in the history
  • Loading branch information
vstakhov committed Apr 13, 2022
1 parent 3d8a528 commit c211ce5
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/libserver/symcache/symcache_c.cxx
Expand Up @@ -82,4 +82,15 @@ rspamd_symcache_set_peak_callback (struct rspamd_symcache *cache, gint cbref)
auto *real_cache = C_API_SYMCACHE(cache);

real_cache->set_peak_cb(cbref);
}

gboolean
rspamd_symcache_add_condition_delayed (struct rspamd_symcache *cache,
const gchar *sym, lua_State *L, gint cbref)
{
auto *real_cache = C_API_SYMCACHE(cache);

real_cache->add_delayed_condition(sym, cbref);

return TRUE;
}
4 changes: 4 additions & 0 deletions src/libserver/symcache/symcache_impl.cxx
Expand Up @@ -646,6 +646,10 @@ auto symcache::set_peak_cb(int cbref) -> void
msg_info_cache("registered peak callback");
}

auto symcache::add_delayed_condition(std::string_view sym, int cbref) -> void
{
delayed_conditions->emplace_back(sym, cbref, (lua_State *)cfg->lua_state);
}

auto cache_item::get_parent(const symcache &cache) const -> const cache_item *
{
Expand Down
10 changes: 10 additions & 0 deletions src/libserver/symcache/symcache_internal.hxx
Expand Up @@ -345,6 +345,9 @@ struct delayed_cache_condition {
std::string sym;
int cbref;
lua_State *L;
public:
delayed_cache_condition(std::string_view _sym, int _cbref, lua_State *_L) :
sym(_sym), cbref(_cbref), L(_L) {}
};

class symcache {
Expand Down Expand Up @@ -499,6 +502,13 @@ public:
* @param cbref
*/
auto set_peak_cb(int cbref) -> void;

/**
* Add a delayed condition for a symbol that might not be registered yet
* @param sym
* @param cbref
*/
auto add_delayed_condition(std::string_view sym, int cbref) -> void;
};

/*
Expand Down

0 comments on commit c211ce5

Please sign in to comment.