]> git.cameronkatri.com Git - bsdgames-darwin.git/blobdiff - monop/malloc.c
Convert from libc/threadlib-style mutex protection to pthread style.
[bsdgames-darwin.git] / monop / malloc.c
index 7596d81524703ee7c9a2abafcdeaf683c52600a7..5e171af85e6ed54e65db183d9ae2f064e108518e 100644 (file)
@@ -1,4 +1,4 @@
-/*     $NetBSD: malloc.c,v 1.2 2003/08/07 09:37:28 agc Exp $   */
+/*     $NetBSD: malloc.c,v 1.4 2004/12/14 00:21:01 nathanw Exp $       */
 
 /*
  * Copyright (c) 1983, 1993
@@ -34,7 +34,7 @@
 #if 0
 static char sccsid[] = "@(#)malloc.c   8.1 (Berkeley) 6/4/93";
 #else
-__RCSID("$NetBSD: malloc.c,v 1.2 2003/08/07 09:37:28 agc Exp $");
+__RCSID("$NetBSD: malloc.c,v 1.4 2004/12/14 00:21:01 nathanw Exp $");
 #endif
 #endif /* LIBC_SCCS and not lint */
 
@@ -59,7 +59,7 @@ __RCSID("$NetBSD: malloc.c,v 1.2 2003/08/07 09:37:28 agc Exp $");
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
-#include <threadlib.h>
+#include <pthread.h>
 
 
 /*
@@ -118,18 +118,18 @@ static    int pagebucket;                 /* page size bucket */
 static u_int nmalloc[NBUCKETS];
 #endif
 
-static mutex_t malloc_mutex = MUTEX_INITIALIZER;
+static pthread_mutex_t malloc_mutex = PTHREAD_MUTEX_INITIALIZER;
 
-static void morecore __P((int));
-static int findbucket __P((union overhead *, int));
+static void morecore(int);
+static int findbucket(union overhead *, int);
 #ifdef MSTATS
-void mstats __P((const char *));
+void mstats(const char *);
 #endif
 
 #if defined(DEBUG) || defined(RCHECK)
 #define        ASSERT(p)   if (!(p)) botch(__STRING(p))
 
-static void botch __P((const char *));
+static void botch(const char *);
 
 /*
  * NOTE: since this may be called while malloc_mutex is locked, stdio must not
@@ -176,7 +176,7 @@ malloc(nbytes)
        long n;
        unsigned amt;
 
-       mutex_lock(&malloc_mutex);
+       pthread_mutex_lock(&malloc_mutex);
 
        /*
         * First time malloc is called, setup page size and
@@ -191,7 +191,7 @@ malloc(nbytes)
                        n += pagesz;
                if (n) {
                        if (sbrk((int)n) == (void *)-1) {
-                               mutex_unlock(&malloc_mutex);
+                               pthread_mutex_unlock(&malloc_mutex);
                                return (NULL);
                        }
                }
@@ -234,7 +234,7 @@ malloc(nbytes)
        if ((op = nextf[bucket]) == NULL) {
                morecore(bucket);
                if ((op = nextf[bucket]) == NULL) {
-                       mutex_unlock(&malloc_mutex);
+                       pthread_mutex_unlock(&malloc_mutex);
                        return (NULL);
                }
        }
@@ -245,7 +245,7 @@ malloc(nbytes)
 #ifdef MSTATS
        nmalloc[bucket]++;
 #endif
-       mutex_unlock(&malloc_mutex);
+       pthread_mutex_unlock(&malloc_mutex);
 #ifdef RCHECK
        /*
         * Record allocated size of block and
@@ -326,13 +326,13 @@ free(cp)
 #endif
        size = op->ov_index;
        ASSERT(size < NBUCKETS);
-       mutex_lock(&malloc_mutex);
+       pthread_mutex_lock(&malloc_mutex);
        op->ov_next = nextf[(unsigned int)size];/* also clobbers ov_magic */
        nextf[(unsigned int)size] = op;
 #ifdef MSTATS
        nmalloc[(size_t)size]--;
 #endif
-       mutex_unlock(&malloc_mutex);
+       pthread_mutex_unlock(&malloc_mutex);
 }
 
 /*
@@ -366,7 +366,7 @@ realloc(cp, nbytes)
                return (NULL);
        }
        op = (union overhead *)(void *)((caddr_t)cp - sizeof (union overhead));
-       mutex_lock(&malloc_mutex);
+       pthread_mutex_lock(&malloc_mutex);
        if (op->ov_magic == MAGIC) {
                was_alloced++;
                i = op->ov_index;
@@ -408,7 +408,7 @@ realloc(cp, nbytes)
                        op->ov_size = (nbytes + RSLOP - 1) & ~(RSLOP - 1);
                        *(u_short *)((caddr_t)(op + 1) + op->ov_size) = RMAGIC;
 #endif
-                       mutex_unlock(&malloc_mutex);
+                       pthread_mutex_unlock(&malloc_mutex);
                        return (cp);
                        
                }
@@ -417,7 +417,7 @@ realloc(cp, nbytes)
                        free(cp);
 #endif
        }
-       mutex_unlock(&malloc_mutex);
+       pthread_mutex_unlock(&malloc_mutex);
        if ((res = malloc(nbytes)) == NULL) {
 #ifdef _REENT
                free(cp);