diff options
author | Vsevolod Stakhov <vsevolod@rspamd.com> | 2023-09-07 13:39:25 +0100 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@rspamd.com> | 2023-09-07 13:49:56 +0100 |
commit | 7ee372d24b5dcc4e8fcd7cf02126e13ccaf897b5 (patch) | |
tree | cb999173e27ae64d3a50a19f321303f9c01b511c /src/libserver/async_session.c | |
parent | f2803c23efc541e23e10521c2922c96cd5547604 (diff) | |
download | rspamd-7ee372d24b5dcc4e8fcd7cf02126e13ccaf897b5.tar.gz rspamd-7ee372d24b5dcc4e8fcd7cf02126e13ccaf897b5.zip |
[Minor] Minor reorg of the async session
Diffstat (limited to 'src/libserver/async_session.c')
-rw-r--r-- | src/libserver/async_session.c | 70 |
1 files changed, 27 insertions, 43 deletions
diff --git a/src/libserver/async_session.c b/src/libserver/async_session.c index 66552418a..962d51368 100644 --- a/src/libserver/async_session.c +++ b/src/libserver/async_session.c @@ -1,11 +1,11 @@ -/*- - * Copyright 2016 Vsevolod Stakhov +/* + * Copyright 2023 Vsevolod Stakhov * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -55,43 +55,15 @@ struct rspamd_async_event { void *user_data; }; -static guint rspamd_event_hash(gconstpointer a); -static gboolean rspamd_event_equal(gconstpointer a, gconstpointer b); - -/* Define **SET** of events */ -KHASH_INIT(rspamd_events_hash, - struct rspamd_async_event *, - char, - false, - rspamd_event_hash, - rspamd_event_equal); - -struct rspamd_async_session { - session_finalizer_t fin; - event_finalizer_t restore; - event_finalizer_t cleanup; - khash_t(rspamd_events_hash) * events; - void *user_data; - rspamd_mempool_t *pool; - guint flags; -}; - -static gboolean -rspamd_event_equal(gconstpointer a, gconstpointer b) +static inline bool +rspamd_event_equal(const struct rspamd_async_event *ev1, const struct rspamd_async_event *ev2) { - const struct rspamd_async_event *ev1 = a, *ev2 = b; - - if (ev1->fin == ev2->fin) { - return ev1->user_data == ev2->user_data; - } - - return FALSE; + return ev1->fin == ev2->fin && ev1->user_data == ev2->user_data; } -static guint -rspamd_event_hash(gconstpointer a) +static inline guint64 +rspamd_event_hash(const struct rspamd_async_event *ev) { - const struct rspamd_async_event *ev = a; union _pointer_fp_thunk { event_finalizer_t f; gpointer p; @@ -107,6 +79,24 @@ rspamd_event_hash(gconstpointer a) return rspamd_cryptobox_fast_hash(&st, sizeof(st), rspamd_hash_seed()); } +/* Define **SET** of events */ +KHASH_INIT(rspamd_events_hash, + struct rspamd_async_event *, + char, + false, + rspamd_event_hash, + rspamd_event_equal); + +struct rspamd_async_session { + session_finalizer_t fin; + event_finalizer_t restore; + event_finalizer_t cleanup; + khash_t(rspamd_events_hash) * events; + void *user_data; + rspamd_mempool_t *pool; + guint flags; +}; + static void rspamd_session_dtor(gpointer d) { @@ -134,13 +124,7 @@ rspamd_session_create(rspamd_mempool_t *pool, s->user_data = user_data; s->events = kh_init(rspamd_events_hash); - if (events_count.mean > 4) { - kh_resize(rspamd_events_hash, s->events, events_count.mean); - } - else { - kh_resize(rspamd_events_hash, s->events, 4); - } - + kh_resize(rspamd_events_hash, s->events, MAX(4, events_count.mean)); rspamd_mempool_add_destructor(pool, rspamd_session_dtor, s); return s; |