<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/2060/">https://reviewboard.asterisk.org/r/2060/</a>
</td>
</tr>
</table>
<br />
<div>
<table width="100%" border="0" bgcolor="white" style="border: 1px solid #C0C0C0; border-collapse: collapse; margin: 2px padding: 2px;">
<thead>
<tr>
<th colspan="4" bgcolor="#F0F0F0" style="border-bottom: 1px solid #C0C0C0; font-size: 9pt; padding: 4px 8px; text-align: left;">
<a href="https://reviewboard.asterisk.org/r/2060/diff/1/?file=30572#file30572line560" style="color: black; font-weight: bold; text-decoration: underline;">/trunk/include/asterisk/lock.h</a>
<span style="font-weight: normal;">
(Diff revision 1)
</span>
</th>
</tr>
</thead>
<tbody style="background-color: #e4d9cb; padding: 4px 8px; text-align: center;">
<tr>
<td colspan="4"><pre style="font-size: 8pt; line-height: 140%; margin: 0; ">static void __attribute__((destructor)) fini_##rwlock(void) \</pre></td>
</tr>
</tbody>
<tbody>
<tr>
<th bgcolor="#b1ebb0" style="border-right: 1px solid #C0C0C0;" align="right"><font size="2"></font></th>
<td bgcolor="#c5ffc4" width="50%"><pre style="font-size: 8pt; line-height: 140%; margin: 0; "></pre></td>
<th bgcolor="#b1ebb0" style="border-left: 1px solid #C0C0C0; border-right: 1px solid #C0C0C0;" align="right"><font size="2">560</font></th>
<td bgcolor="#c5ffc4" width="50%"><pre style="font-size: 8pt; line-height: 140%; margin: 0; "><span class="cp">#define SCOPED_AO2LOCK(varname, obj) SCOPED_LOCK(varname, (obj), ao2_lock, ao2_unlock)</span></pre></td>
</tr>
</tbody>
</table>
<pre style="margin-left: 2em; white-space: pre-wrap; white-space: -moz-pre-wrap; white-space: -pre-wrap; white-space: -o-pre-wrap; word-wrap: break-word;">ao2 also supports rw locks now!
I'll leave you to find the red blobs you have hanging around. :)</pre>
</div>
<br />
<p>- rmudgett</p>
<br />
<p>On July 23rd, 2012, 4:52 p.m., Mark Michelson wrote:</p>
<table bgcolor="#fefadf" width="100%" cellspacing="0" cellpadding="8" style="background-image: url('https://reviewboard.asterisk.org/media/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.</div>
<div>By Mark Michelson.</div>
<p style="color: grey;"><i>Updated July 23, 2012, 4:52 p.m.</i></p>
<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;">This is inspired by the RAII_VAR addition in Asterisk 11.
The idea is that using the cleanup attribute means that we can automatically unlock locks when the go out of scope. I have created a SCOPED_LOCK macro for general purpose RAII locking and unlocking. There are also specializations for common locking operations (SCOPED_MUTEX, SCOPED_RDLOCK, SCOPED_WRLOCK, SCOPED_AO2LOCK).
I have created two unit tests. The first simply demonstrates that the SCOPED_LOCK macro actually works as expected (i.e. locks when declared, unlocks when the lock goes out of scope). The second tests that cleanup attributes run in an expected order. This proves that SCOPED_LOCKs and ao2_objects can work in harmony if applied carefully.
As a final measure, I have changed the mutexes in config.c to use SCOPED_MUTEXes as a proof of concept. You can see in a few spots that it is possible to remove some calls to ast_mutex_unlock() since the unlock occurs automatically when the lock goes out of scope.
The actual SCOPED_LOCK macro and its friends are hideously underdocumented right now mainly because I have no idea if this is the sort of change that will be welcomed with open arms or not. Let me know if this idea is good and I'll provide some doxygen for the SCOPED_LOCK macro.</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;">The unit tests, yo!</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/lock.h <span style="color: grey">(370381)</span></li>
<li>/trunk/main/config.c <span style="color: grey">(370381)</span></li>
<li>/trunk/tests/test_scoped_lock.c <span style="color: grey">(PRE-CREATION)</span></li>
</ul>
<p><a href="https://reviewboard.asterisk.org/r/2060/diff/" style="margin-left: 3em;">View Diff</a></p>
</td>
</tr>
</table>
</div>
</body>
</html>