Skip to content
Snippets Groups Projects
Commit b012b84a authored by Marek Vavrusa's avatar Marek Vavrusa
Browse files

Added checks for malloc_trim() as it is GNU extension.

refs #187
parent dcaa485f
No related branches found
No related tags found
No related merge requests found
......@@ -325,7 +325,7 @@ AC_TYPE_SIZE_T
AC_TYPE_SSIZE_T
# Checks for library functions.
AC_CHECK_FUNCS([clock_gettime gettimeofday fgetln getline madvise poll posix_memalign pselect pthread_setaffinity_np regcomp select setgroups initgroups])
AC_CHECK_FUNCS([clock_gettime gettimeofday fgetln getline madvise malloc_trim poll posix_memalign pselect pthread_setaffinity_np regcomp select setgroups initgroups])
# Check for be64toh function
AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <endian.h>]], [[return be64toh(0);]])],
......
......@@ -20,6 +20,7 @@
#include <string.h>
#include <sys/resource.h>
#include <stdarg.h>
#include <malloc.h>
#include "common/mempattern.h"
#include "common/log.h"
......@@ -172,3 +173,11 @@ void usage_dump()
usage.ru_nivcsw);
fprintf(stderr, "==================\n");
}
/*! \brief Trim excess heap memory. */
void mem_trim(void)
{
#ifdef HAVE_MALLOC_TRIM
malloc_trim(0);
#endif
}
......@@ -28,7 +28,6 @@
#define _KNOTD_COMMON_MALLOC_H_
#include <stddef.h>
#include <malloc.h>
/* Memory allocation function prototypes. */
typedef void* (*mm_alloc_t)(void* ctx, size_t len);
......@@ -112,10 +111,7 @@ char* strcdup(const char *s1, const char *s2);
void usage_dump();
/*! \brief Trim excess heap memory. */
static inline void mem_trim(void)
{
malloc_trim(0);
}
void mem_trim(void);
#endif // _KNOTD_COMMON_MALLOC_H_
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment