struct.QrwLock.html 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <meta name="generator" content="rustdoc">
  7. <meta name="description" content="API documentation for the Rust `QrwLock` struct in crate `qutex`.">
  8. <meta name="keywords" content="rust, rustlang, rust-lang, QrwLock">
  9. <title>qutex::QrwLock - Rust</title>
  10. <link rel="stylesheet" type="text/css" href="../normalize.css">
  11. <link rel="stylesheet" type="text/css" href="../rustdoc.css" id="mainThemeStyle">
  12. <link rel="stylesheet" type="text/css" href="../dark.css">
  13. <link rel="stylesheet" type="text/css" href="../main.css" id="themeStyle">
  14. <script src="../storage.js"></script>
  15. </head>
  16. <body class="rustdoc struct">
  17. <!--[if lte IE 8]>
  18. <div class="warning">
  19. This old browser is unsupported and will most likely display funky
  20. things.
  21. </div>
  22. <![endif]-->
  23. <nav class="sidebar">
  24. <div class="sidebar-menu">&#9776;</div>
  25. <p class='location'>Struct QrwLock</p><div class="sidebar-elems"><div class="block items"><a class="sidebar-title" href="#methods">Methods</a><div class="sidebar-links"><a href="#method.new">new</a><a href="#method.read">read</a><a href="#method.write">write</a><a href="#method.enqueue_lock_request">enqueue_lock_request</a><a href="#method.get_mut">get_mut</a><a href="#method.as_ptr">as_ptr</a><a href="#method.as_mut_ptr">as_mut_ptr</a><a href="#method.process_queues">process_queues</a><a href="#method.upgrade_read_lock">upgrade_read_lock</a><a href="#method.downgrade_write_lock">downgrade_write_lock</a><a href="#method.release_read_lock">release_read_lock</a><a href="#method.release_write_lock">release_write_lock</a></div><a class="sidebar-title" href="#implementations">Trait Implementations</a><div class="sidebar-links"><a href="#impl-Debug">Debug</a><a href="#impl-From%3CT%3E">From&lt;T&gt;</a><a href="#impl-Clone">Clone</a></div></div><p class='location'><a href='index.html'>qutex</a></p><script>window.sidebarCurrent = {name: 'QrwLock', ty: 'struct', relpath: ''};</script><script defer src="sidebar-items.js"></script></div>
  26. </nav>
  27. <div class="theme-picker">
  28. <button id="theme-picker" aria-label="Pick another theme!">
  29. <img src="../brush.svg" width="18" alt="Pick another theme!">
  30. </button>
  31. <div id="theme-choices"></div>
  32. </div>
  33. <script src="../theme.js"></script>
  34. <nav class="sub">
  35. <form class="search-form js-only">
  36. <div class="search-container">
  37. <input class="search-input" name="search"
  38. autocomplete="off"
  39. placeholder="Click or press ‘S’ to search, ‘?’ for more options…"
  40. type="search">
  41. </div>
  42. </form>
  43. </nav>
  44. <section id='main' class="content">
  45. <h1 class='fqn'><span class='in-band'>Struct <a href='index.html'>qutex</a>::<wbr><a class="struct" href=''>QrwLock</a></span><span class='out-of-band'><span id='render-detail'>
  46. <a id="toggle-all-docs" href="javascript:void(0)" title="collapse all docs">
  47. [<span class='inner'>&#x2212;</span>]
  48. </a>
  49. </span><a class='srclink' href='../src/qutex/qrw_lock.rs.html#461-463' title='goto source code'>[src]</a></span></h1>
  50. <pre class='rust struct'>pub struct QrwLock&lt;T&gt; { /* fields omitted */ }</pre><div class='docblock'><p>A queue-backed read/write data lock.</p>
  51. <p>As with any queue-backed system, deadlocks must be carefully avoided when
  52. interoperating with other queues.</p>
  53. </div>
  54. <h2 id='methods' class='small-section-header'>
  55. Methods<a href='#methods' class='anchor'></a>
  56. </h2>
  57. <h3 id='impl' class='impl'><span class='in-band'><code>impl&lt;T&gt; <a class="struct" href="../qutex/struct.QrwLock.html" title="struct qutex::QrwLock">QrwLock</a>&lt;T&gt;</code><a href='#impl' class='anchor'></a></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../src/qutex/qrw_lock.rs.html#465-872' title='goto source code'>[src]</a></span></h3>
  58. <div class='impl-items'><h4 id='method.new' class="method"><span id='new.v' class='invisible'><code>pub fn <a href='#method.new' class='fnname'>new</a>(val: T) -&gt; <a class="struct" href="../qutex/struct.QrwLock.html" title="struct qutex::QrwLock">QrwLock</a>&lt;T&gt;</code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../src/qutex/qrw_lock.rs.html#468-472' title='goto source code'>[src]</a></span></h4>
  59. <div class='docblock'><p>Creates and returns a new <code>QrwLock</code>.</p>
  60. </div><h4 id='method.read' class="method"><span id='read.v' class='invisible'><code>pub fn <a href='#method.read' class='fnname'>read</a>(self) -&gt; <a class="struct" href="../qutex/struct.FutureReadGuard.html" title="struct qutex::FutureReadGuard">FutureReadGuard</a>&lt;T&gt;</code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../src/qutex/qrw_lock.rs.html#477-483' title='goto source code'>[src]</a></span></h4>
  61. <div class='docblock'><p>Returns a new <code>FutureReadGuard</code> which can be used as a future and will
  62. resolve into a <code>ReadGuard</code>.</p>
  63. </div><h4 id='method.write' class="method"><span id='write.v' class='invisible'><code>pub fn <a href='#method.write' class='fnname'>write</a>(self) -&gt; <a class="struct" href="../qutex/struct.FutureWriteGuard.html" title="struct qutex::FutureWriteGuard">FutureWriteGuard</a>&lt;T&gt;</code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../src/qutex/qrw_lock.rs.html#488-494' title='goto source code'>[src]</a></span></h4>
  64. <div class='docblock'><p>Returns a new <code>FutureWriteGuard</code> which can be used as a future and will
  65. resolve into a <code>WriteGuard</code>.</p>
  66. </div><h4 id='method.enqueue_lock_request' class="method"><span id='enqueue_lock_request.v' class='invisible'><code>pub unsafe fn <a href='#method.enqueue_lock_request' class='fnname'>enqueue_lock_request</a>(&amp;self, req: <a class="struct" href="../qutex/struct.QrwRequest.html" title="struct qutex::QrwRequest">QrwRequest</a>)</code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../src/qutex/qrw_lock.rs.html#503-505' title='goto source code'>[src]</a></span></h4>
  67. <div class='docblock'><p>Pushes a lock request onto the queue.</p>
  68. </div><h4 id='method.get_mut' class="method"><span id='get_mut.v' class='invisible'><code>pub fn <a href='#method.get_mut' class='fnname'>get_mut</a>(&amp;mut self) -&gt; <a class="enum" href="https://doc.rust-lang.org/nightly/core/option/enum.Option.html" title="enum core::option::Option">Option</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&amp;mut </a>T&gt;</code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../src/qutex/qrw_lock.rs.html#514-516' title='goto source code'>[src]</a></span></h4>
  69. <div class='docblock'><p>Returns a mutable reference to the inner <code>Vec</code> if there are currently
  70. no other copies of this <code>QrwLock</code>.</p>
  71. <p>Since this call borrows the inner lock mutably, no actual locking needs to
  72. take place---the mutable borrow statically guarantees no locks exist.</p>
  73. </div><h4 id='method.as_ptr' class="method"><span id='as_ptr.v' class='invisible'><code>pub fn <a href='#method.as_ptr' class='fnname'>as_ptr</a>(&amp;self) -&gt; <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.pointer.html">*const T</a></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../src/qutex/qrw_lock.rs.html#521-523' title='goto source code'>[src]</a></span></h4>
  74. <div class='docblock'><p>Returns a reference to the inner value.</p>
  75. </div><h4 id='method.as_mut_ptr' class="method"><span id='as_mut_ptr.v' class='invisible'><code>pub fn <a href='#method.as_mut_ptr' class='fnname'>as_mut_ptr</a>(&amp;self) -&gt; <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.pointer.html">*mut T</a></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../src/qutex/qrw_lock.rs.html#528-530' title='goto source code'>[src]</a></span></h4>
  76. <div class='docblock'><p>Returns a mutable reference to the inner value.</p>
  77. </div><h4 id='method.process_queues' class="method"><span id='process_queues.v' class='invisible'><code>pub unsafe fn <a href='#method.process_queues' class='fnname'>process_queues</a>(&amp;self)</code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../src/qutex/qrw_lock.rs.html#699-744' title='goto source code'>[src]</a></span></h4>
  78. <div class='docblock'><p>Pops the next lock request in the queue if possible.</p>
  79. </div><h4 id='method.upgrade_read_lock' class="method"><span id='upgrade_read_lock.v' class='invisible'><code>pub unsafe fn <a href='#method.upgrade_read_lock' class='fnname'>upgrade_read_lock</a>(&amp;self) -&gt; <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.unit.html">()</a>, <a class="struct" href="../futures/sync/oneshot/struct.Receiver.html" title="struct futures::sync::oneshot::Receiver">Receiver</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.unit.html">()</a>&gt;&gt;</code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../src/qutex/qrw_lock.rs.html#767-790' title='goto source code'>[src]</a></span></h4>
  80. <div class='docblock'><p>Converts a single read lock (read count of '1') into a write lock.</p>
  81. <p>Returns an error containing a oneshot receiver if there is currently
  82. more than one read lock. When the read count reaches one, the receiver
  83. channel will be completed (i.e. poll it).</p>
  84. <p>Panics if there are no read locks.</p>
  85. <p>Do not call this method directly unless you are using a custom guard
  86. or are otherwise managing the lock state manually. Use
  87. <code>ReadGuard::upgrade</code> instead.</p>
  88. </div><h4 id='method.downgrade_write_lock' class="method"><span id='downgrade_write_lock.v' class='invisible'><code>pub unsafe fn <a href='#method.downgrade_write_lock' class='fnname'>downgrade_write_lock</a>(&amp;self)</code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../src/qutex/qrw_lock.rs.html#797-812' title='goto source code'>[src]</a></span></h4>
  89. <div class='docblock'><p>Converts a write lock into a read lock then processes the queue,
  90. allowing additional read requests to acquire locks.</p>
  91. <p>Use <code>WriteGuard::downgrade</code> rather than calling this directly.</p>
  92. </div><h4 id='method.release_read_lock' class="method"><span id='release_read_lock.v' class='invisible'><code>pub unsafe fn <a href='#method.release_read_lock' class='fnname'>release_read_lock</a>(&amp;self)</code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../src/qutex/qrw_lock.rs.html#823-841' title='goto source code'>[src]</a></span></h4>
  93. <div class='docblock'><p>Decreases the reader count by one and unparks the next requester task
  94. in the queue if possible.</p>
  95. <p>If a reader is waiting to be upgraded and the read lock count reaches
  96. 1, the upgrade sender will be completed.</p>
  97. </div><h4 id='method.release_write_lock' class="method"><span id='release_write_lock.v' class='invisible'><code>pub unsafe fn <a href='#method.release_write_lock' class='fnname'>release_write_lock</a>(&amp;self)</code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../src/qutex/qrw_lock.rs.html#848-871' title='goto source code'>[src]</a></span></h4>
  98. <div class='docblock'><p>Unlocks this (the caller's) lock and unparks the next requester task
  99. in the queue if possible.</p>
  100. </div></div>
  101. <h2 id='implementations' class='small-section-header'>
  102. Trait Implementations<a href='#implementations' class='anchor'></a>
  103. </h2>
  104. <h3 id='impl-Debug' class='impl'><span class='in-band'><code>impl&lt;T:&nbsp;<a class="trait" href="https://doc.rust-lang.org/nightly/core/fmt/trait.Debug.html" title="trait core::fmt::Debug">Debug</a>&gt; <a class="trait" href="https://doc.rust-lang.org/nightly/core/fmt/trait.Debug.html" title="trait core::fmt::Debug">Debug</a> for <a class="struct" href="../qutex/struct.QrwLock.html" title="struct qutex::QrwLock">QrwLock</a>&lt;T&gt;</code><a href='#impl-Debug' class='anchor'></a></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../src/qutex/qrw_lock.rs.html#460' title='goto source code'>[src]</a></span></h3>
  105. <div class='impl-items'><h4 id='method.fmt' class="method"><span id='fmt.v' class='invisible'><code>fn <a href='https://doc.rust-lang.org/nightly/core/fmt/trait.Debug.html#tymethod.fmt' class='fnname'>fmt</a>(&amp;self, __arg_0: &amp;mut <a class="struct" href="https://doc.rust-lang.org/nightly/core/fmt/struct.Formatter.html" title="struct core::fmt::Formatter">Formatter</a>) -&gt; <a class="type" href="https://doc.rust-lang.org/nightly/core/fmt/type.Result.html" title="type core::fmt::Result">Result</a></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../src/qutex/qrw_lock.rs.html#460' title='goto source code'>[src]</a></span></h4>
  106. <div class='docblock'><p>Formats the value using the given formatter. <a href="https://doc.rust-lang.org/nightly/core/fmt/trait.Debug.html#tymethod.fmt">Read more</a></p>
  107. </div></div><h3 id='impl-From%3CT%3E' class='impl'><span class='in-band'><code>impl&lt;T&gt; <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.From.html" title="trait core::convert::From">From</a>&lt;T&gt; for <a class="struct" href="../qutex/struct.QrwLock.html" title="struct qutex::QrwLock">QrwLock</a>&lt;T&gt;</code><a href='#impl-From%3CT%3E' class='anchor'></a></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../src/qutex/qrw_lock.rs.html#874-879' title='goto source code'>[src]</a></span></h3>
  108. <div class='impl-items'><h4 id='method.from' class="method"><span id='from.v' class='invisible'><code>fn <a href='https://doc.rust-lang.org/nightly/core/convert/trait.From.html#tymethod.from' class='fnname'>from</a>(val: T) -&gt; <a class="struct" href="../qutex/struct.QrwLock.html" title="struct qutex::QrwLock">QrwLock</a>&lt;T&gt;</code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../src/qutex/qrw_lock.rs.html#876-878' title='goto source code'>[src]</a></span></h4>
  109. <div class='docblock'><p>Performs the conversion.</p>
  110. </div></div><h3 id='impl-Clone' class='impl'><span class='in-band'><code>impl&lt;T&gt; <a class="trait" href="https://doc.rust-lang.org/nightly/core/clone/trait.Clone.html" title="trait core::clone::Clone">Clone</a> for <a class="struct" href="../qutex/struct.QrwLock.html" title="struct qutex::QrwLock">QrwLock</a>&lt;T&gt;</code><a href='#impl-Clone' class='anchor'></a></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../src/qutex/qrw_lock.rs.html#882-889' title='goto source code'>[src]</a></span></h3>
  111. <div class='impl-items'><h4 id='method.clone' class="method"><span id='clone.v' class='invisible'><code>fn <a href='https://doc.rust-lang.org/nightly/core/clone/trait.Clone.html#tymethod.clone' class='fnname'>clone</a>(&amp;self) -&gt; <a class="struct" href="../qutex/struct.QrwLock.html" title="struct qutex::QrwLock">QrwLock</a>&lt;T&gt;</code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../src/qutex/qrw_lock.rs.html#884-888' title='goto source code'>[src]</a></span></h4>
  112. <div class='docblock'><p>Returns a copy of the value. <a href="https://doc.rust-lang.org/nightly/core/clone/trait.Clone.html#tymethod.clone">Read more</a></p>
  113. </div><h4 id='method.clone_from' class="method"><span id='clone_from.v' class='invisible'><code>fn <a href='https://doc.rust-lang.org/nightly/core/clone/trait.Clone.html#method.clone_from' class='fnname'>clone_from</a>(&amp;mut self, source: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&amp;</a>Self)</code></span><span class='out-of-band'><div class='ghost'></div><div class='since' title='Stable since Rust version 1.0.0'>1.0.0</div><a class='srclink' href='https://doc.rust-lang.org/nightly/src/core/clone.rs.html#112-114' title='goto source code'>[src]</a></span></h4>
  114. <div class='docblock'><p>Performs copy-assignment from <code>source</code>. <a href="https://doc.rust-lang.org/nightly/core/clone/trait.Clone.html#method.clone_from">Read more</a></p>
  115. </div></div></section>
  116. <section id='search' class="content hidden"></section>
  117. <section class="footer"></section>
  118. <aside id="help" class="hidden">
  119. <div>
  120. <h1 class="hidden">Help</h1>
  121. <div class="shortcuts">
  122. <h2>Keyboard Shortcuts</h2>
  123. <dl>
  124. <dt><kbd>?</kbd></dt>
  125. <dd>Show this help dialog</dd>
  126. <dt><kbd>S</kbd></dt>
  127. <dd>Focus the search field</dd>
  128. <dt><kbd>↑</kbd></dt>
  129. <dd>Move up in search results</dd>
  130. <dt><kbd>↓</kbd></dt>
  131. <dd>Move down in search results</dd>
  132. <dt><kbd>↹</kbd></dt>
  133. <dd>Switch tab</dd>
  134. <dt><kbd>&#9166;</kbd></dt>
  135. <dd>Go to active search result</dd>
  136. <dt><kbd>+</kbd></dt>
  137. <dd>Expand all sections</dd>
  138. <dt><kbd>-</kbd></dt>
  139. <dd>Collapse all sections</dd>
  140. </dl>
  141. </div>
  142. <div class="infos">
  143. <h2>Search Tricks</h2>
  144. <p>
  145. Prefix searches with a type followed by a colon (e.g.
  146. <code>fn:</code>) to restrict the search to a given type.
  147. </p>
  148. <p>
  149. Accepted types are: <code>fn</code>, <code>mod</code>,
  150. <code>struct</code>, <code>enum</code>,
  151. <code>trait</code>, <code>type</code>, <code>macro</code>,
  152. and <code>const</code>.
  153. </p>
  154. <p>
  155. Search functions by type signature (e.g.
  156. <code>vec -> usize</code> or <code>* -> vec</code>)
  157. </p>
  158. </div>
  159. </div>
  160. </aside>
  161. <script>
  162. window.rootPath = "../";
  163. window.currentCrate = "qutex";
  164. </script>
  165. <script src="../main.js"></script>
  166. <script defer src="../search-index.js"></script>
  167. </body>
  168. </html>