MSYS2-packages/msys2-runtime/0039-Cygwin-cygheap-Add-lock-unlock-method.patch

93 lines
2.9 KiB
Diff

From 0cc983578c7a112265fca83b6c5ea5d0724b29fa Mon Sep 17 00:00:00 2001
From: Takashi Yano <takashi.yano@nifty.ne.jp>
Date: Sat, 19 Jul 2025 23:39:12 +0900
Subject: [PATCH 39/N] Cygwin: cygheap: Add lock()/unlock() method
...so that cygheap can be locked/unlocked from outside of mm/cygheap.cc.
Reviewed-by: Corinna Vinschen <corinna@vinschen.de>
Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp>
(cherry picked from commit aec6dc77a11b264fcac73b63ada701854fc62a22)
---
winsup/cygwin/local_includes/cygheap.h | 5 +++++
winsup/cygwin/mm/cygheap.cc | 12 ++++++------
2 files changed, 11 insertions(+), 6 deletions(-)
diff --git a/winsup/cygwin/local_includes/cygheap.h b/winsup/cygwin/local_includes/cygheap.h
index fed87ec..d9e936c 100644
--- a/winsup/cygwin/local_includes/cygheap.h
+++ b/winsup/cygwin/local_includes/cygheap.h
@@ -498,6 +498,9 @@ struct threadlist_t
struct init_cygheap: public mini_cygheap
{
+private:
+ static SRWLOCK cygheap_protect;
+public:
_cmalloc_entry *chain;
char *buckets[NBUCKETS];
UNICODE_STRING installation_root;
@@ -541,6 +544,8 @@ struct init_cygheap: public mini_cygheap
threadlist_t *find_tls (int, bool&);
sigset_t compute_sigblkmask ();
void unlock_tls (threadlist_t *t) { if (t) ReleaseMutex (t->mutex); }
+ inline void lock () { AcquireSRWLockExclusive (&cygheap_protect); }
+ inline void unlock () { ReleaseSRWLockExclusive (&cygheap_protect); }
};
diff --git a/winsup/cygwin/mm/cygheap.cc b/winsup/cygwin/mm/cygheap.cc
index 5409a6b..4a60995 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 SRWLOCK cygheap_protect = SRWLOCK_INIT;
+SRWLOCK NO_COPY init_cygheap::cygheap_protect = SRWLOCK_INIT;
struct cygheap_entry
{
@@ -377,7 +377,7 @@ _cmalloc (unsigned size)
if (b >= NBUCKETS)
return NULL;
- AcquireSRWLockExclusive (&cygheap_protect);
+ cygheap->lock ();
if (cygheap->buckets[b])
{
rvc = (_cmalloc_entry *) cygheap->buckets[b];
@@ -389,7 +389,7 @@ _cmalloc (unsigned size)
rvc = (_cmalloc_entry *) _csbrk (bucket_val[b] + sizeof (_cmalloc_entry));
if (!rvc)
{
- ReleaseSRWLockExclusive (&cygheap_protect);
+ cygheap->unlock ();
return NULL;
}
@@ -397,19 +397,19 @@ _cmalloc (unsigned size)
rvc->prev = cygheap->chain;
cygheap->chain = rvc;
}
- ReleaseSRWLockExclusive (&cygheap_protect);
+ cygheap->unlock ();
return rvc->data;
}
static void
_cfree (void *ptr)
{
- AcquireSRWLockExclusive (&cygheap_protect);
+ cygheap->lock ();
_cmalloc_entry *rvc = to_cmalloc (ptr);
unsigned b = rvc->b;
rvc->ptr = cygheap->buckets[b];
cygheap->buckets[b] = (char *) rvc;
- ReleaseSRWLockExclusive (&cygheap_protect);
+ cygheap->unlock ();
}
static void *