<html>
<body>
<div style="font-family: Verdana, Arial, Helvetica, Sans-Serif;">
<table bgcolor="#f9f3c9" width="100%" cellpadding="8" style="border: 1px #c9c399 solid;">
<tr>
<td>
This is an automatically generated e-mail. To reply, visit:
<a href="https://reviewboard.asterisk.org/r/2716/">https://reviewboard.asterisk.org/r/2716/</a>
</td>
</tr>
</table>
<br />
<table bgcolor="#fefadf" width="100%" cellspacing="0" cellpadding="8" style="background-image: url('https://reviewboard.asterisk.org/static/rb/images/review_request_box_top_bg.png'); background-position: left top; background-repeat: repeat-x; border: 1px black solid;">
<tr>
<td>
<div>Review request for Asterisk Developers, kmoore and Matt Jordan.</div>
<div>By David Lee.</div>
<div style="margin-top: 1.5em;">
<b style="color: #575012; font-size: 10pt;">Repository: </b>
Asterisk
</div>
<h1 style="color: #575012; font-size: 10pt; margin-top: 1.5em;">Description </h1>
<table width="100%" bgcolor="#ffffff" cellspacing="0" cellpadding="10" style="border: 1px solid #b8b5a0">
<tr>
<td>
<pre style="margin: 0; padding: 0; white-space: pre-wrap; white-space: -moz-pre-wrap; white-space: -pre-wrap; white-space: -o-pre-wrap; word-wrap: break-word;">In tracking down some unit tests failures, I ended up reading the fine
print[1] regarding Jansson's thread safety.
In short:
1. Ref-counting is non-atomic.
2. json_dumps() and friends are not thread safe.
This patch adds locking where necessary to our ast_json_* wrapper API,
with documentation in json.h describing the thread safety limitations of
the API.
* Jansson (as of 2.4) provides fairly weak thread safety guarantees. The
* Asterisk wrapper improves upon that slightly. The remaining refcounting
* problems are issues when slicing/sharing/mixing instances between JSON
* objects and arrays, which we avoid.
*
* The \c ast_json_dump_* functions are thread safe for multiple concurrent
* dumps of the same object, so long as the concurrent dumps start from the same
* \c root object. But if an object is shared by other JSON objects/arrays, then
* concurrent dumps of the outer objects/arrays are not thread safe. This can be
* avoided by using ast_json_deep_copy() when sharing JSON instances between
* objects.
*
* The ast_json_ref() and ast_json_unref() functions are thread safe. Since the
* Asterisk wrapper exclusively uses the reference stealing API, Jansson won't
* be performing many refcount modifications behind our backs. There are a few
* exceptions.
*
* The first is the transitive json_decref() that occurs when \ref
* AST_JSON_OBJECT and \ref AST_JSON_ARRAY instances are deleted. This can be
* avoided by using ast_json_deep_copy() when sharing JSON instances between
* objects.
*
* The second is when using the reference borrowing specifier in
* ast_json_pack() (capital \c O). This can be avoided by using the reference
* stealing specifier (lowercase \c o) and wrapping the JSON object parameter
* with ast_json_ref() for an explicit ref-bump.
[1]: http://www.digip.org/jansson/doc/2.4/portability.html#thread-safety</pre>
</td>
</tr>
</table>
<h1 style="color: #575012; font-size: 10pt; margin-top: 1.5em;">Testing </h1>
<table width="100%" bgcolor="#ffffff" cellspacing="0" cellpadding="10" style="border: 1px solid #b8b5a0">
<tr>
<td>
<pre style="margin: 0; padding: 0; white-space: pre-wrap; white-space: -moz-pre-wrap; white-space: -pre-wrap; white-space: -o-pre-wrap; word-wrap: break-word;">Unit tests pass.</pre>
</td>
</tr>
</table>
<h1 style="color: #575012; font-size: 10pt; margin-top: 1.5em;">Diffs</b> </h1>
<ul style="margin-left: 3em; padding-left: 0;">
<li>/trunk/include/asterisk/json.h <span style="color: grey">(395792)</span></li>
<li>/trunk/main/json.c <span style="color: grey">(395792)</span></li>
<li>/trunk/tests/test_json.c <span style="color: grey">(395792)</span></li>
</ul>
<p><a href="https://reviewboard.asterisk.org/r/2716/diff/" style="margin-left: 3em;">View Diff</a></p>
</td>
</tr>
</table>
</div>
</body>
</html>