From 5d3e79ec6bb7362cb56765025a5ca756da41a293 Mon Sep 17 00:00:00 2001 From: Corinna Vinschen Date: Fri, 1 Mar 2024 22:24:37 +0100 Subject: [PATCH] Cygwin: cygheap: use SRWLOCK for cygheap locking Signed-off-by: Corinna Vinschen --- winsup/cygwin/mm/cygheap.cc | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/winsup/cygwin/mm/cygheap.cc b/winsup/cygwin/mm/cygheap.cc index 3dc0c011f..c763a0967 100644 --- a/winsup/cygwin/mm/cygheap.cc +++ b/winsup/cygwin/mm/cygheap.cc @@ -35,7 +35,7 @@ static mini_cygheap NO_COPY cygheap_dummy = init_cygheap NO_COPY *cygheap = (init_cygheap *) &cygheap_dummy; void NO_COPY *cygheap_max; -static NO_COPY muto cygheap_protect; +static NO_COPY SRWLOCK cygheap_protect = SRWLOCK_INIT; struct cygheap_entry { @@ -278,7 +278,6 @@ static const uint32_t bucket_val[NBUCKETS] = { void cygheap_init () { - cygheap_protect.init ("cygheap_protect"); if (cygheap == &cygheap_dummy) { cygheap = (init_cygheap *) VirtualAlloc ((LPVOID) CYGHEAP_STORAGE_LOW, @@ -364,7 +363,7 @@ _cmalloc (unsigned size) if (b >= NBUCKETS) return NULL; - cygheap_protect.acquire (); + AcquireSRWLockExclusive (&cygheap_protect); if (cygheap->buckets[b]) { rvc = (_cmalloc_entry *) cygheap->buckets[b]; @@ -376,7 +375,7 @@ _cmalloc (unsigned size) rvc = (_cmalloc_entry *) _csbrk (bucket_val[b] + sizeof (_cmalloc_entry)); if (!rvc) { - cygheap_protect.release (); + ReleaseSRWLockExclusive (&cygheap_protect); return NULL; } @@ -384,19 +383,19 @@ _cmalloc (unsigned size) rvc->prev = cygheap->chain; cygheap->chain = rvc; } - cygheap_protect.release (); + ReleaseSRWLockExclusive (&cygheap_protect); return rvc->data; } static void _cfree (void *ptr) { - cygheap_protect.acquire (); + AcquireSRWLockExclusive (&cygheap_protect); _cmalloc_entry *rvc = to_cmalloc (ptr); unsigned b = rvc->b; rvc->ptr = cygheap->buckets[b]; cygheap->buckets[b] = (char *) rvc; - cygheap_protect.release (); + ReleaseSRWLockExclusive (&cygheap_protect); } static void *