Welcome to mirror list, hosted at ThFree Co, Russian Federation.

cygwin.com/git/newlib-cygwin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristopher Faylor <me@cgf.cx>2000-10-02 06:26:04 +0400
committerChristopher Faylor <me@cgf.cx>2000-10-02 06:26:04 +0400
commit9fc09d00f7579eab987fabffbe14fdb210a45637 (patch)
tree476981be354ffea18888b8df0fd7af0c848f90ee /winsup/cygwin/cygheap.cc
parent0ce83ef6b8e1e7b113c1081d5ca203f5cac0e7b2 (diff)
* cygheap.cc (cygheap_init): Born again function.
(_cmalloc): Reorganize to accomodate muto locking. (_cfree): Use muto lock to avoid multi-thread problems. * cygheap.h (incygheap): Just use cygheap_max to find upper cygwin heap bounds. * dcrt0.cc (dll_crt0_1): Reinstitute cygheap_init call. * path.cc (getcwd): Just return cwdstuff::get result, allowing correct handling of negative length. (cwdstuff::get): Malloc a buffer if one is not available.
Diffstat (limited to 'winsup/cygwin/cygheap.cc')
-rw-r--r--winsup/cygwin/cygheap.cc39
1 files changed, 32 insertions, 7 deletions
diff --git a/winsup/cygwin/cygheap.cc b/winsup/cygwin/cygheap.cc
index 5509ebae0..e71c94d0e 100644
--- a/winsup/cygwin/cygheap.cc
+++ b/winsup/cygwin/cygheap.cc
@@ -12,13 +12,23 @@
#include <errno.h>
#include <fhandler.h>
#include <assert.h>
+#include <stdlib.h>
#include "cygheap.h"
#include "heap.h"
#include "cygerrno.h"
+#include "sync.h"
void *cygheap = NULL;
void *cygheap_max = NULL;
+static NO_COPY muto *cygheap_protect = NULL;
+
+extern "C" void __stdcall
+cygheap_init ()
+{
+ cygheap_protect = new_muto (FALSE, "cygheap_protect");
+}
+
inline static void
init_cheap ()
{
@@ -116,30 +126,35 @@ _cmalloc (int size)
init_buckets ();
b = size2bucket (size);
+ cygheap_protect->acquire ();
if (buckets[b])
{
rvc = (_cmalloc_entry *) buckets[b];
buckets[b] = rvc->ptr;
rvc->b = b;
- return rvc->data;
}
+ else
+ {
+ size = bucket2size[b] + sizeof (_cmalloc_entry);
+ rvc = (_cmalloc_entry *) _csbrk (size);
- size = bucket2size[b] + sizeof (_cmalloc_entry);
- rvc = (_cmalloc_entry *) _csbrk (size);
-
- rvc->b = b;
- rvc->prev = *cygheap_chain;
- *cygheap_chain = rvc;
+ rvc->b = b;
+ rvc->prev = *cygheap_chain;
+ *cygheap_chain = rvc;
+ }
+ cygheap_protect->release ();
return rvc->data;
}
static void __stdcall
_cfree (void *ptr)
{
+ cygheap_protect->acquire ();
_cmalloc_entry *rvc = to_cmalloc (ptr);
DWORD b = rvc->b;
rvc->ptr = buckets[b];
buckets[b] = (char *) rvc;
+ cygheap_protect->release ();
}
static void *__stdcall
@@ -226,6 +241,7 @@ creturn (cygheap_types x, cygheap_entry * c, int len)
c->type = x;
if (cygheap_max < ((char *) c + len))
cygheap_max = (char *) c + len;
+ MALLOC_CHECK;
return (void *) c->data;
}
@@ -233,6 +249,7 @@ extern "C" void *__stdcall
cmalloc (cygheap_types x, DWORD n)
{
cygheap_entry *c;
+ MALLOC_CHECK;
c = (cygheap_entry *) _cmalloc (sizeof_cygheap (n));
if (!c)
system_printf ("cmalloc returned NULL");
@@ -242,6 +259,7 @@ cmalloc (cygheap_types x, DWORD n)
extern "C" void *__stdcall
crealloc (void *s, DWORD n)
{
+ MALLOC_CHECK;
if (s == NULL)
return cmalloc (HEAP_STR, n); // kludge
@@ -257,14 +275,17 @@ crealloc (void *s, DWORD n)
extern "C" void __stdcall
cfree (void *s)
{
+ MALLOC_CHECK;
assert (!inheap (s));
(void) _cfree (tocygheap (s));
+ MALLOC_CHECK;
}
extern "C" void *__stdcall
ccalloc (cygheap_types x, DWORD n, DWORD size)
{
cygheap_entry *c;
+ MALLOC_CHECK;
c = (cygheap_entry *) _cmalloc (sizeof_cygheap (n * size));
if (c)
memset (c->data, 0, size);
@@ -276,19 +297,23 @@ ccalloc (cygheap_types x, DWORD n, DWORD size)
extern "C" char *__stdcall
cstrdup (const char *s)
{
+ MALLOC_CHECK;
char *p = (char *) cmalloc (HEAP_STR, strlen (s) + 1);
if (!p)
return NULL;
strcpy (p, s);
+ MALLOC_CHECK;
return p;
}
extern "C" char *__stdcall
cstrdup1 (const char *s)
{
+ MALLOC_CHECK;
char *p = (char *) cmalloc (HEAP_1_STR, strlen (s) + 1);
if (!p)
return NULL;
strcpy (p, s);
+ MALLOC_CHECK;
return p;
}