Files
GopherGate/target/doc/parking_lot_core/index.html
2026-02-26 12:00:21 -05:00

31 lines
9.0 KiB
HTML

<!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="This library exposes a low-level API for creating your own efficient synchronization primitives."><title>parking_lot_core - Rust</title><script>if(window.location.protocol!=="file:")document.head.insertAdjacentHTML("beforeend","SourceSerif4-Regular-6b053e98.ttf.woff2,FiraSans-Italic-81dc35de.woff2,FiraSans-Regular-0fe48ade.woff2,FiraSans-MediumItalic-ccf7e434.woff2,FiraSans-Medium-e1aa3f0a.woff2,SourceCodePro-Regular-8badfe75.ttf.woff2,SourceCodePro-Semibold-aa29a496.ttf.woff2".split(",").map(f=>`<link rel="preload" as="font" type="font/woff2"href="../static.files/${f}">`).join(""))</script><link rel="stylesheet" href="../static.files/normalize-9960930a.css"><link rel="stylesheet" href="../static.files/rustdoc-ca0dd0c4.css"><meta name="rustdoc-vars" data-root-path="../" data-static-root-path="../static.files/" data-current-crate="parking_lot_core" data-themes="" data-resource-suffix="" data-rustdoc-version="1.93.1 (01f6ddf75 2026-02-11) (Arch Linux rust 1:1.93.1-1)" data-channel="1.93.1" data-search-js="search-9e2438ea.js" data-stringdex-js="stringdex-a3946164.js" data-settings-js="settings-c38705f0.js" ><script src="../static.files/storage-e2aeef58.js"></script><script defer src="../crates.js"></script><script defer src="../static.files/main-a410ff4d.js"></script><noscript><link rel="stylesheet" href="../static.files/noscript-263c88ec.css"></noscript><link rel="alternate icon" type="image/png" href="../static.files/favicon-32x32-eab170b8.png"><link rel="icon" type="image/svg+xml" href="../static.files/favicon-044be391.svg"></head><body class="rustdoc mod crate"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><rustdoc-topbar><h2><a href="#">Crate parking_lot_core</a></h2></rustdoc-topbar><nav class="sidebar"><div class="sidebar-crate"><h2><a href="../parking_lot_core/index.html">parking_<wbr>lot_<wbr>core</a><span class="version">0.9.12</span></h2></div><div class="sidebar-elems"><ul class="block"><li><a id="all-types" href="all.html">All Items</a></li></ul><section id="rustdoc-toc"><h3><a href="#">Sections</a></h3><ul class="block top-toc"><li><a href="#the-parking-lot" title="The parking lot">The parking lot</a></li><li><a href="#building-custom-synchronization-primitives" title="Building custom synchronization primitives">Building custom synchronization primitives</a></li></ul><h3><a href="#modules">Crate Items</a></h3><ul class="block"><li><a href="#modules" title="Modules">Modules</a></li><li><a href="#structs" title="Structs">Structs</a></li><li><a href="#enums" title="Enums">Enums</a></li><li><a href="#constants" title="Constants">Constants</a></li><li><a href="#functions" title="Functions">Functions</a></li></ul></section><div id="rustdoc-modnav"></div></div></nav><div class="sidebar-resizer" title="Drag to resize sidebar"></div><main><div class="width-limiter"><section id="main-content" class="content"><div class="main-heading"><h1>Crate <span>parking_<wbr>lot_<wbr>core</span>&nbsp;<button id="copy-path" title="Copy item path to clipboard">Copy item path</button></h1><rustdoc-toolbar></rustdoc-toolbar><span class="sub-heading"><a class="src" href="../src/parking_lot_core/lib.rs.html#8-67">Source</a> </span></div><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>This library exposes a low-level API for creating your own efficient
synchronization primitives.</p>
<h2 id="the-parking-lot"><a class="doc-anchor" href="#the-parking-lot">§</a>The parking lot</h2>
<p>To keep synchronization primitives small, all thread queuing and suspending
functionality is offloaded to the <em>parking lot</em>. The idea behind this is based
on the Webkit <a href="https://webkit.org/blog/6161/locking-in-webkit/"><code>WTF::ParkingLot</code></a>
class, which essentially consists of a hash table mapping of lock addresses
to queues of parked (sleeping) threads. The Webkit parking lot was itself
inspired by Linux <a href="http://man7.org/linux/man-pages/man2/futex.2.html">futexes</a>,
but it is more powerful since it allows invoking callbacks while holding a
queue lock.</p>
<p>There are two main operations that can be performed on the parking lot:</p>
<ul>
<li><em>Parking</em> refers to suspending the thread while simultaneously enqueuing it
on a queue keyed by some address.</li>
<li><em>Unparking</em> refers to dequeuing a thread from a queue keyed by some address
and resuming it.</li>
</ul>
<p>See the documentation of the individual functions for more details.</p>
<h2 id="building-custom-synchronization-primitives"><a class="doc-anchor" href="#building-custom-synchronization-primitives">§</a>Building custom synchronization primitives</h2>
<p>Building custom synchronization primitives is very simple since the parking
lot takes care of all the hard parts for you. A simple example for a
custom primitive would be to integrate a <code>Mutex</code> inside another data type.
Since a mutex only requires 2 bits, it can share space with other data.
For example, one could create an <code>ArcMutex</code> type that combines the atomic
reference count and the two mutex bits in the same atomic word.</p>
</div></details><h2 id="modules" class="section-header">Modules<a href="#modules" class="anchor">§</a></h2><dl class="item-table"><dt><a class="mod" href="deadlock/index.html" title="mod parking_lot_core::deadlock">deadlock</a></dt><dd>[Experimental] Deadlock detection</dd></dl><h2 id="structs" class="section-header">Structs<a href="#structs" class="anchor">§</a></h2><dl class="item-table"><dt><a class="struct" href="struct.ParkToken.html" title="struct parking_lot_core::ParkToken">Park<wbr>Token</a></dt><dd>A value associated with a parked thread which can be used by <code>unpark_filter</code>.</dd><dt><a class="struct" href="struct.SpinWait.html" title="struct parking_lot_core::SpinWait">Spin<wbr>Wait</a></dt><dd>A counter used to perform exponential backoff in spin loops.</dd><dt><a class="struct" href="struct.UnparkResult.html" title="struct parking_lot_core::UnparkResult">Unpark<wbr>Result</a></dt><dd>Result of an unpark operation.</dd><dt><a class="struct" href="struct.UnparkToken.html" title="struct parking_lot_core::UnparkToken">Unpark<wbr>Token</a></dt><dd>A value which is passed from an unparker to a parked thread.</dd></dl><h2 id="enums" class="section-header">Enums<a href="#enums" class="anchor">§</a></h2><dl class="item-table"><dt><a class="enum" href="enum.FilterOp.html" title="enum parking_lot_core::FilterOp">Filter<wbr>Op</a></dt><dd>Operation that <code>unpark_filter</code> should perform for each thread.</dd><dt><a class="enum" href="enum.ParkResult.html" title="enum parking_lot_core::ParkResult">Park<wbr>Result</a></dt><dd>Result of a park operation.</dd><dt><a class="enum" href="enum.RequeueOp.html" title="enum parking_lot_core::RequeueOp">Requeue<wbr>Op</a></dt><dd>Operation that <code>unpark_requeue</code> should perform.</dd></dl><h2 id="constants" class="section-header">Constants<a href="#constants" class="anchor">§</a></h2><dl class="item-table"><dt><a class="constant" href="constant.DEFAULT_PARK_TOKEN.html" title="constant parking_lot_core::DEFAULT_PARK_TOKEN">DEFAULT_<wbr>PARK_<wbr>TOKEN</a></dt><dd>A default park token to use.</dd><dt><a class="constant" href="constant.DEFAULT_UNPARK_TOKEN.html" title="constant parking_lot_core::DEFAULT_UNPARK_TOKEN">DEFAULT_<wbr>UNPARK_<wbr>TOKEN</a></dt><dd>A default unpark token to use.</dd></dl><h2 id="functions" class="section-header">Functions<a href="#functions" class="anchor">§</a></h2><dl class="item-table"><dt><a class="fn" href="fn.park.html" title="fn parking_lot_core::park">park</a><sup title="unsafe function"></sup></dt><dd>Parks the current thread in the queue associated with the given key.</dd><dt><a class="fn" href="fn.unpark_all.html" title="fn parking_lot_core::unpark_all">unpark_<wbr>all</a><sup title="unsafe function"></sup></dt><dd>Unparks all threads in the queue associated with the given key.</dd><dt><a class="fn" href="fn.unpark_filter.html" title="fn parking_lot_core::unpark_filter">unpark_<wbr>filter</a><sup title="unsafe function"></sup></dt><dd>Unparks a number of threads from the front of the queue associated with
<code>key</code> depending on the results of a filter function which inspects the
<code>ParkToken</code> associated with each thread.</dd><dt><a class="fn" href="fn.unpark_one.html" title="fn parking_lot_core::unpark_one">unpark_<wbr>one</a><sup title="unsafe function"></sup></dt><dd>Unparks one thread from the queue associated with the given key.</dd><dt><a class="fn" href="fn.unpark_requeue.html" title="fn parking_lot_core::unpark_requeue">unpark_<wbr>requeue</a><sup title="unsafe function"></sup></dt><dd>Removes all threads from the queue associated with <code>key_from</code>, optionally
unparks the first one and requeues the rest onto the queue associated with
<code>key_to</code>.</dd></dl></section></div></main></body></html>