Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Open sidebar
Håvard Eidnes
BIND
Commits
13e36adb
Commit
13e36adb
authored
May 07, 2020
by
Witold Krecicki
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Proper implementation of adaptive rwlocks
parent
3535c561
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
10 additions
and
4 deletions
+10
-4
lib/isc/rwlock.c
lib/isc/rwlock.c
+10
-4
No files found.
lib/isc/rwlock.c
View file @
13e36adb
...
...
@@ -397,8 +397,10 @@ isc__rwlock_lock(isc_rwlock_t *rwl, isc_rwlocktype_t type) {
isc_result_t
isc_rwlock_lock
(
isc_rwlock_t
*
rwl
,
isc_rwlocktype_t
type
)
{
int32_t
cnt
=
0
;
int32_t
spins
=
atomic_load_acquire
(
&
rwl
->
spins
)
*
2
+
10
;
int32_t
max_cnt
=
ISC_MAX
(
spins
,
RWLOCK_MAX_ADAPTIVE_COUNT
);
int32_t
cachedspins
=
atomic_load_acquire
(
&
rwl
->
spins
);
int32_t
spins
=
cachedspins
*
2
+
10
;
int32_t
max_cnt
=
ISC_MIN
(
spins
,
RWLOCK_MAX_ADAPTIVE_COUNT
);
isc_result_t
result
=
ISC_R_SUCCESS
;
do
{
...
...
@@ -408,8 +410,12 @@ isc_rwlock_lock(isc_rwlock_t *rwl, isc_rwlocktype_t type) {
}
isc_rwlock_pause
();
}
while
(
isc_rwlock_trylock
(
rwl
,
type
)
!=
ISC_R_SUCCESS
);
atomic_fetch_add_release
(
&
rwl
->
spins
,
(
cnt
-
spins
)
/
8
);
/*
* C99 integer division rounds towards 0, but we want a real 'floor'
* here - otherwise we will never drop to anything below 7.
*/
int32_t
update
=
((
cnt
-
cachedspins
+
9
)
/
8
)
-
1
;
atomic_fetch_add_release
(
&
rwl
->
spins
,
update
);
return
(
result
);
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment