Commit 4a329a8f authored by Leif Walsh's avatar Leif Walsh Committed by Yoni Fogel

refs #5537 replace non-abstracted function calls with calls into the portability layer

git-svn-id: file:///svn/toku/tokudb@48401 c7de825b-a66e-492c-adef-691d508d4ae1
parent 6e7e2670
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include <db.h> #include <db.h>
#include <sys/stat.h> #include <sys/stat.h>
#include "ydb-internal.h" #include "ydb-internal.h"
#include <memory.h>
#include <dlfcn.h> #include <dlfcn.h>
DB_ENV *env; DB_ENV *env;
...@@ -40,18 +41,9 @@ size_t hiwater_start; ...@@ -40,18 +41,9 @@ size_t hiwater_start;
static long long mcount = 0, fcount=0; static long long mcount = 0, fcount=0;
typedef size_t (*malloc_usable_size_fun_t)(void *p);
#if defined(HAVE_MALLOC_USABLE_SIZE)
extern "C" size_t malloc_usable_size(void *p);
static malloc_usable_size_fun_t malloc_usable_size_f = malloc_usable_size;
#elif defined(HAVE_MALLOC_SIZE)
extern "C" size_t malloc_size(void *p);
static malloc_usable_size_fun_t malloc_usable_size_f = malloc_size;
#endif
static void my_free(void*p) { static void my_free(void*p) {
if (p) { if (p) {
water-=malloc_usable_size_f(p); water-=toku_malloc_usable_size(p);
} }
free(p); free(p);
} }
...@@ -59,18 +51,18 @@ static void my_free(void*p) { ...@@ -59,18 +51,18 @@ static void my_free(void*p) {
static void *my_malloc(size_t size) { static void *my_malloc(size_t size) {
void *r = malloc(size); void *r = malloc(size);
if (r) { if (r) {
water += malloc_usable_size_f(r); water += toku_malloc_usable_size(r);
if (water>hiwater) hiwater=water; if (water>hiwater) hiwater=water;
} }
return r; return r;
} }
static void *my_realloc(void *p, size_t size) { static void *my_realloc(void *p, size_t size) {
size_t old_usable = p ? malloc_usable_size_f(p) : 0; size_t old_usable = p ? toku_malloc_usable_size(p) : 0;
void *r = realloc(p, size); void *r = realloc(p, size);
if (r) { if (r) {
water -= old_usable; water -= old_usable;
water += malloc_usable_size_f(r); water += toku_malloc_usable_size(r);
} }
return r; return r;
} }
......
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
#include <db.h> #include <db.h>
#include <sys/stat.h> #include <sys/stat.h>
#include "ydb-internal.h" #include "ydb-internal.h"
#include <memory.h>
#include <dlfcn.h> #include <dlfcn.h>
DB_ENV *env; DB_ENV *env;
...@@ -48,19 +49,9 @@ size_t water; ...@@ -48,19 +49,9 @@ size_t water;
size_t hiwater_start; size_t hiwater_start;
static long long mcount = 0, fcount=0; static long long mcount = 0, fcount=0;
typedef size_t (*malloc_usable_size_fun_t)(void *p);
#if defined(HAVE_MALLOC_USABLE_SIZE)
extern "C" size_t malloc_usable_size(void *p);
static malloc_usable_size_fun_t malloc_usable_size_f = malloc_usable_size;
#elif defined(HAVE_MALLOC_SIZE)
extern "C" size_t malloc_size(void *p);
static malloc_usable_size_fun_t malloc_usable_size_f = malloc_size;
#endif
static void my_free(void*p) { static void my_free(void*p) {
if (p) { if (p) {
water-=malloc_usable_size_f(p); water-=toku_malloc_usable_size(p);
} }
free(p); free(p);
} }
...@@ -68,18 +59,18 @@ static void my_free(void*p) { ...@@ -68,18 +59,18 @@ static void my_free(void*p) {
static void *my_malloc(size_t size) { static void *my_malloc(size_t size) {
void *r = malloc(size); void *r = malloc(size);
if (r) { if (r) {
water += malloc_usable_size_f(r); water += toku_malloc_usable_size(r);
if (water>hiwater) hiwater=water; if (water>hiwater) hiwater=water;
} }
return r; return r;
} }
static void *my_realloc(void *p, size_t size) { static void *my_realloc(void *p, size_t size) {
size_t old_usable = p ? malloc_usable_size_f(p) : 0; size_t old_usable = p ? toku_malloc_usable_size(p) : 0;
void *r = realloc(p, size); void *r = realloc(p, size);
if (r) { if (r) {
water -= old_usable; water -= old_usable;
water += malloc_usable_size_f(r); water += toku_malloc_usable_size(r);
} }
return r; return r;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment