2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
3 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
5 <html xmlns="http://www.w3.org/1999/xhtml">
7 <meta http-equiv="X-UA-Compatible" content="IE=Edge" />
8 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
9 <title>Locks — Freedom Metal v201905 documentation</title>
10 <link rel="stylesheet" href="../_static/alabaster.css" type="text/css" />
11 <link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
12 <script type="text/javascript" id="documentation_options" data-url_root="../" src="../_static/documentation_options.js"></script>
13 <script type="text/javascript" src="../_static/jquery.js"></script>
14 <script type="text/javascript" src="../_static/underscore.js"></script>
15 <script type="text/javascript" src="../_static/doctools.js"></script>
16 <link rel="index" title="Index" href="../genindex.html" />
17 <link rel="search" title="Search" href="../search.html" />
18 <link rel="next" title="Memory Enumeration" href="memory.html" />
19 <link rel="prev" title="LEDs" href="led.html" />
21 <link rel="stylesheet" href="../_static/custom.css" type="text/css" />
24 <meta name="viewport" content="width=device-width, initial-scale=0.9, maximum-scale=0.9" />
29 <div class="document">
30 <div class="documentwrapper">
31 <div class="bodywrapper">
34 <div class="body" role="main">
36 <div class="section" id="locks">
37 <h1>Locks<a class="headerlink" href="#locks" title="Permalink to this headline">¶</a></h1>
38 <p>An API for creating and using a software lock/mutex. </p>
39 <div class="breathe-sectiondef docutils container">
40 <p class="breathe-sectiondef-title rubric">Defines</p>
42 <dt id="c.METAL_LOCK_DECLARE">
43 <span class="target" id="lock_8h_1ab374ff07975df10c0dd028439b351af9"></span><code class="descname">METAL_LOCK_DECLARE</code><span class="sig-paren">(</span>name<span class="sig-paren">)</span><a class="headerlink" href="#c.METAL_LOCK_DECLARE" title="Permalink to this definition">¶</a></dt>
44 <dd><p>Declare a lock. </p>
45 <p>Locks must be declared with METAL_LOCK_DECLARE to ensure that the lock is linked into a memory region which supports atomic memory operations. </p>
49 <div class="breathe-sectiondef docutils container">
50 <p class="breathe-sectiondef-title rubric">Functions</p>
52 <dt id="_CPPv315metal_lock_initP10metal_lock">
53 <span id="_CPPv215metal_lock_initP10metal_lock"></span><span id="metal_lock_init__metal_lockP"></span><span class="target" id="lock_8h_1ac6c3769091eb4746302c9c5c9b42050c"></span>int <code class="descname">metal_lock_init</code><span class="sig-paren">(</span><em class="property">struct</em> <a class="reference internal" href="#_CPPv310metal_lock" title="metal_lock">metal_lock</a> *<em>lock</em><span class="sig-paren">)</span><a class="headerlink" href="#_CPPv315metal_lock_initP10metal_lock" title="Permalink to this definition">¶</a><br /></dt>
54 <dd><p>Initialize a lock. </p>
55 <p><p>If the lock cannot be initialized, attempts to take or give the lock will result in a Store/AMO access fault. </p>
57 <dt><strong>Return</strong></dt>
58 <dd>0 if the lock is successfully initialized. A non-zero code indicates failure.</dd>
59 <dt><strong>Parameters</strong></dt>
60 <dd><ul class="breatheparameterlist first last simple">
61 <li><code class="docutils literal notranslate"><span class="pre">lock</span></code>: The handle for a lock </li>
69 <dt id="_CPPv315metal_lock_takeP10metal_lock">
70 <span id="_CPPv215metal_lock_takeP10metal_lock"></span><span id="metal_lock_take__metal_lockP"></span><span class="target" id="lock_8h_1a62f98dd8920e3e1dcab6e87763a0e413"></span>int <code class="descname">metal_lock_take</code><span class="sig-paren">(</span><em class="property">struct</em> <a class="reference internal" href="#_CPPv310metal_lock" title="metal_lock">metal_lock</a> *<em>lock</em><span class="sig-paren">)</span><a class="headerlink" href="#_CPPv315metal_lock_takeP10metal_lock" title="Permalink to this definition">¶</a><br /></dt>
71 <dd><p>Take a lock. </p>
72 <p><p>If the lock initialization failed, attempts to take a lock will result in a Store/AMO access fault. </p>
74 <dt><strong>Return</strong></dt>
75 <dd>0 if the lock is successfully taken</dd>
76 <dt><strong>Parameters</strong></dt>
77 <dd><ul class="breatheparameterlist first last simple">
78 <li><code class="docutils literal notranslate"><span class="pre">lock</span></code>: The handle for a lock </li>
86 <dt id="_CPPv315metal_lock_giveP10metal_lock">
87 <span id="_CPPv215metal_lock_giveP10metal_lock"></span><span id="metal_lock_give__metal_lockP"></span><span class="target" id="lock_8h_1a2a107fe4f7faea16bb3f98e572dc480b"></span>int <code class="descname">metal_lock_give</code><span class="sig-paren">(</span><em class="property">struct</em> <a class="reference internal" href="#_CPPv310metal_lock" title="metal_lock">metal_lock</a> *<em>lock</em><span class="sig-paren">)</span><a class="headerlink" href="#_CPPv315metal_lock_giveP10metal_lock" title="Permalink to this definition">¶</a><br /></dt>
88 <dd><p>Give back a held lock. </p>
89 <p><p>If the lock initialization failed, attempts to give a lock will result in a Store/AMO access fault. </p>
91 <dt><strong>Return</strong></dt>
92 <dd>0 if the lock is successfully given</dd>
93 <dt><strong>Parameters</strong></dt>
94 <dd><ul class="breatheparameterlist first last simple">
95 <li><code class="docutils literal notranslate"><span class="pre">lock</span></code>: The handle for a lock </li>
104 <dt id="_CPPv310metal_lock">
105 <span id="_CPPv210metal_lock"></span><span id="metal_lock"></span><span class="target" id="structmetal__lock"></span><em class="property">struct </em><code class="descname">metal_lock</code><a class="headerlink" href="#_CPPv310metal_lock" title="Permalink to this definition">¶</a><br /></dt>
106 <dd><em>#include <lock.h></em><p>A handle for a lock. </p>
116 <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
117 <div class="sphinxsidebarwrapper">
118 <h1 class="logo"><a href="../index.html">Freedom Metal</a></h1>
129 <li class="toctree-l1"><a class="reference internal" href="../introduction.html">Introduction to Freedom Metal</a></li>
130 <li class="toctree-l1"><a class="reference internal" href="../devguide.html">Developer Guide</a></li>
131 <li class="toctree-l1 current"><a class="reference internal" href="../api.html">API Reference</a><ul class="current">
132 <li class="toctree-l2"><a class="reference internal" href="button.html">Buttons</a></li>
133 <li class="toctree-l2"><a class="reference internal" href="cache.html">Caches</a></li>
134 <li class="toctree-l2"><a class="reference internal" href="clock.html">Clocks</a></li>
135 <li class="toctree-l2"><a class="reference internal" href="cpu.html">CPU</a></li>
136 <li class="toctree-l2"><a class="reference internal" href="gpio.html">GPIO</a></li>
137 <li class="toctree-l2"><a class="reference internal" href="interrupt.html">Interrupts</a></li>
138 <li class="toctree-l2"><a class="reference internal" href="itim.html">ITIM</a></li>
139 <li class="toctree-l2"><a class="reference internal" href="led.html">LEDs</a></li>
140 <li class="toctree-l2 current"><a class="current reference internal" href="#">Locks</a></li>
141 <li class="toctree-l2"><a class="reference internal" href="memory.html">Memory Enumeration</a></li>
142 <li class="toctree-l2"><a class="reference internal" href="pmp.html">PMPs</a></li>
143 <li class="toctree-l2"><a class="reference internal" href="shutdown.html">Shutdown</a></li>
144 <li class="toctree-l2"><a class="reference internal" href="spi.html">SPIs</a></li>
145 <li class="toctree-l2"><a class="reference internal" href="switch.html">Switches</a></li>
146 <li class="toctree-l2"><a class="reference internal" href="timer.html">Timer API</a></li>
147 <li class="toctree-l2"><a class="reference internal" href="tty.html">TTY</a></li>
148 <li class="toctree-l2"><a class="reference internal" href="uart.html">UARTs</a></li>
153 <div class="relations">
154 <h3>Related Topics</h3>
156 <li><a href="../index.html">Documentation overview</a><ul>
157 <li><a href="../api.html">API Reference</a><ul>
158 <li>Previous: <a href="led.html" title="previous chapter">LEDs</a></li>
159 <li>Next: <a href="memory.html" title="next chapter">Memory Enumeration</a></li>
164 <div id="searchbox" style="display: none" role="search">
165 <h3>Quick search</h3>
166 <div class="searchformwrapper">
167 <form class="search" action="../search.html" method="get">
168 <input type="text" name="q" />
169 <input type="submit" value="Go" />
170 <input type="hidden" name="check_keywords" value="yes" />
171 <input type="hidden" name="area" value="default" />
175 <script type="text/javascript">$('#searchbox').show(0);</script>
178 <div class="clearer"></div>
181 ©2019, SiFive Inc..
184 Powered by <a href="http://sphinx-doc.org/">Sphinx 1.7.5</a>
185 & <a href="https://github.com/bitprophet/alabaster">Alabaster 0.7.11</a>
188 <a href="../_sources/apiref/lock.rst.txt"
189 rel="nofollow">Page source</a>