<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 />





 <pre style="white-space: pre-wrap; white-space: -moz-pre-wrap; white-space: -pre-wrap; white-space: -o-pre-wrap; word-wrap: break-word;">Other than the mention of red blobs, this looks good to go and would be great for any new code being written.  Like you said, it needs more documentation.</pre>
 <br />







<p>- opticron</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&#39;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>