Skip to content

Commit

Permalink
Merge pull request #1478 from ampli/fmacro
Browse files Browse the repository at this point in the history
RUSAGE_THREAD, malloc_trim(): Check features directly
  • Loading branch information
linas authored Mar 27, 2024
2 parents 789d8db + 785776a commit 1127b98
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ AC_LANG([C])

AC_C_CONST

AC_CHECK_FUNCS(strndup strtok_r sigaction)
AC_CHECK_FUNCS(strndup strtok_r sigaction malloc_trim)
AC_CHECK_FUNCS(aligned_alloc posix_memalign _aligned_malloc)

AC_FUNC_ALLOCA
Expand Down
4 changes: 2 additions & 2 deletions link-grammar/parse/extract-links.c
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ void free_extractor(extractor_t * pex)
pex->x_table_size = 0;
pex->x_table = NULL;

#if defined __GLIBC__
#if HAVE_MALLOC_TRIM
// MST parsing can result in pathological cases, with almost a
// billion elts in the Parse_choice_pool. This blows up the
// resident-set size (RSS) over time. Avoid this issue by trimming.
Expand All @@ -298,7 +298,7 @@ void free_extractor(extractor_t * pex)

xfree((void *) pex, sizeof(extractor_t));

#if defined __GLIBC__
#if HAVE_MALLOC_TRIM
// malloc_trim() is a gnu extension. An alternative would be
// to call madvise(MADV_DONTNEED) but this is more complicated.
if (trim) malloc_trim(0);
Expand Down
2 changes: 1 addition & 1 deletion link-grammar/resources.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ int getrusage(int who, struct rusage *rusage);
/** Returns the CPU usage time, for this thread only, in seconds. */
static double current_usage_time(void)
{
#if !defined(_WIN32) && !defined(__APPLE__)
#if defined RUSAGE_THREAD
struct rusage u;
getrusage (RUSAGE_THREAD, &u);
return (u.ru_utime.tv_sec + ((double) u.ru_utime.tv_usec) / 1000000.0);
Expand Down

0 comments on commit 1127b98

Please sign in to comment.