1
0
Fork 0
mirror of https://github.com/warmcat/libwebsockets.git synced 2025-03-09 00:00:04 +01:00

malloc_trim: move out of unix plat and into lwsws

https://github.com/warmcat/libwebsockets/issues/1849
This commit is contained in:
Andy Green 2020-02-24 10:06:43 +00:00
parent 5d74cf668c
commit 62f22c9e0e
3 changed files with 28 additions and 11 deletions

View file

@ -1082,7 +1082,7 @@ lws_context_destroy(struct lws_context *context)
if (!context->being_destroyed2) {
lws_context_destroy2(context);
goto out;
return;
}
lwsl_info("%s: ctx %p: already being destroyed\n",
__func__, context);
@ -1180,6 +1180,8 @@ lws_context_destroy(struct lws_context *context)
return;
#if defined(LWS_WITH_NETWORK)
out:
context->inside_context_destroy = 0;
#endif
}

View file

@ -35,10 +35,6 @@
#endif
#include <dirent.h>
#if defined(LWS_HAVE_MALLOC_TRIM)
#include <malloc.h>
#endif
#if defined(LWS_WITH_NETWORK)
static void
lws_sul_plat_unix(lws_sorted_usec_list_t *sul)
@ -53,9 +49,6 @@ lws_sul_plat_unix(lws_sorted_usec_list_t *sul)
kill(pt->context->started_with_parent, 0) < 0)
kill(getpid(), SIGTERM);
#endif
#if defined(LWS_HAVE_MALLOC_TRIM)
malloc_trim(4 * 1024);
#endif
if (pt->context->deprecated && !pt->context->count_wsi_allocated) {
lwsl_notice("%s: ending deprecated context\n", __func__);

View file

@ -1,7 +1,7 @@
/*
* libwebsockets web server application
*
* Written in 2010-2019 by Andy Green <andy@warmcat.com>
* Written in 2010-2020 by Andy Green <andy@warmcat.com>
*
* This file is made available under the Creative Commons CC0 1.0
* Universal Public Domain Dedication.
@ -51,7 +51,12 @@ int fork(void)
#include <uv.h>
#if defined(LWS_HAVE_MALLOC_TRIM)
#include <malloc.h>
#endif
static struct lws_context *context;
static lws_sorted_usec_list_t sul_lwsws;
static char config_dir[128];
static int opts = 0, do_reload = 1;
static uv_loop_t loop;
@ -111,6 +116,18 @@ void signal_cb(uv_signal_t *watcher, int signum)
lws_context_destroy(context);
}
static void
lwsws_min(lws_sorted_usec_list_t *sul)
{
lwsl_debug("%s\n", __func__);
#if defined(LWS_HAVE_MALLOC_TRIM)
malloc_trim(4 * 1024);
#endif
lws_sul_schedule(context, 0, &sul_lwsws, lwsws_min, 60 * LWS_US_PER_SEC);
}
static int
context_creation(void)
{
@ -162,6 +179,8 @@ context_creation(void)
if (lwsws_get_config_vhosts(context, &info, config_dir, &cs, &cs_len))
return 1;
lws_sul_schedule(context, 0, &sul_lwsws, lwsws_min, 60 * LWS_US_PER_SEC);
return 0;
init_failed:
@ -287,8 +306,8 @@ int main(int argc, char **argv)
lws_set_log_level(debug_level, lwsl_emit_stderr_notimestamp);
lwsl_notice("lwsws libwebsockets web server - license CC0 + LGPL2.1\n");
lwsl_notice("(C) Copyright 2010-2018 Andy Green <andy@warmcat.com>\n");
lwsl_notice("lwsws libwebsockets web server - license CC0 + MIT\n");
lwsl_notice("(C) Copyright 2010-2020 Andy Green <andy@warmcat.com>\n");
#if (UV_VERSION_MAJOR > 0) // Travis...
uv_loop_init(&loop);
@ -315,6 +334,9 @@ int main(int argc, char **argv)
uv_close((uv_handle_t *)&signal_outer[n], NULL);
}
/* cancel the per-minute sul */
lws_sul_schedule(context, 0, &sul_lwsws, NULL, LWS_SET_TIMER_USEC_CANCEL);
lws_context_destroy(context);
(void)budget;
#if (UV_VERSION_MAJOR > 0) // Travis...