Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[mc] Move some SIMIX inspection code in the Process class
[simgrid.git] / src / xbt / mallocator.c
index 3acc9b3..04d9cc2 100644 (file)
@@ -1,11 +1,12 @@
 /* mallocator - recycle objects to avoid malloc() / free()                  */
 
-/* Copyright (c) 2006-2011. The SimGrid Team.
+/* Copyright (c) 2006-2014. The SimGrid Team.
  * All rights reserved.                                                     */
 
 /* This program is free software; you can redistribute it and/or modify it
  * under the terms of the license (GNU LGPL) which comes with this package. */
 
+#include "src/internal_config.h"
 #include "xbt/mallocator.h"
 #include "xbt/asserts.h"
 #include "xbt/sysdep.h"
@@ -42,16 +43,12 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(xbt_mallocator, xbt, "Mallocators");
  * mallocators should be protected from concurrent accesses.  */
 static int initialization_done = 0;
 
-static XBT_INLINE void lock_create(xbt_mallocator_t m)
+static inline void lock_reset(xbt_mallocator_t m)
 {
   m->lock = 0;
 }
 
-static XBT_INLINE void lock_destroy(xbt_mallocator_t m)
-{
-}
-
-static XBT_INLINE void lock_acquire(xbt_mallocator_t m)
+static inline void lock_acquire(xbt_mallocator_t m)
 {
   if (initialization_done > 1) {
     int *lock = &m->lock;
@@ -60,7 +57,7 @@ static XBT_INLINE void lock_acquire(xbt_mallocator_t m)
   }
 }
 
-static XBT_INLINE void lock_release(xbt_mallocator_t m)
+static inline void lock_release(xbt_mallocator_t m)
 {
   if (initialization_done > 1)
     __sync_lock_release(&m->lock);
@@ -80,8 +77,8 @@ void xbt_mallocator_initialization_is_done(int protect)
 }
 
 /** used by the module to know if it's time to activate the mallocators yet */
-static XBT_INLINE int xbt_mallocator_is_active(void) {
-#if MALLOCATOR_COMPILED_IN
+static inline int xbt_mallocator_is_active(void) {
+#if HAVE_MALLOCATOR
   return initialization_done && !MC_is_active();
 #else
   return 0;
@@ -147,7 +144,6 @@ void xbt_mallocator_free(xbt_mallocator_t m)
     m->free_f(m->objects[i]);
   }
   xbt_free(m->objects);
-  lock_destroy(m);
   xbt_free(m);
 }
 
@@ -195,7 +191,7 @@ void *xbt_mallocator_get(xbt_mallocator_t m)
     if (xbt_mallocator_is_active()) {
       // We have to switch this mallocator from inactive to active (and then get an object)
       m->objects = xbt_new0(void *, m->max_size);
-      lock_create(m);
+      lock_reset(m);
       return xbt_mallocator_get(m);
     } else {
       object = m->new_f();
@@ -242,7 +238,7 @@ void xbt_mallocator_release(xbt_mallocator_t m, void *object)
     if (xbt_mallocator_is_active()) {
       // We have to switch this mallocator from inactive to active (and then store that object)
       m->objects = xbt_new0(void *, m->max_size);
-      lock_create(m);
+      lock_reset(m);
       xbt_mallocator_release(m,object);
     } else {
       m->free_f(object);