From e40ef4996aedb6cc7677b2d807fdb7d4a252132d Mon Sep 17 00:00:00 2001 From: "W. Eric Norum" Date: Sun, 11 May 2008 21:28:55 +0000 Subject: [PATCH] Fix up free space calculation. --- src/RTEMS/base/rtems_init.c | 18 ++++++++---------- src/libCom/osi/os/RTEMS/osdPoolStatus.c | 8 +++++--- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/RTEMS/base/rtems_init.c b/src/RTEMS/base/rtems_init.c index 3daad57d2..f439ee474 100644 --- a/src/RTEMS/base/rtems_init.c +++ b/src/RTEMS/base/rtems_init.c @@ -323,17 +323,15 @@ static void netStatCallFunc(const iocshArgBuf *args) static const iocshFuncDef heapSpaceFuncDef = {"heapSpace",0,NULL}; static void heapSpaceCallFunc(const iocshArgBuf *args) { - rtems_malloc_statistics_t stats; + rtems_malloc_statistics_t s; + double x; - malloc_get_statistics(&stats); - if (stats.space_available >= 1024*1024) { - double x = (double)stats.space_available / (1024 * 1024); - printf("Heap space: %.1f MB\n", x); - } - else { - double x = (double)stats.space_available / 1024; - printf("Heap space: %.1f kB\n", x); - } + malloc_get_statistics(&s); + x = s.space_available - (unsigned long)(s.lifetime_allocated - s.lifetime_freed); + if (x >= 1024*1024) + printf("Heap space: %.1f MB\n", x / (1024 * 1024)); + else + printf("Heap space: %.1f kB\n", x / 1024); } #ifndef OMIT_NFS_SUPPORT diff --git a/src/libCom/osi/os/RTEMS/osdPoolStatus.c b/src/libCom/osi/os/RTEMS/osdPoolStatus.c index 9adb81031..b2f401190 100644 --- a/src/libCom/osi/os/RTEMS/osdPoolStatus.c +++ b/src/libCom/osi/os/RTEMS/osdPoolStatus.c @@ -17,8 +17,10 @@ */ epicsShareFunc int epicsShareAPI osiSufficentSpaceInPool ( size_t contiguousBlockSize ) { - rtems_malloc_statistics_t stats; + rtems_malloc_statistics_t s; + unsigned long n; - malloc_get_statistics(&stats); - return (stats.space_available > (50000 + contiguousBlockSize)); + malloc_get_statistics(&s); + n = s.space_available - (unsigned long)(s.lifetime_allocated - s.lifetime_freed); + return (n > (50000 + contiguousBlockSize)); }