diff options
author | Amar Tumballi <amar@gluster.com> | 2011-03-16 09:38:21 +0000 |
---|---|---|
committer | Vijay Bellur <vijay@dev.gluster.com> | 2011-03-17 11:57:11 -0700 |
commit | ebe47d5dae42da18b289e7be44eb67a8157a56b1 (patch) | |
tree | 13d3c68f86ca5dec97f8a1ca183d801bc9d3c92b /libglusterfs/src/mem-pool.h | |
parent | ce01662eefb575d1afe397486653920ec101f40f (diff) |
libglusterfs: gf_log_nomem() and other minor updates
log will be done when the memory allocation fails, hence in code,
no explicit logs required for memory allocation failures.
also, if there are logs before actually doing a log_init(), they will
be logged in 'stderr'.
Signed-off-by: Amar Tumballi <amar@gluster.com>
Signed-off-by: Vijay Bellur <vijay@dev.gluster.com>
BUG: 2346 (Log message enhancements in GlusterFS - phase 1)
URL: http://bugs.gluster.com/cgi-bin/bugzilla3/show_bug.cgi?id=2346
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 0cda62fb85b..85ceeb87e06 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 |