First set of licensing changes
[mono.git] / mono / metadata / mempool.c
index f4cf35629dfce0cd9cb5811bd8d0d1ece8b6d3a5..60d36ae2ad1765d76cbf450dbb8feb9b616bf479 100644 (file)
@@ -10,6 +10,7 @@
  * Copyright 2001-2003 Ximian, Inc (http://www.ximian.com)
  * Copyright 2004-2009 Novell, Inc (http://www.novell.com)
  * Copyright 2011 Xamarin Inc. (http://www.xamarin.com)
+ * Licensed under the MIT license. See LICENSE file in the project root for full license information.
  */
 
 #include <config.h>
@@ -107,7 +108,7 @@ mono_mempool_new_size (int initial_size)
                initial_size = MONO_MEMPOOL_MINSIZE;
 #endif
 
-       pool = g_malloc (initial_size);
+       pool = (MonoMemPool *)g_malloc (initial_size);
 
        pool->next = NULL;
        pool->pos = (guint8*)pool + SIZEOF_MEM_POOL; // Start after header
@@ -147,9 +148,6 @@ mono_mempool_destroy (MonoMemPool *pool)
 void
 mono_mempool_invalidate (MonoMemPool *pool)
 {
-#ifdef INDIVIDUAL_ALLOCATIONS
-       g_assert_not_reached ();
-#else
        MonoMemPool *p, *n;
 
        p = pool;
@@ -158,7 +156,6 @@ mono_mempool_invalidate (MonoMemPool *pool)
                memset (p, 42, p->size);
                p = n;
        }
-#endif
 }
 
 /**
@@ -173,9 +170,6 @@ mono_mempool_invalidate (MonoMemPool *pool)
 void
 mono_mempool_stats (MonoMemPool *pool)
 {
-#ifdef INDIVIDUAL_ALLOCATIONS
-       g_assert_not_reached ();
-#else
        MonoMemPool *p;
        int count = 0;
        guint32 still_free = pool->end - pool->pos;
@@ -191,10 +185,8 @@ mono_mempool_stats (MonoMemPool *pool)
                g_print ("Num chunks: %d\n", count);
                g_print ("Free memory: %d\n", still_free);
        }
-#endif
 }
 
-#ifndef INDIVIDUAL_ALLOCATIONS
 #ifdef TRACE_ALLOCATIONS
 #include <execinfo.h>
 #include "metadata/appdomain.h"
@@ -211,11 +203,11 @@ mono_backtrace (int size)
         static gboolean inited;
 
         if (!inited) {
-            mono_mutex_init_recursive (&mempool_tracing_lock);
+            mono_os_mutex_init_recursive (&mempool_tracing_lock);
             inited = TRUE;
         }
 
-        mono_mutex_lock (&mempool_tracing_lock);
+        mono_os_mutex_lock (&mempool_tracing_lock);
         g_print ("Allocating %d bytes\n", size);
         symbols = backtrace (array, BACKTRACE_DEPTH);
         names = backtrace_symbols (array, symbols);
@@ -223,10 +215,9 @@ mono_backtrace (int size)
                 g_print ("\t%s\n", names [i]);
         }
         free (names);
-        mono_mutex_unlock (&mempool_tracing_lock);
+        mono_os_mutex_unlock (&mempool_tracing_lock);
 }
 
-#endif
 #endif
 
 /**
@@ -287,7 +278,7 @@ mono_mempool_alloc (MonoMemPool *pool, guint size)
                // (In individual allocation mode, the constant will be 0 and this path will always be taken)
                if (size >= MONO_MEMPOOL_PREFER_INDIVIDUAL_ALLOCATION_SIZE) {
                        guint new_size = SIZEOF_MEM_POOL + size;
-                       MonoMemPool *np = g_malloc (new_size);
+                       MonoMemPool *np = (MonoMemPool *)g_malloc (new_size);
 
                        np->next = pool->next;
                        np->size = new_size;
@@ -299,7 +290,7 @@ mono_mempool_alloc (MonoMemPool *pool, guint size)
                } else {
                        // Notice: any unused memory at the end of the old head becomes simply abandoned in this case until the mempool is freed (see Bugzilla #35136)
                        guint new_size = get_next_size (pool, size);
-                       MonoMemPool *np = g_malloc (new_size);
+                       MonoMemPool *np = (MonoMemPool *)g_malloc (new_size);
 
                        np->next = pool->next;
                        np->size = new_size;
@@ -383,7 +374,7 @@ mono_mempool_strdup (MonoMemPool *pool,
                return NULL;
 
        l = strlen (s);
-       res = mono_mempool_alloc (pool, l + 1);
+       res = (char *)mono_mempool_alloc (pool, l + 1);
        memcpy (res, s, l + 1);
 
        return res;