https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=d62ac25ff4eebf117bad1982464cff4d439947b6
commit d62ac25ff4eebf117bad1982464cff4d439947b6 Author: Takashi Yano <takashi.y...@nifty.ne.jp> Date: Sat Jul 19 23:39:12 2025 +0900 Cygwin: cygheap: Add lock()/unlock() method ...so that cygheap can be locked/unlocked from outside of mm/cygheap.cc. Reviewed-by: Corinna Vinschen <cori...@vinschen.de> Signed-off-by: Takashi Yano <takashi.y...@nifty.ne.jp> (cherry picked from commit aec6dc77a11b264fcac73b63ada701854fc62a22) Diff: --- 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 fed87ec2b..d9e936c1e 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 338886468..1c9b8037b 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 { @@ -367,7 +367,7 @@ _cmalloc (unsigned size) if (b >= NBUCKETS) return NULL; - AcquireSRWLockExclusive (&cygheap_protect); + cygheap->lock (); if (cygheap->buckets[b]) { rvc = (_cmalloc_entry *) cygheap->buckets[b]; @@ -379,7 +379,7 @@ _cmalloc (unsigned size) rvc = (_cmalloc_entry *) _csbrk (bucket_val[b] + sizeof (_cmalloc_entry)); if (!rvc) { - ReleaseSRWLockExclusive (&cygheap_protect); + cygheap->unlock (); return NULL; } @@ -387,19 +387,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 *