added the heapless crate and added new docs
This commit is contained in:
parent
a33a57bd49
commit
ba5662a17e
230 changed files with 48215 additions and 40 deletions
1
docs/doc/atomic_polyfill/all.html
Normal file
1
docs/doc/atomic_polyfill/all.html
Normal file
|
@ -0,0 +1 @@
|
|||
<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta name="generator" content="rustdoc"><meta name="description" content="List of all items in this crate"><title>List of all items in this crate</title><link rel="preload" as="font" type="font/woff2" crossorigin href="../static.files/SourceSerif4-Regular-46f98efaafac5295.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../static.files/FiraSans-Regular-018c141bf0843ffd.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../static.files/FiraSans-Medium-8f9a781e4970d388.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../static.files/SourceCodePro-Regular-562dcc5011b6de7d.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../static.files/SourceSerif4-Bold-a2c9cd1067f8b328.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../static.files/SourceCodePro-Semibold-d899c5a5c4aeb14a.ttf.woff2"><link rel="stylesheet" href="../static.files/normalize-76eba96aa4d2e634.css"><link rel="stylesheet" href="../static.files/rustdoc-cb6f1f67f1bcd037.css" id="mainThemeStyle"><meta name="rustdoc-vars" data-root-path="../" data-static-root-path="../static.files/" data-current-crate="atomic_polyfill" data-themes="" data-resource-suffix="" data-rustdoc-version="1.73.0-nightly (500647fd8 2023-07-27)" data-channel="nightly" data-search-js="search-6dfdfced5eff6596.js" data-settings-js="settings-de11bff964e9d4e5.js" data-settings-css="settings-8c76f75bfb6bd192.css" data-theme-light-css="light-6d2c9675f3d09c26.css" data-theme-dark-css="dark-45ceb8f2e522f4d1.css" data-theme-ayu-css="ayu-fd19013d6ce078bf.css" ><script src="../static.files/storage-db41da1a38ea3cb8.js"></script><script defer src="../static.files/main-0795b7d26be81095.js"></script><noscript><link rel="stylesheet" media="(prefers-color-scheme:light)" href="../static.files/light-6d2c9675f3d09c26.css"><link rel="stylesheet" media="(prefers-color-scheme:dark)" href="../static.files/dark-45ceb8f2e522f4d1.css"><link rel="stylesheet" href="../static.files/noscript-cffde32267a19fd6.css"></noscript><link rel="alternate icon" type="image/png" href="../static.files/favicon-16x16-8b506e7a72182f1c.png"><link rel="alternate icon" type="image/png" href="../static.files/favicon-32x32-422f7d1d52889060.png"><link rel="icon" type="image/svg+xml" href="../static.files/favicon-2c020d218678b618.svg"></head><body class="rustdoc mod"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="mobile-topbar"><button class="sidebar-menu-toggle">☰</button><a class="logo-container" href="../atomic_polyfill/index.html"><img class="rust-logo" src="../static.files/rust-logo-151179464ae7ed46.svg" alt="logo"></a><h2></h2></nav><nav class="sidebar"><a class="logo-container" href="../atomic_polyfill/index.html"><img class="rust-logo" src="../static.files/rust-logo-151179464ae7ed46.svg" alt="logo"></a><h2 class="location"><a href="#">Crate atomic_polyfill</a></h2><div class="sidebar-elems"><section><ul class="block"><li><a href="#structs">Structs</a></li><li><a href="#enums">Enums</a></li><li><a href="#constants">Constants</a></li><li><a href="#functions">Functions</a></li></ul></section></div></nav><main><div class="width-limiter"><nav class="sub"><form class="search-form"><span></span><input class="search-input" name="search" aria-label="Run search in the documentation" autocomplete="off" spellcheck="false" placeholder="Click or press ‘S’ to search, ‘?’ for more options…" type="search"><div id="help-button" title="help" tabindex="-1"><a href="../help.html">?</a></div><div id="settings-menu" tabindex="-1"><a href="../settings.html" title="settings"><img width="22" height="22" alt="Change settings" src="../static.files/wheel-7b819b6101059cd0.svg"></a></div></form></nav><section id="main-content" class="content"><h1>List of all items</h1><h3 id="structs">Structs</h3><ul class="all-items"><li><a href="struct.AtomicBool.html">AtomicBool</a></li><li><a href="struct.AtomicI8.html">AtomicI8</a></li><li><a href="struct.AtomicU8.html">AtomicU8</a></li></ul><h3 id="enums">Enums</h3><ul class="all-items"><li><a href="enum.Ordering.html">Ordering</a></li></ul><h3 id="functions">Functions</h3><ul class="all-items"><li><a href="fn.compiler_fence.html">compiler_fence</a></li><li><a href="fn.fence.html">fence</a></li><li><a href="fn.spin_loop_hint.html">spin_loop_hint</a></li></ul><h3 id="constants">Constants</h3><ul class="all-items"><li><a href="constant.ATOMIC_BOOL_INIT.html">ATOMIC_BOOL_INIT</a></li></ul></section></div></main></body></html>
|
2
docs/doc/atomic_polyfill/constant.ATOMIC_BOOL_INIT.html
Normal file
2
docs/doc/atomic_polyfill/constant.ATOMIC_BOOL_INIT.html
Normal file
File diff suppressed because one or more lines are too long
60
docs/doc/atomic_polyfill/enum.Ordering.html
Normal file
60
docs/doc/atomic_polyfill/enum.Ordering.html
Normal file
File diff suppressed because one or more lines are too long
57
docs/doc/atomic_polyfill/fn.compiler_fence.html
Normal file
57
docs/doc/atomic_polyfill/fn.compiler_fence.html
Normal file
|
@ -0,0 +1,57 @@
|
|||
<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta name="generator" content="rustdoc"><meta name="description" content="A compiler memory fence."><title>compiler_fence in atomic_polyfill - Rust</title><link rel="preload" as="font" type="font/woff2" crossorigin href="../static.files/SourceSerif4-Regular-46f98efaafac5295.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../static.files/FiraSans-Regular-018c141bf0843ffd.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../static.files/FiraSans-Medium-8f9a781e4970d388.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../static.files/SourceCodePro-Regular-562dcc5011b6de7d.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../static.files/SourceSerif4-Bold-a2c9cd1067f8b328.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../static.files/SourceCodePro-Semibold-d899c5a5c4aeb14a.ttf.woff2"><link rel="stylesheet" href="../static.files/normalize-76eba96aa4d2e634.css"><link rel="stylesheet" href="../static.files/rustdoc-cb6f1f67f1bcd037.css" id="mainThemeStyle"><meta name="rustdoc-vars" data-root-path="../" data-static-root-path="../static.files/" data-current-crate="atomic_polyfill" data-themes="" data-resource-suffix="" data-rustdoc-version="1.73.0-nightly (500647fd8 2023-07-27)" data-channel="nightly" data-search-js="search-6dfdfced5eff6596.js" data-settings-js="settings-de11bff964e9d4e5.js" data-settings-css="settings-8c76f75bfb6bd192.css" data-theme-light-css="light-6d2c9675f3d09c26.css" data-theme-dark-css="dark-45ceb8f2e522f4d1.css" data-theme-ayu-css="ayu-fd19013d6ce078bf.css" ><script src="../static.files/storage-db41da1a38ea3cb8.js"></script><script defer src="sidebar-items.js"></script><script defer src="../static.files/main-0795b7d26be81095.js"></script><noscript><link rel="stylesheet" media="(prefers-color-scheme:light)" href="../static.files/light-6d2c9675f3d09c26.css"><link rel="stylesheet" media="(prefers-color-scheme:dark)" href="../static.files/dark-45ceb8f2e522f4d1.css"><link rel="stylesheet" href="../static.files/noscript-cffde32267a19fd6.css"></noscript><link rel="alternate icon" type="image/png" href="../static.files/favicon-16x16-8b506e7a72182f1c.png"><link rel="alternate icon" type="image/png" href="../static.files/favicon-32x32-422f7d1d52889060.png"><link rel="icon" type="image/svg+xml" href="../static.files/favicon-2c020d218678b618.svg"></head><body class="rustdoc fn"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="mobile-topbar"><button class="sidebar-menu-toggle">☰</button><a class="logo-container" href="../atomic_polyfill/index.html"><img class="rust-logo" src="../static.files/rust-logo-151179464ae7ed46.svg" alt="logo"></a><h2></h2></nav><nav class="sidebar"><a class="logo-container" href="../atomic_polyfill/index.html"><img class="rust-logo" src="../static.files/rust-logo-151179464ae7ed46.svg" alt="logo"></a><div class="sidebar-elems"><h2><a href="index.html">In atomic_polyfill</a></h2></div></nav><main><div class="width-limiter"><nav class="sub"><form class="search-form"><span></span><input class="search-input" name="search" aria-label="Run search in the documentation" autocomplete="off" spellcheck="false" placeholder="Click or press ‘S’ to search, ‘?’ for more options…" type="search"><div id="help-button" title="help" tabindex="-1"><a href="../help.html">?</a></div><div id="settings-menu" tabindex="-1"><a href="../settings.html" title="settings"><img width="22" height="22" alt="Change settings" src="../static.files/wheel-7b819b6101059cd0.svg"></a></div></form></nav><section id="main-content" class="content"><div class="main-heading"><h1>Function <a href="index.html">atomic_polyfill</a>::<wbr><a class="fn" href="#">compiler_fence</a><button id="copy-path" title="Copy item path to clipboard"><img src="../static.files/clipboard-7571035ce49a181d.svg" width="19" height="18" alt="Copy item path"></button></h1><span class="out-of-band"><span class="since" title="Stable since Rust version 1.21.0">1.21.0</span> · <button id="toggle-all-docs" title="collapse all docs">[<span>−</span>]</button></span></div><pre class="rust item-decl"><code>pub fn compiler_fence(order: <a class="enum" href="enum.Ordering.html" title="enum atomic_polyfill::Ordering">Ordering</a>)</code></pre><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>A compiler memory fence.</p>
|
||||
<p><code>compiler_fence</code> does not emit any machine code, but restricts the kinds
|
||||
of memory re-ordering the compiler is allowed to do. Specifically, depending on
|
||||
the given <a href="enum.Ordering.html" title="enum atomic_polyfill::Ordering"><code>Ordering</code></a> semantics, the compiler may be disallowed from moving reads
|
||||
or writes from before or after the call to the other side of the call to
|
||||
<code>compiler_fence</code>. Note that it does <strong>not</strong> prevent the <em>hardware</em>
|
||||
from doing such re-ordering. This is not a problem in a single-threaded,
|
||||
execution context, but when other threads may modify memory at the same
|
||||
time, stronger synchronization primitives such as <a href="fn.fence.html" title="fn atomic_polyfill::fence"><code>fence</code></a> are required.</p>
|
||||
<p>The re-ordering prevented by the different ordering semantics are:</p>
|
||||
<ul>
|
||||
<li>with <a href="enum.Ordering.html#variant.SeqCst" title="variant atomic_polyfill::Ordering::SeqCst"><code>SeqCst</code></a>, no re-ordering of reads and writes across this point is allowed.</li>
|
||||
<li>with <a href="enum.Ordering.html#variant.Release" title="variant atomic_polyfill::Ordering::Release"><code>Release</code></a>, preceding reads and writes cannot be moved past subsequent writes.</li>
|
||||
<li>with <a href="enum.Ordering.html#variant.Acquire" title="variant atomic_polyfill::Ordering::Acquire"><code>Acquire</code></a>, subsequent reads and writes cannot be moved ahead of preceding reads.</li>
|
||||
<li>with <a href="enum.Ordering.html#variant.AcqRel" title="variant atomic_polyfill::Ordering::AcqRel"><code>AcqRel</code></a>, both of the above rules are enforced.</li>
|
||||
</ul>
|
||||
<p><code>compiler_fence</code> is generally only useful for preventing a thread from
|
||||
racing <em>with itself</em>. That is, if a given thread is executing one piece
|
||||
of code, and is then interrupted, and starts executing code elsewhere
|
||||
(while still in the same thread, and conceptually still on the same
|
||||
core). In traditional programs, this can only occur when a signal
|
||||
handler is registered. In more low-level code, such situations can also
|
||||
arise when handling interrupts, when implementing green threads with
|
||||
pre-emption, etc. Curious readers are encouraged to read the Linux kernel’s
|
||||
discussion of <a href="https://www.kernel.org/doc/Documentation/memory-barriers.txt">memory barriers</a>.</p>
|
||||
<h2 id="panics"><a href="#panics">Panics</a></h2>
|
||||
<p>Panics if <code>order</code> is <a href="enum.Ordering.html#variant.Relaxed" title="variant atomic_polyfill::Ordering::Relaxed"><code>Relaxed</code></a>.</p>
|
||||
<h2 id="examples"><a href="#examples">Examples</a></h2>
|
||||
<p>Without <code>compiler_fence</code>, the <code>assert_eq!</code> in following code
|
||||
is <em>not</em> guaranteed to succeed, despite everything happening in a single thread.
|
||||
To see why, remember that the compiler is free to swap the stores to
|
||||
<code>IMPORTANT_VARIABLE</code> and <code>IS_READY</code> since they are both
|
||||
<code>Ordering::Relaxed</code>. If it does, and the signal handler is invoked right
|
||||
after <code>IS_READY</code> is updated, then the signal handler will see
|
||||
<code>IS_READY=1</code>, but <code>IMPORTANT_VARIABLE=0</code>.
|
||||
Using a <code>compiler_fence</code> remedies this situation.</p>
|
||||
|
||||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>std::sync::atomic::{AtomicBool, AtomicUsize};
|
||||
<span class="kw">use </span>std::sync::atomic::Ordering;
|
||||
<span class="kw">use </span>std::sync::atomic::compiler_fence;
|
||||
|
||||
<span class="kw">static </span>IMPORTANT_VARIABLE: AtomicUsize = AtomicUsize::new(<span class="number">0</span>);
|
||||
<span class="kw">static </span>IS_READY: AtomicBool = AtomicBool::new(<span class="bool-val">false</span>);
|
||||
|
||||
<span class="kw">fn </span>main() {
|
||||
IMPORTANT_VARIABLE.store(<span class="number">42</span>, Ordering::Relaxed);
|
||||
<span class="comment">// prevent earlier writes from being moved beyond this point
|
||||
</span>compiler_fence(Ordering::Release);
|
||||
IS_READY.store(<span class="bool-val">true</span>, Ordering::Relaxed);
|
||||
}
|
||||
|
||||
<span class="kw">fn </span>signal_handler() {
|
||||
<span class="kw">if </span>IS_READY.load(Ordering::Relaxed) {
|
||||
<span class="macro">assert_eq!</span>(IMPORTANT_VARIABLE.load(Ordering::Relaxed), <span class="number">42</span>);
|
||||
}
|
||||
}</code></pre></div>
|
||||
</div></details></section></div></main></body></html>
|
62
docs/doc/atomic_polyfill/fn.fence.html
Normal file
62
docs/doc/atomic_polyfill/fn.fence.html
Normal file
|
@ -0,0 +1,62 @@
|
|||
<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta name="generator" content="rustdoc"><meta name="description" content="An atomic fence."><title>fence in atomic_polyfill - Rust</title><link rel="preload" as="font" type="font/woff2" crossorigin href="../static.files/SourceSerif4-Regular-46f98efaafac5295.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../static.files/FiraSans-Regular-018c141bf0843ffd.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../static.files/FiraSans-Medium-8f9a781e4970d388.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../static.files/SourceCodePro-Regular-562dcc5011b6de7d.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../static.files/SourceSerif4-Bold-a2c9cd1067f8b328.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../static.files/SourceCodePro-Semibold-d899c5a5c4aeb14a.ttf.woff2"><link rel="stylesheet" href="../static.files/normalize-76eba96aa4d2e634.css"><link rel="stylesheet" href="../static.files/rustdoc-cb6f1f67f1bcd037.css" id="mainThemeStyle"><meta name="rustdoc-vars" data-root-path="../" data-static-root-path="../static.files/" data-current-crate="atomic_polyfill" data-themes="" data-resource-suffix="" data-rustdoc-version="1.73.0-nightly (500647fd8 2023-07-27)" data-channel="nightly" data-search-js="search-6dfdfced5eff6596.js" data-settings-js="settings-de11bff964e9d4e5.js" data-settings-css="settings-8c76f75bfb6bd192.css" data-theme-light-css="light-6d2c9675f3d09c26.css" data-theme-dark-css="dark-45ceb8f2e522f4d1.css" data-theme-ayu-css="ayu-fd19013d6ce078bf.css" ><script src="../static.files/storage-db41da1a38ea3cb8.js"></script><script defer src="sidebar-items.js"></script><script defer src="../static.files/main-0795b7d26be81095.js"></script><noscript><link rel="stylesheet" media="(prefers-color-scheme:light)" href="../static.files/light-6d2c9675f3d09c26.css"><link rel="stylesheet" media="(prefers-color-scheme:dark)" href="../static.files/dark-45ceb8f2e522f4d1.css"><link rel="stylesheet" href="../static.files/noscript-cffde32267a19fd6.css"></noscript><link rel="alternate icon" type="image/png" href="../static.files/favicon-16x16-8b506e7a72182f1c.png"><link rel="alternate icon" type="image/png" href="../static.files/favicon-32x32-422f7d1d52889060.png"><link rel="icon" type="image/svg+xml" href="../static.files/favicon-2c020d218678b618.svg"></head><body class="rustdoc fn"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="mobile-topbar"><button class="sidebar-menu-toggle">☰</button><a class="logo-container" href="../atomic_polyfill/index.html"><img class="rust-logo" src="../static.files/rust-logo-151179464ae7ed46.svg" alt="logo"></a><h2></h2></nav><nav class="sidebar"><a class="logo-container" href="../atomic_polyfill/index.html"><img class="rust-logo" src="../static.files/rust-logo-151179464ae7ed46.svg" alt="logo"></a><div class="sidebar-elems"><h2><a href="index.html">In atomic_polyfill</a></h2></div></nav><main><div class="width-limiter"><nav class="sub"><form class="search-form"><span></span><input class="search-input" name="search" aria-label="Run search in the documentation" autocomplete="off" spellcheck="false" placeholder="Click or press ‘S’ to search, ‘?’ for more options…" type="search"><div id="help-button" title="help" tabindex="-1"><a href="../help.html">?</a></div><div id="settings-menu" tabindex="-1"><a href="../settings.html" title="settings"><img width="22" height="22" alt="Change settings" src="../static.files/wheel-7b819b6101059cd0.svg"></a></div></form></nav><section id="main-content" class="content"><div class="main-heading"><h1>Function <a href="index.html">atomic_polyfill</a>::<wbr><a class="fn" href="#">fence</a><button id="copy-path" title="Copy item path to clipboard"><img src="../static.files/clipboard-7571035ce49a181d.svg" width="19" height="18" alt="Copy item path"></button></h1><span class="out-of-band"><span class="since" title="Stable since Rust version 1.0.0">1.0.0</span> · <button id="toggle-all-docs" title="collapse all docs">[<span>−</span>]</button></span></div><pre class="rust item-decl"><code>pub fn fence(order: <a class="enum" href="enum.Ordering.html" title="enum atomic_polyfill::Ordering">Ordering</a>)</code></pre><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>An atomic fence.</p>
|
||||
<p>Depending on the specified order, a fence prevents the compiler and CPU from
|
||||
reordering certain types of memory operations around it.
|
||||
That creates synchronizes-with relationships between it and atomic operations
|
||||
or fences in other threads.</p>
|
||||
<p>A fence ‘A’ which has (at least) <a href="enum.Ordering.html#variant.Release" title="variant atomic_polyfill::Ordering::Release"><code>Release</code></a> ordering semantics, synchronizes
|
||||
with a fence ‘B’ with (at least) <a href="enum.Ordering.html#variant.Acquire" title="variant atomic_polyfill::Ordering::Acquire"><code>Acquire</code></a> semantics, if and only if there
|
||||
exist operations X and Y, both operating on some atomic object ‘M’ such
|
||||
that A is sequenced before X, Y is sequenced before B and Y observes
|
||||
the change to M. This provides a happens-before dependence between A and B.</p>
|
||||
<div class="example-wrap"><pre class="language-text"><code> Thread 1 Thread 2
|
||||
|
||||
fence(Release); A --------------
|
||||
x.store(3, Relaxed); X --------- |
|
||||
| |
|
||||
| |
|
||||
-------------> Y if x.load(Relaxed) == 3 {
|
||||
|-------> B fence(Acquire);
|
||||
...
|
||||
}
|
||||
</code></pre></div>
|
||||
<p>Atomic operations with <a href="enum.Ordering.html#variant.Release" title="variant atomic_polyfill::Ordering::Release"><code>Release</code></a> or <a href="enum.Ordering.html#variant.Acquire" title="variant atomic_polyfill::Ordering::Acquire"><code>Acquire</code></a> semantics can also synchronize
|
||||
with a fence.</p>
|
||||
<p>A fence which has <a href="enum.Ordering.html#variant.SeqCst" title="variant atomic_polyfill::Ordering::SeqCst"><code>SeqCst</code></a> ordering, in addition to having both <a href="enum.Ordering.html#variant.Acquire" title="variant atomic_polyfill::Ordering::Acquire"><code>Acquire</code></a>
|
||||
and <a href="enum.Ordering.html#variant.Release" title="variant atomic_polyfill::Ordering::Release"><code>Release</code></a> semantics, participates in the global program order of the
|
||||
other <a href="enum.Ordering.html#variant.SeqCst" title="variant atomic_polyfill::Ordering::SeqCst"><code>SeqCst</code></a> operations and/or fences.</p>
|
||||
<p>Accepts <a href="enum.Ordering.html#variant.Acquire" title="variant atomic_polyfill::Ordering::Acquire"><code>Acquire</code></a>, <a href="enum.Ordering.html#variant.Release" title="variant atomic_polyfill::Ordering::Release"><code>Release</code></a>, <a href="enum.Ordering.html#variant.AcqRel" title="variant atomic_polyfill::Ordering::AcqRel"><code>AcqRel</code></a> and <a href="enum.Ordering.html#variant.SeqCst" title="variant atomic_polyfill::Ordering::SeqCst"><code>SeqCst</code></a> orderings.</p>
|
||||
<h2 id="panics"><a href="#panics">Panics</a></h2>
|
||||
<p>Panics if <code>order</code> is <a href="enum.Ordering.html#variant.Relaxed" title="variant atomic_polyfill::Ordering::Relaxed"><code>Relaxed</code></a>.</p>
|
||||
<h2 id="examples"><a href="#examples">Examples</a></h2>
|
||||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>std::sync::atomic::AtomicBool;
|
||||
<span class="kw">use </span>std::sync::atomic::fence;
|
||||
<span class="kw">use </span>std::sync::atomic::Ordering;
|
||||
|
||||
<span class="comment">// A mutual exclusion primitive based on spinlock.
|
||||
</span><span class="kw">pub struct </span>Mutex {
|
||||
flag: AtomicBool,
|
||||
}
|
||||
|
||||
<span class="kw">impl </span>Mutex {
|
||||
<span class="kw">pub fn </span>new() -> Mutex {
|
||||
Mutex {
|
||||
flag: AtomicBool::new(<span class="bool-val">false</span>),
|
||||
}
|
||||
}
|
||||
|
||||
<span class="kw">pub fn </span>lock(<span class="kw-2">&</span><span class="self">self</span>) {
|
||||
<span class="comment">// Wait until the old value is `false`.
|
||||
</span><span class="kw">while </span><span class="self">self
|
||||
</span>.flag
|
||||
.compare_exchange_weak(<span class="bool-val">false</span>, <span class="bool-val">true</span>, Ordering::Relaxed, Ordering::Relaxed)
|
||||
.is_err()
|
||||
{}
|
||||
<span class="comment">// This fence synchronizes-with store in `unlock`.
|
||||
</span>fence(Ordering::Acquire);
|
||||
}
|
||||
|
||||
<span class="kw">pub fn </span>unlock(<span class="kw-2">&</span><span class="self">self</span>) {
|
||||
<span class="self">self</span>.flag.store(<span class="bool-val">false</span>, Ordering::Release);
|
||||
}
|
||||
}</code></pre></div>
|
||||
</div></details></section></div></main></body></html>
|
3
docs/doc/atomic_polyfill/fn.spin_loop_hint.html
Normal file
3
docs/doc/atomic_polyfill/fn.spin_loop_hint.html
Normal file
|
@ -0,0 +1,3 @@
|
|||
<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta name="generator" content="rustdoc"><meta name="description" content="Signals the processor that it is inside a busy-wait spin-loop (“spin lock”)."><title>spin_loop_hint in atomic_polyfill - Rust</title><link rel="preload" as="font" type="font/woff2" crossorigin href="../static.files/SourceSerif4-Regular-46f98efaafac5295.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../static.files/FiraSans-Regular-018c141bf0843ffd.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../static.files/FiraSans-Medium-8f9a781e4970d388.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../static.files/SourceCodePro-Regular-562dcc5011b6de7d.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../static.files/SourceSerif4-Bold-a2c9cd1067f8b328.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../static.files/SourceCodePro-Semibold-d899c5a5c4aeb14a.ttf.woff2"><link rel="stylesheet" href="../static.files/normalize-76eba96aa4d2e634.css"><link rel="stylesheet" href="../static.files/rustdoc-cb6f1f67f1bcd037.css" id="mainThemeStyle"><meta name="rustdoc-vars" data-root-path="../" data-static-root-path="../static.files/" data-current-crate="atomic_polyfill" data-themes="" data-resource-suffix="" data-rustdoc-version="1.73.0-nightly (500647fd8 2023-07-27)" data-channel="nightly" data-search-js="search-6dfdfced5eff6596.js" data-settings-js="settings-de11bff964e9d4e5.js" data-settings-css="settings-8c76f75bfb6bd192.css" data-theme-light-css="light-6d2c9675f3d09c26.css" data-theme-dark-css="dark-45ceb8f2e522f4d1.css" data-theme-ayu-css="ayu-fd19013d6ce078bf.css" ><script src="../static.files/storage-db41da1a38ea3cb8.js"></script><script defer src="sidebar-items.js"></script><script defer src="../static.files/main-0795b7d26be81095.js"></script><noscript><link rel="stylesheet" media="(prefers-color-scheme:light)" href="../static.files/light-6d2c9675f3d09c26.css"><link rel="stylesheet" media="(prefers-color-scheme:dark)" href="../static.files/dark-45ceb8f2e522f4d1.css"><link rel="stylesheet" href="../static.files/noscript-cffde32267a19fd6.css"></noscript><link rel="alternate icon" type="image/png" href="../static.files/favicon-16x16-8b506e7a72182f1c.png"><link rel="alternate icon" type="image/png" href="../static.files/favicon-32x32-422f7d1d52889060.png"><link rel="icon" type="image/svg+xml" href="../static.files/favicon-2c020d218678b618.svg"></head><body class="rustdoc fn"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="mobile-topbar"><button class="sidebar-menu-toggle">☰</button><a class="logo-container" href="../atomic_polyfill/index.html"><img class="rust-logo" src="../static.files/rust-logo-151179464ae7ed46.svg" alt="logo"></a><h2></h2></nav><nav class="sidebar"><a class="logo-container" href="../atomic_polyfill/index.html"><img class="rust-logo" src="../static.files/rust-logo-151179464ae7ed46.svg" alt="logo"></a><div class="sidebar-elems"><h2><a href="index.html">In atomic_polyfill</a></h2></div></nav><main><div class="width-limiter"><nav class="sub"><form class="search-form"><span></span><input class="search-input" name="search" aria-label="Run search in the documentation" autocomplete="off" spellcheck="false" placeholder="Click or press ‘S’ to search, ‘?’ for more options…" type="search"><div id="help-button" title="help" tabindex="-1"><a href="../help.html">?</a></div><div id="settings-menu" tabindex="-1"><a href="../settings.html" title="settings"><img width="22" height="22" alt="Change settings" src="../static.files/wheel-7b819b6101059cd0.svg"></a></div></form></nav><section id="main-content" class="content"><div class="main-heading"><h1>Function <a href="index.html">atomic_polyfill</a>::<wbr><a class="fn" href="#">spin_loop_hint</a><button id="copy-path" title="Copy item path to clipboard"><img src="../static.files/clipboard-7571035ce49a181d.svg" width="19" height="18" alt="Copy item path"></button></h1><span class="out-of-band"><span class="since" title="Stable since Rust version 1.24.0">1.24.0</span> · <button id="toggle-all-docs" title="collapse all docs">[<span>−</span>]</button></span></div><pre class="rust item-decl"><code>pub fn spin_loop_hint()</code></pre><span class="item-info"><div class="stab deprecated"><span class="emoji">👎</span><span>Deprecated since 1.51.0: use hint::spin_loop instead</span></div></span><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>Signals the processor that it is inside a busy-wait spin-loop (“spin lock”).</p>
|
||||
<p>This function is deprecated in favor of <a href="crate::hint::spin_loop"><code>hint::spin_loop</code></a>.</p>
|
||||
</div></details></section></div></main></body></html>
|
1
docs/doc/atomic_polyfill/index.html
Normal file
1
docs/doc/atomic_polyfill/index.html
Normal file
File diff suppressed because one or more lines are too long
1
docs/doc/atomic_polyfill/sidebar-items.js
Normal file
1
docs/doc/atomic_polyfill/sidebar-items.js
Normal file
|
@ -0,0 +1 @@
|
|||
window.SIDEBAR_ITEMS = {"constant":["ATOMIC_BOOL_INIT"],"enum":["Ordering"],"fn":["compiler_fence","fence","spin_loop_hint"],"struct":["AtomicBool","AtomicI8","AtomicU8"]};
|
163
docs/doc/atomic_polyfill/struct.AtomicBool.html
Normal file
163
docs/doc/atomic_polyfill/struct.AtomicBool.html
Normal file
File diff suppressed because one or more lines are too long
167
docs/doc/atomic_polyfill/struct.AtomicI8.html
Normal file
167
docs/doc/atomic_polyfill/struct.AtomicI8.html
Normal file
File diff suppressed because one or more lines are too long
167
docs/doc/atomic_polyfill/struct.AtomicU8.html
Normal file
167
docs/doc/atomic_polyfill/struct.AtomicU8.html
Normal file
File diff suppressed because one or more lines are too long
Loading…
Add table
Add a link
Reference in a new issue