Files
flexiber/delog/fn.try_enqueue.html
2021-03-06 12:00:40 +00:00

19 lines
5.0 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<!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="API documentation for the Rust `try_enqueue` fn in crate `delog`."><meta name="keywords" content="rust, rustlang, rust-lang, try_enqueue"><title>delog::try_enqueue - Rust</title><link rel="stylesheet" type="text/css" href="../normalize.css"><link rel="stylesheet" type="text/css" href="../rustdoc.css" id="mainThemeStyle"><link rel="stylesheet" type="text/css" href="../light.css" id="themeStyle"><link rel="stylesheet" type="text/css" href="../dark.css" disabled ><link rel="stylesheet" type="text/css" href="../ayu.css" disabled ><script id="default-settings"></script><script src="../storage.js"></script><noscript><link rel="stylesheet" href="../noscript.css"></noscript><link rel="icon" type="image/svg+xml" href="../favicon.svg">
<link rel="alternate icon" type="image/png" href="../favicon-16x16.png">
<link rel="alternate icon" type="image/png" href="../favicon-32x32.png"><style type="text/css">#crate-search{background-image:url("../down-arrow.svg");}</style></head><body class="rustdoc fn"><!--[if lte IE 8]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="sidebar"><div class="sidebar-menu">&#9776;</div><a href='../delog/index.html'><div class='logo-container rust-logo'><img src='../rust-logo.png' alt='logo'></div></a><div class="sidebar-elems"><p class="location"><a href="index.html">delog</a></p><script>window.sidebarCurrent = {name: "try_enqueue", ty: "fn", relpath: ""};</script><script defer src="sidebar-items.js"></script></div></nav><div class="theme-picker"><button id="theme-picker" aria-label="Pick another theme!" aria-haspopup="menu"><img src="../brush.svg" width="18" alt="Pick another theme!"></button><div id="theme-choices" role="menu"></div></div><script src="../theme.js"></script><nav class="sub"><form class="search-form"><div class="search-container"><div><select id="crate-search"><option value="All crates">All crates</option></select><input class="search-input" name="search" disabled autocomplete="off" spellcheck="false" placeholder="Click or press S to search, ? for more options…" type="search"></div><button type="button" class="help-button">?</button>
<a id="settings-menu" href="../settings.html"><img src="../wheel.svg" width="18" alt="Change settings"></a></div></form></nav><section id="main" class="content"><h1 class="fqn"><span class="out-of-band"><span id="render-detail"><a id="toggle-all-docs" href="javascript:void(0)" title="collapse all docs">[<span class="inner">&#x2212;</span>]</a></span><a class="srclink" href="../src/delog/logger.rs.html#433-524" title="goto source code">[src]</a></span><span class="in-band">Function <a href="index.html">delog</a>::<wbr><a class="fn" href="">try_enqueue</a></span></h1><pre class="rust fn">pub unsafe fn try_enqueue(<br>&nbsp;&nbsp;&nbsp;&nbsp;delogger: impl <a class="trait" href="../delog/trait.Delogger.html" title="trait delog::Delogger">Delogger</a>, <br>&nbsp;&nbsp;&nbsp;&nbsp;record: &amp;<a class="struct" href="../delog/struct.Record.html" title="struct delog::Record">Record</a>&lt;'_&gt;<br>) -&gt; <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;(), ()&gt;</pre><div class="docblock"><p>The fallible &quot;write to circular buffer&quot; method. Marked unsafe to discourage use!</p>
<h1 id="safety" class="section-header"><a href="#safety">Safety</a></h1>
<p>Unfortunately exposed for all to see, as the <code>delog!</code> macro needs access to it to
implement the logger at call site. Hence marked as unsafe.</p>
<p>This implementation needs some HEAVY testing. It is unsound on PC, where the OS
can schedule threads in any manner, but assumed to be sound in ARM Cortex-M NVIC
situations, where interrupts are &quot;nested&quot;, in the sense that one may be interrupted,
then the interrupter can, ..., then the interrupter hands back control, ..., and finally
the original caller of this function regains control.</p>
<p>In this situation, we keep track of three counters <code>(read, written, claimed)</code>, with
invariants <code>read &lt;= written &lt;= claimed</code>. Each writer pessimistically gauges sufficient
capacity for its log by checking <code>claimed + size &lt;= read + capacity</code>, accounting for the
wraparound. If so, the writer <strong>atomically advances the claim counter</strong>, and starts copying
its data in this newly claimed space. At the end, it is the duty of the &quot;first&quot; caller
to advance the <code>written</code> counter to the correct state.</p>
</div></section><section id="search" class="content hidden"></section><section class="footer"></section><script>window.rootPath = "../";window.currentCrate = "delog";</script><script src="../main.js"></script><script defer src="../search-index.js"></script></body></html>