]> AND Public Git Repository - simgrid.git/blobdiff - src/xbt/mmalloc/mmprivate.h
Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Update copyright lines for 2023.
[simgrid.git] / src / xbt / mmalloc / mmprivate.h
index 2756de438ea869b505d94f06adf76d5cd479805f..76b459c107f63a58f448b72c4d070ac7f0655400 100644 (file)
@@ -1,6 +1,6 @@
 /* Declarations for `mmalloc' and friends. */
 
-/* Copyright (c) 2010-2022. The SimGrid Team. All rights reserved.          */
+/* Copyright (c) 2010-2023. 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. */
@@ -18,7 +18,6 @@
 #include "xbt/mmalloc.h"
 
 #include <limits.h>
-#include <pthread.h>
 #include <stdint.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -94,7 +93,7 @@ XBT_PRIVATE xbt_mheap_t mmalloc_preinit(void);
 
 /* Address to block number and vice versa.  */
 
-#define BLOCK(A) (((char*) (A) - (char*) mdp -> heapbase) / BLOCKSIZE + 1)
+#define BLOCK(A) ((size_t)(((char*)(A) - (char*)mdp->heapbase) / BLOCKSIZE + 1))
 
 #define ADDRESS(B) ((void*) (((ADDR2UINT(B)) - 1) * BLOCKSIZE + (char*) mdp -> heapbase))
 
@@ -174,9 +173,6 @@ typedef struct {
  * if such a file exists.
  * */
 struct mdesc {
-  /** @brief Mutex locking the access to the heap */
-  pthread_mutex_t mutex;
-
   /** @brief Chained lists of mdescs */
   struct mdesc *next_mdesc;
 
@@ -261,19 +257,18 @@ XBT_PUBLIC_DATA struct mdesc* __mmalloc_default_mdp;
 
 XBT_PUBLIC void* mmorecore(struct mdesc* mdp, ssize_t size);
 
-/** Thread-safety (if the mutex is already created)
- *
- * This is mandatory in the case where the user runs a parallel simulation
- * in a model-checking enabled tree. Without this protection, our malloc
- * implementation will not like multi-threading AT ALL.
- */
-#define LOCK(mdp) pthread_mutex_lock(&(mdp)->mutex)
-#define UNLOCK(mdp) pthread_mutex_unlock(&(mdp)->mutex)
-
-XBT_PRIVATE int malloc_use_mmalloc(void);
-
 XBT_PRIVATE size_t mmalloc_get_bytes_used_remote(size_t heaplimit, const malloc_info* heapinfo);
 
+/* We call dlsym during mmalloc initialization, but dlsym uses malloc.
+ * So during mmalloc initialization, any call to malloc is diverted to a private static buffer.
+ */
+extern uint64_t* mmalloc_preinit_buffer;
+#ifdef __FreeBSD__ /* FreeBSD require more memory, other might */
+#define mmalloc_preinit_buffer_size 256
+#else /* Valid on: Linux */
+#define mmalloc_preinit_buffer_size 32
+#endif
+
 SG_END_DECL
 
 #endif