aboutsummaryrefslogtreecommitdiffstats
path: root/src/libserver/task.c
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2018-10-29 13:19:14 +0000
committerVsevolod Stakhov <vsevolod@highsecure.ru>2018-10-29 13:19:14 +0000
commit34f0b5587e72a7f77425d9faccac8b03b363fdcc (patch)
tree1a03c4c065315bdbdf02f47bfc6c9e64ab90e7d7 /src/libserver/task.c
parent8376bed06ce63da58256c383f1899f17094140d1 (diff)
downloadrspamd-34f0b5587e72a7f77425d9faccac8b03b363fdcc.tar.gz
rspamd-34f0b5587e72a7f77425d9faccac8b03b363fdcc.zip
[Rework] Change time handling
Diffstat (limited to 'src/libserver/task.c')
-rw-r--r--src/libserver/task.c40
1 files changed, 36 insertions, 4 deletions
diff --git a/src/libserver/task.c b/src/libserver/task.c
index 061feaded..de2745701 100644
--- a/src/libserver/task.c
+++ b/src/libserver/task.c
@@ -62,8 +62,9 @@ rspamd_request_header_dtor (gpointer p)
*/
struct rspamd_task *
rspamd_task_new (struct rspamd_worker *worker, struct rspamd_config *cfg,
- rspamd_mempool_t *pool,
- struct rspamd_lang_detector *lang_det)
+ rspamd_mempool_t *pool,
+ struct rspamd_lang_detector *lang_det,
+ struct event_base *ev_base)
{
struct rspamd_task *new_task;
@@ -89,8 +90,23 @@ rspamd_task_new (struct rspamd_worker *worker, struct rspamd_config *cfg,
}
}
+ new_task->ev_base = ev_base;
+
+#ifdef HAVE_EVENT_NO_CACHE_TIME_FUNC
+ if (ev_base) {
+ event_base_update_cache_time (ev_base);
+ event_base_gettimeofday_cached (ev_base, &new_task->tv);
+ new_task->time_real = tv_to_double (&new_task->tv);
+ }
+ else {
+ gettimeofday (&new_task->tv, NULL);
+ new_task->time_real = tv_to_double (&new_task->tv);
+ }
+#else
gettimeofday (&new_task->tv, NULL);
- new_task->time_real = rspamd_get_ticks (FALSE);
+ new_task->time_real = tv_to_double (&new_task->tv);
+#endif
+
new_task->time_virtual = rspamd_get_virtual_ticks ();
new_task->time_real_finish = NAN;
new_task->time_virtual_finish = NAN;
@@ -1645,8 +1661,24 @@ rspamd_task_profile_get (struct rspamd_task *task, const gchar *key)
gboolean
rspamd_task_set_finish_time (struct rspamd_task *task)
{
+ struct timeval tv;
+
if (isnan (task->time_real_finish)) {
- task->time_real_finish = rspamd_get_ticks (FALSE);
+
+#ifdef HAVE_EVENT_NO_CACHE_TIME_FUNC
+ if (task->ev_base) {
+ event_base_update_cache_time (task->ev_base);
+ event_base_gettimeofday_cached (task->ev_base, &tv);
+ task->time_real_finish = tv_to_double (&tv);
+ }
+ else {
+ gettimeofday (&tv, NULL);
+ task->time_real_finish = tv_to_double (&tv);
+ }
+#else
+ gettimeofday (&tv, NULL);
+ task->time_real_finish = tv_to_double (&tv);
+#endif
task->time_virtual_finish = rspamd_get_virtual_ticks ();
return TRUE;