summaryrefslogtreecommitdiffstats
path: root/libglusterfs/src/mem-pool.h
diff options
context:
space:
mode:
authorAmar Tumballi <amar@gluster.com>2011-03-16 09:38:21 +0000
committerVijay Bellur <vijay@dev.gluster.com>2011-03-17 11:57:11 -0700
commitebe47d5dae42da18b289e7be44eb67a8157a56b1 (patch)
tree13d3c68f86ca5dec97f8a1ca183d801bc9d3c92b /libglusterfs/src/mem-pool.h
parentce01662eefb575d1afe397486653920ec101f40f (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.h64
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