<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
<html lang="en">
<head>
<meta content="text/html; charset=US-ASCII" http-equiv="Content-Type">
<title>
GitLab
</title>
<style>img {
max-width: 100%; height: auto;
}
</style>
</head>
<body>
<div class="content">
<p style="color: #777777;">
<a href="https://gitlab.com/asosedkin">Alexander Sosedkin</a>
commented on a
discussion on <a href="https://gitlab.com/gnutls/gnutls/-/merge_requests/1483#note_721296096">lib/priority.c</a>:
</p>
<table>
<tr class="line_holder" id="">
<td class="old_line diff-line-num" data-linenumber="1452" style="width: 35px; color: rgba(0,0,0,0.3); border-right-width: 1px; border-right-color: #f0f0f0; border-right-style: solid; padding: 0 5px;" align="right" bgcolor="#fafafa">
1452
</td>
<td class="new_line diff-line-num" data-linenumber="1443" style="width: 35px; color: rgba(0,0,0,0.3); border-right-width: 1px; border-right-color: #f0f0f0; border-right-style: solid; padding: 0 5px;" align="right" bgcolor="#fafafa">
1443
</td>
<td class="line_content" style="padding-left: 0.5em; padding-right: 0.5em;">
<pre style="margin: 0;"> <span id="LC1443" class="line" lang="c"><span class="cm" style="color: #998; font-style: italic;"> * allow it to be updated without restarting</span></span>
</pre>
</td>
</tr>
<tr class="line_holder" id="">
<td class="old_line diff-line-num" data-linenumber="1453" style="width: 35px; color: rgba(0,0,0,0.3); border-right-width: 1px; border-right-color: #f0f0f0; border-right-style: solid; padding: 0 5px;" align="right" bgcolor="#fafafa">
1453
</td>
<td class="new_line diff-line-num" data-linenumber="1444" style="width: 35px; color: rgba(0,0,0,0.3); border-right-width: 1px; border-right-color: #f0f0f0; border-right-style: solid; padding: 0 5px;" align="right" bgcolor="#fafafa">
1444
</td>
<td class="line_content" style="padding-left: 0.5em; padding-right: 0.5em;">
<pre style="margin: 0;"> <span id="LC1444" class="line" lang="c"><span class="cm" style="color: #998; font-style: italic;"> * all applications</span></span>
</pre>
</td>
</tr>
<tr class="line_holder" id="">
<td class="old_line diff-line-num" data-linenumber="1454" style="width: 35px; color: rgba(0,0,0,0.3); border-right-width: 1px; border-right-color: #f0f0f0; border-right-style: solid; padding: 0 5px;" align="right" bgcolor="#fafafa">
1454
</td>
<td class="new_line diff-line-num" data-linenumber="1445" style="width: 35px; color: rgba(0,0,0,0.3); border-right-width: 1px; border-right-color: #f0f0f0; border-right-style: solid; padding: 0 5px;" align="right" bgcolor="#fafafa">
1445
</td>
<td class="line_content" style="padding-left: 0.5em; padding-right: 0.5em;">
<pre style="margin: 0;"> <span id="LC1445" class="line" lang="c"><span class="cm" style="color: #998; font-style: italic;"> */</span></span>
</pre>
</td>
</tr>
<tr class="line_holder new" id="">
<td class="old_line diff-line-num new" data-linenumber="1455" style="width: 35px; color: rgba(0,0,0,0.3); border-right-width: 1px; border-right-color: #c7f0d2; border-right-style: solid; padding: 0 5px;" align="right" bgcolor="#ddfbe6">
</td>
<td class="new_line diff-line-num new" data-linenumber="1446" style="width: 35px; color: rgba(0,0,0,0.3); border-right-width: 1px; border-right-color: #c7f0d2; border-right-style: solid; padding: 0 5px;" align="right" bgcolor="#ddfbe6">
1446
</td>
<td class="line_content new" style="padding-left: 0.5em; padding-right: 0.5em;" bgcolor="#ecfdf0">
<pre style="margin: 0;">+<span id="LC1446" class="line" lang="c"> <span class="n" style="color: #333;">GNUTLS_STATIC_MUTEX_LOCK</span><span class="p">(</span><span class="n" style="color: #333;">system_wide_config_mutex</span><span class="p">);</span></span>
</pre>
</td>
</tr>
<tr class="line_holder" id="">
<td class="old_line diff-line-num" data-linenumber="1455" style="width: 35px; color: rgba(0,0,0,0.3); border-right-width: 1px; border-right-color: #f0f0f0; border-right-style: solid; padding: 0 5px;" align="right" bgcolor="#fafafa">
1455
</td>
<td class="new_line diff-line-num" data-linenumber="1447" style="width: 35px; color: rgba(0,0,0,0.3); border-right-width: 1px; border-right-color: #f0f0f0; border-right-style: solid; padding: 0 5px;" align="right" bgcolor="#fafafa">
1447
</td>
<td class="line_content" style="padding-left: 0.5em; padding-right: 0.5em;">
<pre style="margin: 0;"> <span id="LC1447" class="line" lang="c"> <span class="n" style="color: #333;">_gnutls_update_system_priorities</span><span class="p">();</span></span>
</pre>
</td>
</tr>
</table>
<div style="">
<p dir="auto">I hope that all the heavy lifting here is localized in <code>_gnutls_update_system_priority</code> and is conditioned on actually reading the file after failing the mtime stat check; and then everyone has to wait no matter what. Provided no actual reload is necessary, it'll be just a stat call we wrlock for, and the rest shouldn't really meaningfully be long, just a bit of syscall-free string crunching, right? So, I see little benefit in scenario 2 over 1: we unconditionally wrlock in both and the scope of wrlocking isn't much different.</p>
<p dir="auto">Now, one could keep advancing in your suggested direction and narrow wrlocking further to also exclude the mtime check:</p>
<pre class="code highlight js-syntax-highlight language-plaintext" lang="plaintext" v-pre="true" style="background-color: #fff; font-family: monospace; font-size: 90%; -premailer-cellpadding: 0; -premailer-cellspacing: 0; -premailer-width: 100%; margin: 0;"><code><span id="LC1" class="line" lang="plaintext">// rdlock</span>
<span id="LC2" class="line" lang="plaintext">inside _gnutls_update_system_priorities {</span>
<span id="LC3" class="line" lang="plaintext"> if (/* mtime_check() */)</span>
<span id="LC4" class="line" lang="plaintext"> return;</span>
<span id="LC5" class="line" lang="plaintext"> // upgrade rdlock to wrlock</span>
<span id="LC6" class="line" lang="plaintext"> // init check</span>
<span id="LC7" class="line" lang="plaintext"> // heavy lifting</span>
<span id="LC8" class="line" lang="plaintext"> // unlock</span>
<span id="LC9" class="line" lang="plaintext">}</span>
<span id="LC10" class="line" lang="plaintext"></span>
<span id="LC11" class="line" lang="plaintext">do {</span>
<span id="LC12" class="line" lang="plaintext"> // rdlock</span>
<span id="LC13" class="line" lang="plaintext"> // access</span>
<span id="LC14" class="line" lang="plaintext"> // unlock</span>
<span id="LC15" class="line" lang="plaintext">}</span></code></pre>
<p dir="auto">that allows for some executions to attempt no wrlocks, but will the gains between 1 and 3 be worth the complexity? I doubt it. If it were on me, I'd probably leave a note saying <code>TODO if somebody complains about the performance: locking could be narrowed to wrlocking for the part past the mcheck</code> and move on for now =)</p>
</div>
</div>
<div class="footer" style="margin-top: 10px;">
<p style="font-size: small; color: #666;">
—
<br>
Reply to this email directly or <a href="https://gitlab.com/gnutls/gnutls/-/merge_requests/1483#note_721296096">view it on GitLab</a>.
<br>
You're receiving this email because of your account on gitlab.com.
If you'd like to receive fewer emails, you can
<a href="https://gitlab.com/-/sent_notifications/05d2645b27df00160296f7e4c0344565/unsubscribe">unsubscribe</a>
from this thread or
adjust your notification settings.
<script type="application/ld+json">{"@context":"http://schema.org","@type":"EmailMessage","action":{"@type":"ViewAction","name":"View Merge request","url":"https://gitlab.com/gnutls/gnutls/-/merge_requests/1483#note_721296096"}}</script>
</p>
</div>
</body>
</html>