aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKonstantin Belousov <kib@FreeBSD.org>2023-07-13 15:56:11 +0000
committerKonstantin Belousov <kib@FreeBSD.org>2023-07-23 11:44:24 +0000
commitb1be52209c4237140d0755e1d7d3263ffc3543d2 (patch)
tree9288580fe8830cd753461b94d775a96c35180189
parent50a4d8b345705ff2180c150903228f99b08b5674 (diff)
downloadsrc-b1be52209c4237140d0755e1d7d3263ffc3543d2.tar.gz
src-b1be52209c4237140d0755e1d7d3263ffc3543d2.zip
libthr: trigger library initialization on rwlock calls
(cherry picked from commit ad056b5d35d9957b1bd023abeb6461601449b725)
-rw-r--r--lib/libthr/thread/thr_rwlock.c13
1 files changed, 11 insertions, 2 deletions
diff --git a/lib/libthr/thread/thr_rwlock.c b/lib/libthr/thread/thr_rwlock.c
index ab10431b9d41..a61eb35cbd31 100644
--- a/lib/libthr/thread/thr_rwlock.c
+++ b/lib/libthr/thread/thr_rwlock.c
@@ -163,6 +163,7 @@ int
_thr_rwlock_init(pthread_rwlock_t *rwlock, const pthread_rwlockattr_t *attr)
{
+ _thr_check_init();
*rwlock = NULL;
return (rwlock_init(rwlock, attr));
}
@@ -231,6 +232,7 @@ rwlock_rdlock_common(pthread_rwlock_t *rwlock, const struct timespec *abstime)
int
_Tthr_rwlock_rdlock(pthread_rwlock_t *rwlock)
{
+ _thr_check_init();
return (rwlock_rdlock_common(rwlock, NULL));
}
@@ -238,21 +240,24 @@ int
_pthread_rwlock_timedrdlock(pthread_rwlock_t * __restrict rwlock,
const struct timespec * __restrict abstime)
{
+ _thr_check_init();
return (rwlock_rdlock_common(rwlock, abstime));
}
int
_Tthr_rwlock_tryrdlock(pthread_rwlock_t *rwlock)
{
- struct pthread *curthread = _get_curthread();
+ struct pthread *curthread;
pthread_rwlock_t prwlock;
int flags;
int ret;
+ _thr_check_init();
ret = check_and_init_rwlock(rwlock, &prwlock);
if (ret != 0)
return (ret);
+ curthread = _get_curthread();
if (curthread->rdlock_count) {
/*
* To avoid having to track all the rdlocks held by
@@ -280,14 +285,16 @@ _Tthr_rwlock_tryrdlock(pthread_rwlock_t *rwlock)
int
_Tthr_rwlock_trywrlock(pthread_rwlock_t *rwlock)
{
- struct pthread *curthread = _get_curthread();
+ struct pthread *curthread;
pthread_rwlock_t prwlock;
int ret;
+ _thr_check_init();
ret = check_and_init_rwlock(rwlock, &prwlock);
if (ret != 0)
return (ret);
+ curthread = _get_curthread();
ret = _thr_rwlock_trywrlock(&prwlock->lock);
if (ret == 0)
prwlock->owner = TID(curthread);
@@ -343,6 +350,7 @@ rwlock_wrlock_common(pthread_rwlock_t *rwlock, const struct timespec *abstime)
int
_Tthr_rwlock_wrlock(pthread_rwlock_t *rwlock)
{
+ _thr_check_init();
return (rwlock_wrlock_common(rwlock, NULL));
}
@@ -350,6 +358,7 @@ int
_pthread_rwlock_timedwrlock(pthread_rwlock_t * __restrict rwlock,
const struct timespec * __restrict abstime)
{
+ _thr_check_init();
return (rwlock_wrlock_common(rwlock, abstime));
}