svn commit: r318581 - head/lib/libthr/thread
Eric van Gyzen
vangyzen at FreeBSD.org
Sat May 20 17:30:49 UTC 2017
Author: vangyzen
Date: Sat May 20 17:30:48 2017
New Revision: 318581
URL: https://svnweb.freebsd.org/changeset/base/318581
Log:
libthr: change CHECK_AND_INIT_RWLOCK to an inline function
This was prompted by a compiler warning about 'ret' shadowing
a local variable in the callers of the macro.
Reviewed by: kib
MFC after: 3 days
Sponsored by: Dell EMC
Differential Revision: https://reviews.freebsd.org/D10832
Modified:
head/lib/libthr/thread/thr_rwlock.c
Modified: head/lib/libthr/thread/thr_rwlock.c
==============================================================================
--- head/lib/libthr/thread/thr_rwlock.c Sat May 20 17:29:36 2017 (r318580)
+++ head/lib/libthr/thread/thr_rwlock.c Sat May 20 17:30:48 2017 (r318581)
@@ -49,27 +49,42 @@ __weak_reference(_pthread_rwlock_unlock,
__weak_reference(_pthread_rwlock_wrlock, pthread_rwlock_wrlock);
__weak_reference(_pthread_rwlock_timedwrlock, pthread_rwlock_timedwrlock);
-#define CHECK_AND_INIT_RWLOCK \
- if (*rwlock == THR_PSHARED_PTR) { \
- prwlock = __thr_pshared_offpage(rwlock, 0); \
- if (prwlock == NULL) \
- return (EINVAL); \
- } else if (__predict_false((prwlock = (*rwlock)) <= \
- THR_RWLOCK_DESTROYED)) { \
- if (prwlock == THR_RWLOCK_INITIALIZER) { \
- int ret; \
- ret = init_static(_get_curthread(), rwlock); \
- if (ret) \
- return (ret); \
- } else if (prwlock == THR_RWLOCK_DESTROYED) { \
- return (EINVAL); \
- } \
- prwlock = *rwlock; \
- }
-
-/*
- * Prototypes
- */
+static int init_static(struct pthread *thread, pthread_rwlock_t *rwlock);
+static int init_rwlock(pthread_rwlock_t *rwlock, pthread_rwlock_t *rwlock_out);
+
+static int __always_inline
+check_and_init_rwlock(pthread_rwlock_t *rwlock, pthread_rwlock_t *rwlock_out)
+{
+ if (__predict_false(*rwlock == THR_PSHARED_PTR ||
+ *rwlock <= THR_RWLOCK_DESTROYED))
+ return (init_rwlock(rwlock, rwlock_out));
+ *rwlock_out = *rwlock;
+ return (0);
+}
+
+static int __noinline
+init_rwlock(pthread_rwlock_t *rwlock, pthread_rwlock_t *rwlock_out)
+{
+ pthread_rwlock_t prwlock;
+ int ret;
+
+ if (*rwlock == THR_PSHARED_PTR) {
+ prwlock = __thr_pshared_offpage(rwlock, 0);
+ if (prwlock == NULL)
+ return (EINVAL);
+ } else if ((prwlock = *rwlock) <= THR_RWLOCK_DESTROYED) {
+ if (prwlock == THR_RWLOCK_INITIALIZER) {
+ ret = init_static(_get_curthread(), rwlock);
+ if (ret != 0)
+ return (ret);
+ } else if (prwlock == THR_RWLOCK_DESTROYED) {
+ return (EINVAL);
+ }
+ prwlock = *rwlock;
+ }
+ *rwlock_out = prwlock;
+ return (0);
+}
static int
rwlock_init(pthread_rwlock_t *rwlock, const pthread_rwlockattr_t *attr)
@@ -148,7 +163,9 @@ rwlock_rdlock_common(pthread_rwlock_t *r
int flags;
int ret;
- CHECK_AND_INIT_RWLOCK
+ ret = check_and_init_rwlock(rwlock, &prwlock);
+ if (ret != 0)
+ return (ret);
if (curthread->rdlock_count) {
/*
@@ -220,7 +237,9 @@ _pthread_rwlock_tryrdlock (pthread_rwloc
int flags;
int ret;
- CHECK_AND_INIT_RWLOCK
+ ret = check_and_init_rwlock(rwlock, &prwlock);
+ if (ret != 0)
+ return (ret);
if (curthread->rdlock_count) {
/*
@@ -253,7 +272,9 @@ _pthread_rwlock_trywrlock (pthread_rwloc
pthread_rwlock_t prwlock;
int ret;
- CHECK_AND_INIT_RWLOCK
+ ret = check_and_init_rwlock(rwlock, &prwlock);
+ if (ret != 0)
+ return (ret);
ret = _thr_rwlock_trywrlock(&prwlock->lock);
if (ret == 0)
@@ -268,7 +289,9 @@ rwlock_wrlock_common (pthread_rwlock_t *
pthread_rwlock_t prwlock;
int ret;
- CHECK_AND_INIT_RWLOCK
+ ret = check_and_init_rwlock(rwlock, &prwlock);
+ if (ret != 0)
+ return (ret);
/*
* POSIX said the validity of the abstimeout parameter need
More information about the svn-src-all
mailing list