[m-rev.] for review: Add missing MR_GC_malloc_atomic procedure

Paul Bone paul at bone.id.au
Tue Apr 15 22:20:02 AEST 2014


For review by anyone.

Branches: master

---

Add missing MR_GC_malloc_atomic procedure

In the runtime system we create wrappers for a number of procedures from the
Boehm GC, this helps provide portability incase we change garbage
collectors or compile without garbage collection support.

This patch adds the useful MR_GC_malloc_atomic procedure to this set of
procedures.

runtime/mercury_memory.c:
runtime/mercury_memory.h:
    As above.
---
 runtime/mercury_memory.c | 18 ++++++++++++++++++
 runtime/mercury_memory.h |  6 ++++++
 2 files changed, 24 insertions(+)

diff --git a/runtime/mercury_memory.c b/runtime/mercury_memory.c
index 76769cf..3189143 100644
--- a/runtime/mercury_memory.c
+++ b/runtime/mercury_memory.c
@@ -347,6 +347,24 @@ MR_GC_malloc(size_t num_bytes)
 }
 
 void *
+MR_GC_malloc_atomic(size_t num_bytes)
+{
+    void    *ptr;
+
+#ifdef  MR_CONSERVATIVE_GC
+    ptr = GC_MALLOC_ATOMIC(num_bytes);
+#else
+    ptr = malloc(num_bytes);
+#endif
+
+    if (ptr == NULL && num_bytes != 0) {
+        MR_fatal_error("could not allocate memory");
+    }
+
+    return ptr;
+}
+
+void *
 MR_GC_malloc_uncollectable(size_t num_bytes)
 {
     void    *ptr;
diff --git a/runtime/mercury_memory.h b/runtime/mercury_memory.h
index 862d1fa..50d818c 100644
--- a/runtime/mercury_memory.h
+++ b/runtime/mercury_memory.h
@@ -159,6 +159,11 @@ extern	void 	MR_ensure_big_enough_buffer(char **buffer_ptr,
 **	The memory will not be garbage collected, and so
 **	it should be explicitly deallocated using MR_GC_free().
 **
+** MR_GC_malloc_atomic(bytes):
+**  Allocates the given number of bytes.
+**  Pointers to GC objects may not be stored in this object.  This allows
+**  the GC to optimize it's marking phase.
+**
 ** MR_GC_realloc(ptr, bytes):
 **	Reallocates the memory block pointed to by ptr.
 **
@@ -191,6 +196,7 @@ extern	void 	MR_ensure_big_enough_buffer(char **buffer_ptr,
 
 extern	void	*MR_GC_malloc(size_t num_bytes);
 extern	void	*MR_GC_malloc_uncollectable(size_t num_bytes);
+extern	void	*MR_GC_malloc_atomic(size_t num_bytes);
 extern	void	*MR_GC_realloc(void *ptr, size_t num_bytes);
 
 typedef void 	(*MR_GC_finalizer)(void *ptr, void *data);
-- 
1.9.1




More information about the reviews mailing list