diff options
Diffstat (limited to 'libglusterfs/src/mem-pool.h')
| -rw-r--r-- | libglusterfs/src/mem-pool.h | 64 | 
1 files changed, 51 insertions, 13 deletions
diff --git a/libglusterfs/src/mem-pool.h b/libglusterfs/src/mem-pool.h index 0cda62fb8..85ceeb87e 100644 --- a/libglusterfs/src/mem-pool.h +++ b/libglusterfs/src/mem-pool.h @@ -22,6 +22,7 @@  #include "list.h"  #include "locking.h" +#include "logging.h"  #include "mem-types.h"  #include <stdlib.h>  #include <inttypes.h> @@ -29,15 +30,6 @@  #include <stdarg.h> -#define MALLOC(size) malloc(size) -#define CALLOC(cnt,size) calloc(cnt,size) - -#define FREE(ptr)                               \ -        if (ptr != NULL) {                      \ -                free ((void *)ptr);             \ -                ptr = (void *)0xeeeeeeee;       \ -        } -  struct mem_acct {          uint32_t            num_types;          struct mem_acct_rec     *rec; @@ -67,16 +59,62 @@ gf_vasprintf (char **string_ptr, const char *format, va_list arg);  int  gf_asprintf (char **string_ptr, const char *format, ...); +void +__gf_free (void *ptr); + + +static inline +void* __gf_default_malloc (size_t size) +{ +        void *ptr = NULL; + +        ptr = malloc (size); +        if (!ptr) +                gf_log_nomem ("", GF_LOG_ALERT, size); + +        return ptr; +} + +static inline +void* __gf_default_calloc (int cnt, size_t size) +{ +        void *ptr = NULL; + +        ptr = calloc (cnt, size); +        if (!ptr) +                gf_log_nomem ("", GF_LOG_ALERT, (cnt * size)); + +        return ptr; +} + +static inline +void* __gf_default_realloc (void *oldptr, size_t size) +{ +        void *ptr = NULL; + +        ptr = realloc (oldptr, size); +        if (!ptr) +                gf_log_nomem ("", GF_LOG_ALERT, size); + +        return ptr; +} + +#define MALLOC(size)       __gf_default_malloc(size) +#define CALLOC(cnt,size)   __gf_default_calloc(cnt,size) +#define REALLOC(ptr,size)  __gf_default_realloc(ptr,size) + +#define FREE(ptr)                               \ +        if (ptr != NULL) {                      \ +                free ((void *)ptr);             \ +                ptr = (void *)0xeeeeeeee;       \ +        } +  #define GF_CALLOC(nmemb, size, type) __gf_calloc (nmemb, size, type)  #define GF_MALLOC(size, type)  __gf_malloc (size, type)  #define GF_REALLOC(ptr, size)  __gf_realloc (ptr, size) -void -__gf_free (void *ptr); - -  #define GF_FREE(free_ptr) __gf_free (free_ptr);  static inline  | 
