Date: Mon, 18 Jan 2021 05:40:33 GMT From: Konstantin Belousov <kib@FreeBSD.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org Subject: git: 20432a4fa157 - stable/12 - libthr malloc: support recursion on thr_malloc_umtx. Message-ID: <202101180540.10I5eXIn058214@gitrepo.freebsd.org>
next in thread | raw e-mail | index | archive | help
The branch stable/12 has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=20432a4fa157be15465e3aefc7977b494c812584 commit 20432a4fa157be15465e3aefc7977b494c812584 Author: Konstantin Belousov <kib@FreeBSD.org> AuthorDate: 2021-01-12 09:02:37 +0000 Commit: Konstantin Belousov <kib@FreeBSD.org> CommitDate: 2021-01-18 05:11:07 +0000 libthr malloc: support recursion on thr_malloc_umtx. PR: 252579 (cherry picked from commit 85d028223bc2768651f4d44881644ceb5dc2a664) --- lib/libthr/thread/thr_malloc.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/lib/libthr/thread/thr_malloc.c b/lib/libthr/thread/thr_malloc.c index 2f1c81142942..80a81f9c6c27 100644 --- a/lib/libthr/thread/thr_malloc.c +++ b/lib/libthr/thread/thr_malloc.c @@ -41,6 +41,7 @@ int npagesizes; size_t *pagesizes; static size_t pagesizes_d[2]; static struct umutex thr_malloc_umtx; +static u_int thr_malloc_umtx_level; void __thr_malloc_init(void) @@ -60,11 +61,16 @@ __thr_malloc_init(void) static void thr_malloc_lock(struct pthread *curthread) { + uint32_t curtid; if (curthread == NULL) return; curthread->locklevel++; - _thr_umutex_lock(&thr_malloc_umtx, TID(curthread)); + curtid = TID(curthread); + if ((uint32_t)thr_malloc_umtx.m_owner == curtid) + thr_malloc_umtx_level++; + else + _thr_umutex_lock(&thr_malloc_umtx, curtid); } static void @@ -73,7 +79,10 @@ thr_malloc_unlock(struct pthread *curthread) if (curthread == NULL) return; - _thr_umutex_unlock(&thr_malloc_umtx, TID(curthread)); + if (thr_malloc_umtx_level > 0) + thr_malloc_umtx_level--; + else + _thr_umutex_unlock(&thr_malloc_umtx, TID(curthread)); curthread->locklevel--; _thr_ast(curthread); }
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202101180540.10I5eXIn058214>