aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTakashi Yano <takashi.yano@nifty.ne.jp>2025-07-19 23:39:12 +0900
committerTakashi Yano <takashi.yano@nifty.ne.jp>2025-07-23 19:51:03 +0900
commitaec6dc77a11b264fcac73b63ada701854fc62a22 (patch)
tree22ad66c05759271427e4d4ed47bee4d82886a0da
parent4ac96b9da4ce6f4e3847cc356d58e1a929665858 (diff)
downloadnewlib-aec6dc77a11b264fcac73b63ada701854fc62a22.zip
newlib-aec6dc77a11b264fcac73b63ada701854fc62a22.tar.gz
newlib-aec6dc77a11b264fcac73b63ada701854fc62a22.tar.bz2
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>
-rw-r--r--winsup/cygwin/local_includes/cygheap.h5
-rw-r--r--winsup/cygwin/mm/cygheap.cc12
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 3388864..1c9b803 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 *