- * \brief Constructor
- * \param size size of the internal stack: number of objects the mallocator
- * will be able to store
- * \param new_f function to allocate a new object of your datatype, called
- * in \a xbt_mallocator_get() when the mallocator is empty
- * \param free_f function to free an object of your datatype, called
- * in \a xbt_mallocator_release() when the stack is full, and when
- * the mallocator is freed.
- * \param reset_f function to reinitialise an object of your datatype, called
- * when you extract an object from the mallocator (can be NULL)
+ * This function must be called once the framework configuration is done. If not, mallocators will never get used.
+ * Check the implementation notes in src/xbt/mallocator.c for the justification of this.
+ *
+ * For example, surf_config uses this function to tell to the mallocators that the simgrid configuration is now
+ * finished and that it can create them if not done yet */
+void xbt_mallocator_initialization_is_done(int protect)
+{
+ initialization_done = protect ? 2 : 1;
+}
+
+/** used by the module to know if it's time to activate the mallocators yet */
+static inline int xbt_mallocator_is_active(void) {
+#if SIMGRID_HAVE_MALLOCATOR
+ return initialization_done && !MC_is_active();
+#else
+ return 0;
+#endif
+}
+
+/**
+ * @brief Constructor
+ * @param size size of the internal stack: number of objects the mallocator will be able to store
+ * @param new_f function to allocate a new object of your datatype, called in @a xbt_mallocator_get() when the
+ * mallocator is empty
+ * @param free_f function to free an object of your datatype, called in @a xbt_mallocator_release() when the stack is
+ * full, and when the mallocator is freed.
+ * @param reset_f function to reinitialize an object of your datatype, called when you extract an object from the
+ * mallocator (can be NULL)