I forgot to mention that you'd have to repeat the find operation once you get the write lock since there is a small window between the unlock and lock where another thread may have created the item.<br><br><br><div class="gmail_quote">
On Thu, Aug 18, 2011 at 6:42 AM, Christopher Rienzo <span dir="ltr"><<a href="mailto:cmrienzo@gmail.com">cmrienzo@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<p>Unlock the read lock and then lock as a write lock.</p>
<p></p><blockquote type="cite"><div><div></div><div class="h5">On Aug 17, 2011 8:20 PM, "Seven Du" <<a href="mailto:dujinfang@gmail.com" target="_blank">dujinfang@gmail.com</a>> wrote:<br><br><div>
<div>
<span>Hi,<br>
</span></div><div><span><br></span></div><div><span><br></span></div><div><span>Just wondering how to upgrade a read lock to a write lock, say I do a find_or_create_item_in_queue()</span></div><div><span><br>
</span></div><div><span><div><span style="white-space:pre-wrap">        </span>switch_thread_rwlock_rdlock(lock);</div><div><br></div><div><span style="white-space:pre-wrap">        </span>find an item from queue, if not found, create one</div>
<div><br></div><div><div><span style="white-space:pre-wrap">        </span>switch_thread_rwlock_upgrade_to_wrlock(lock);</div></div><div><br></div></span></div><div>
<span><span style="white-space:pre-wrap">        </span></span><span>write</span></div><div><span><span style="white-space:pre-wrap">        </span></span></div><div><span style="white-space:pre-wrap">        </span>switch_thread_rwlock_unlock(lock);</div>
<div><br></div><div><span>Thanks<br><font color="#888888">-- <br>Seven Du<br><div>About: <a href="http://about.me/dujinfang" target="_blank">http://about.me/dujinfang</a></div><div>Blog: <a href="http://www.dujinfang.com" target="_blank">http://www.dujinfang.com</a></div>
<div>Proj: <a href="http://www.freeswitch.org.cn" target="_blank">http://www.freeswitch.org.cn</a></div>Sent with <a href="http://www.sparrowmailapp.com" target="_blank">Sparrow</a><br></font></span></div><div></div><div>
<br></div><div>
</div>
</div><br></div></div>_______________________________________________<br>
Join us at ClueCon 2011, Aug 9-11, Chicago<br>
<a href="http://www.cluecon.com" target="_blank">http://www.cluecon.com</a> 877-7-4ACLUE<br>
<br>
FreeSWITCH-dev mailing list<br>
<a href="mailto:FreeSWITCH-dev@lists.freeswitch.org" target="_blank">FreeSWITCH-dev@lists.freeswitch.org</a><br>
<a href="http://lists.freeswitch.org/mailman/listinfo/freeswitch-dev" target="_blank">http://lists.freeswitch.org/mailman/listinfo/freeswitch-dev</a><br>
UNSUBSCRIBE:<a href="http://lists.freeswitch.org/mailman/options/freeswitch-dev" target="_blank">http://lists.freeswitch.org/mailman/options/freeswitch-dev</a><br>
<a href="http://www.freeswitch.org" target="_blank">http://www.freeswitch.org</a><br>
<br></blockquote><p></p>
</blockquote></div><br>