<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<title>Mutex Management</title>
<title>CMSIS-RTOS2: Mutex Management</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="cmsis.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<script type="text/javascript" src="printComponentTabs.js"></script>
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/javascript">
  $(document).ready(initResizable);
  $(window).load(resizeHeight);
</script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/search.js"></script>
<script type="text/javascript">
  $(document).ready(function() { searchBox.OnSelectItem(0); });
</script>
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 46px;">
  <td id="projectlogo"><img alt="Logo" src="CMSIS_Logo_Final.png"/></td>
  <td style="padding-left: 0.5em;">
   <div id="projectname">CMSIS-RTOS2
   &#160;<span id="projectnumber">Version 2.1.0</span>
   </div>
   <div id="projectbrief">Real-Time Operating System: API and RTX Reference Implementation</div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<div id="CMSISnav" class="tabs1">
    <ul class="tablist">
      <script type="text/javascript">
		<!--
		writeComponentTabs.call(this);
		//-->
      </script>
	  </ul>
</div>
<!-- Generated by Doxygen 1.8.6 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Search');
</script>
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="pages.html"><span>Usage&#160;and&#160;Description</span></a></li>
      <li><a href="modules.html"><span>Reference</span></a></li>
      <li>
        <div id="MSearchBox" class="MSearchBoxInactive">
        <span class="left">
          <img id="MSearchSelect" src="search/mag_sel.png"
               onmouseover="return searchBox.OnSearchSelectShow()"
               onmouseout="return searchBox.OnSearchSelectHide()"
               alt=""/>
          <input type="text" id="MSearchField" value="Search" accesskey="S"
               onfocus="searchBox.OnSearchFieldFocus(true)" 
               onblur="searchBox.OnSearchFieldFocus(false)" 
               onkeyup="searchBox.OnSearchFieldChange(event)"/>
          </span><span class="right">
            <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
          </span>
        </div>
      </li>
    </ul>
  </div>
</div><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
      <div id="nav-sync" class="sync"></div>
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
$(document).ready(function(){initNavTree('group__CMSIS__RTOS__MutexMgmt.html','');});
</script>
<div id="doc-content">
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
<a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(0)"><span class="SelectionMark">&#160;</span>All</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(1)"><span class="SelectionMark">&#160;</span>Data Structures</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(2)"><span class="SelectionMark">&#160;</span>Files</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(3)"><span class="SelectionMark">&#160;</span>Functions</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(4)"><span class="SelectionMark">&#160;</span>Variables</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(5)"><span class="SelectionMark">&#160;</span>Typedefs</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(6)"><span class="SelectionMark">&#160;</span>Enumerations</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(7)"><span class="SelectionMark">&#160;</span>Enumerator</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(8)"><span class="SelectionMark">&#160;</span>Macros</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(9)"><span class="SelectionMark">&#160;</span>Groups</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(10)"><span class="SelectionMark">&#160;</span>Pages</a></div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div class="header">
  <div class="summary">
<a href="#nested-classes">Data Structures</a> &#124;
<a href="#define-members">Macros</a> &#124;
<a href="#typedef-members">Typedefs</a> &#124;
<a href="#func-members">Functions</a>  </div>
  <div class="headertitle">
<div class="title">Mutex Management<div class="ingroups"><a class="el" href="group__CMSIS__RTOS.html">CMSIS-RTOS2 API</a></div></div>  </div>
</div><!--header-->
<div class="contents">

<p>Synchronize resource access using Mutual Exclusion (Mutex).  
<a href="#details">More...</a></p>
<table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a name="nested-classes"></a>
Data Structures</h2></td></tr>
<tr class="memitem:structosMutexAttr__t"><td class="memItemLeft" align="right" valign="top">struct &#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__CMSIS__RTOS__MutexMgmt.html#structosMutexAttr__t">osMutexAttr_t</a></td></tr>
<tr class="memdesc:structosMutexAttr__t"><td class="mdescLeft">&#160;</td><td class="mdescRight">Attributes structure for mutex.  <a href="group__CMSIS__RTOS__MutexMgmt.html#structosMutexAttr__t">More...</a><br/></td></tr>
<tr class="separator:structosMutexAttr__t"><td class="memSeparator" colspan="2">&#160;</td></tr>
</table><table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a name="define-members"></a>
Macros</h2></td></tr>
<tr class="memitem:ga65c2482cc64a35d03871f3180f305926"><td class="memItemLeft" align="right" valign="top">#define&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__CMSIS__RTOS__MutexMgmt.html#ga65c2482cc64a35d03871f3180f305926">osMutexRecursive</a>&#160;&#160;&#160;0x00000001U</td></tr>
<tr class="memdesc:ga65c2482cc64a35d03871f3180f305926"><td class="mdescLeft">&#160;</td><td class="mdescRight">Mutex attributes (attr_bits in <a class="el" href="group__CMSIS__RTOS__MutexMgmt.html#structosMutexAttr__t">osMutexAttr_t</a>).  <a href="#ga65c2482cc64a35d03871f3180f305926">More...</a><br/></td></tr>
<tr class="separator:ga65c2482cc64a35d03871f3180f305926"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:ga40fba270cb31a977b3bd551d41eb9599"><td class="memItemLeft" align="right" valign="top">#define&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__CMSIS__RTOS__MutexMgmt.html#ga40fba270cb31a977b3bd551d41eb9599">osMutexPrioInherit</a>&#160;&#160;&#160;0x00000002U</td></tr>
<tr class="memdesc:ga40fba270cb31a977b3bd551d41eb9599"><td class="mdescLeft">&#160;</td><td class="mdescRight">Priority inherit protocol.  <a href="#ga40fba270cb31a977b3bd551d41eb9599">More...</a><br/></td></tr>
<tr class="separator:ga40fba270cb31a977b3bd551d41eb9599"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:gaf0e1dee376798b4d516d164981526780"><td class="memItemLeft" align="right" valign="top">#define&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__CMSIS__RTOS__MutexMgmt.html#gaf0e1dee376798b4d516d164981526780">osMutexRobust</a>&#160;&#160;&#160;0x00000008U</td></tr>
<tr class="memdesc:gaf0e1dee376798b4d516d164981526780"><td class="mdescLeft">&#160;</td><td class="mdescRight">Robust mutex.  <a href="#gaf0e1dee376798b4d516d164981526780">More...</a><br/></td></tr>
<tr class="separator:gaf0e1dee376798b4d516d164981526780"><td class="memSeparator" colspan="2">&#160;</td></tr>
</table><table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a name="typedef-members"></a>
Typedefs</h2></td></tr>
<tr class="memitem:ga313801836c62deb23055efb55a420e42"><td class="memItemLeft" align="right" valign="top">typedef void *&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__CMSIS__RTOS__MutexMgmt.html#ga313801836c62deb23055efb55a420e42">osMutexId_t</a></td></tr>
<tr class="separator:ga313801836c62deb23055efb55a420e42"><td class="memSeparator" colspan="2">&#160;</td></tr>
</table><table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a name="func-members"></a>
Functions</h2></td></tr>
<tr class="memitem:gab90920022ab944296821368ef6bb52f8"><td class="memItemLeft" align="right" valign="top"><a class="el" href="group__CMSIS__RTOS__MutexMgmt.html#ga313801836c62deb23055efb55a420e42">osMutexId_t</a>&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__CMSIS__RTOS__MutexMgmt.html#gab90920022ab944296821368ef6bb52f8">osMutexNew</a> (const <a class="el" href="group__CMSIS__RTOS__MutexMgmt.html#structosMutexAttr__t">osMutexAttr_t</a> *attr)</td></tr>
<tr class="memdesc:gab90920022ab944296821368ef6bb52f8"><td class="mdescLeft">&#160;</td><td class="mdescRight">Create and Initialize a Mutex object.  <a href="#gab90920022ab944296821368ef6bb52f8">More...</a><br/></td></tr>
<tr class="separator:gab90920022ab944296821368ef6bb52f8"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:ga00b5e58cd247a412d1afd18732d8b752"><td class="memItemLeft" align="right" valign="top">const char *&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__CMSIS__RTOS__MutexMgmt.html#ga00b5e58cd247a412d1afd18732d8b752">osMutexGetName</a> (<a class="el" href="group__CMSIS__RTOS__MutexMgmt.html#ga313801836c62deb23055efb55a420e42">osMutexId_t</a> mutex_id)</td></tr>
<tr class="memdesc:ga00b5e58cd247a412d1afd18732d8b752"><td class="mdescLeft">&#160;</td><td class="mdescRight">Get name of a Mutex object.  <a href="#ga00b5e58cd247a412d1afd18732d8b752">More...</a><br/></td></tr>
<tr class="separator:ga00b5e58cd247a412d1afd18732d8b752"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:gabc54686ea0fc281823b1763422d2a924"><td class="memItemLeft" align="right" valign="top"><a class="el" href="group__CMSIS__RTOS__Definitions.html#ga6c0dbe6069e4e7f47bb4cd32ae2b813e">osStatus_t</a>&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__CMSIS__RTOS__MutexMgmt.html#gabc54686ea0fc281823b1763422d2a924">osMutexAcquire</a> (<a class="el" href="group__CMSIS__RTOS__MutexMgmt.html#ga313801836c62deb23055efb55a420e42">osMutexId_t</a> mutex_id, uint32_t timeout)</td></tr>
<tr class="memdesc:gabc54686ea0fc281823b1763422d2a924"><td class="mdescLeft">&#160;</td><td class="mdescRight">Acquire a Mutex or timeout if it is locked.  <a href="#gabc54686ea0fc281823b1763422d2a924">More...</a><br/></td></tr>
<tr class="separator:gabc54686ea0fc281823b1763422d2a924"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:gaea629705703580ff58776bf73c8db915"><td class="memItemLeft" align="right" valign="top"><a class="el" href="group__CMSIS__RTOS__Definitions.html#ga6c0dbe6069e4e7f47bb4cd32ae2b813e">osStatus_t</a>&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__CMSIS__RTOS__MutexMgmt.html#gaea629705703580ff58776bf73c8db915">osMutexRelease</a> (<a class="el" href="group__CMSIS__RTOS__MutexMgmt.html#ga313801836c62deb23055efb55a420e42">osMutexId_t</a> mutex_id)</td></tr>
<tr class="memdesc:gaea629705703580ff58776bf73c8db915"><td class="mdescLeft">&#160;</td><td class="mdescRight">Release a Mutex that was acquired by <a class="el" href="group__CMSIS__RTOS__MutexMgmt.html#gabc54686ea0fc281823b1763422d2a924">osMutexAcquire</a>.  <a href="#gaea629705703580ff58776bf73c8db915">More...</a><br/></td></tr>
<tr class="separator:gaea629705703580ff58776bf73c8db915"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:ga7f9a7666df0978738cd570cb700b83fb"><td class="memItemLeft" align="right" valign="top"><a class="el" href="group__CMSIS__RTOS__ThreadMgmt.html#gaa6c32fe2a3e0a2e01f212d55b02e51c7">osThreadId_t</a>&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__CMSIS__RTOS__MutexMgmt.html#ga7f9a7666df0978738cd570cb700b83fb">osMutexGetOwner</a> (<a class="el" href="group__CMSIS__RTOS__MutexMgmt.html#ga313801836c62deb23055efb55a420e42">osMutexId_t</a> mutex_id)</td></tr>
<tr class="memdesc:ga7f9a7666df0978738cd570cb700b83fb"><td class="mdescLeft">&#160;</td><td class="mdescRight">Get Thread which owns a Mutex object.  <a href="#ga7f9a7666df0978738cd570cb700b83fb">More...</a><br/></td></tr>
<tr class="separator:ga7f9a7666df0978738cd570cb700b83fb"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:gabee73ad227ba4587d3db12ef9bd582bc"><td class="memItemLeft" align="right" valign="top"><a class="el" href="group__CMSIS__RTOS__Definitions.html#ga6c0dbe6069e4e7f47bb4cd32ae2b813e">osStatus_t</a>&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__CMSIS__RTOS__MutexMgmt.html#gabee73ad227ba4587d3db12ef9bd582bc">osMutexDelete</a> (<a class="el" href="group__CMSIS__RTOS__MutexMgmt.html#ga313801836c62deb23055efb55a420e42">osMutexId_t</a> mutex_id)</td></tr>
<tr class="memdesc:gabee73ad227ba4587d3db12ef9bd582bc"><td class="mdescLeft">&#160;</td><td class="mdescRight">Delete a Mutex object.  <a href="#gabee73ad227ba4587d3db12ef9bd582bc">More...</a><br/></td></tr>
<tr class="separator:gabee73ad227ba4587d3db12ef9bd582bc"><td class="memSeparator" colspan="2">&#160;</td></tr>
</table>
<a name="details" id="details"></a><h2 class="groupheader">Description</h2>
<p><b>Mutual exclusion</b> (widely known as <b>Mutex</b>) is used in various operating systems for resource management. Many resources in a microcontroller device can be used repeatedly, but only by one thread at a time (for example communication channels, memory, and files). Mutexes are used to protect access to a shared resource. A mutex is created and then passed between the threads (they can acquire and release the mutex).</p>
<div class="image">
<img src="Mutex.png" alt="Mutex.png"/>
<div class="caption">
CMSIS-RTOS Mutex</div></div>
<p> A mutex is a special version of a <a class="el" href="group__CMSIS__RTOS__SemaphoreMgmt.html">semaphore</a>. Like the semaphore, it is a container for tokens. But instead of being able to have multiple tokens, a mutex can only carry one (representing the resource). Thus, a mutex token is binary and bounded. The advantage of a mutex is that it introduces thread ownership. When a thread acquires a mutex and becomes its owner, subsequent mutex acquires from that thread will succeed immediately without any latency (if <a class="el" href="group__CMSIS__RTOS__MutexMgmt.html#ga65c2482cc64a35d03871f3180f305926">osMutexRecursive</a> is specified). Thus, mutex acquires/releases can be nested.</p>
<dl class="section note"><dt>Note</dt><dd>Mutex management functions cannot be called from <a class="el" href="theory_of_operation.html#CMSIS_RTOS_ISR_Calls">Interrupt Service Routines</a> (ISR), unlike a binary semaphore that can be released from an ISR. </dd>
<dd>
Refer to <a class="el" href="config_rtx5.html#mutexConfig">Mutex Configuration</a> for RTX5 configuration options. </dd></dl>
<hr/><h2 class="groupheader">Data Structure Documentation</h2>
<a name="structosMutexAttr__t" id="structosMutexAttr__t"></a>
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">struct osMutexAttr_t</td>
        </tr>
      </table>
</div><div class="memdoc">
<div class="textblock"></div><table class="fieldtable">
<tr><th colspan="3">Data Fields</th></tr>
<tr><td class="fieldtype">
<a class="anchor" id="ab74e6bf80237ddc4109968cedc58c151"></a>const char *</td>
<td class="fieldname">
name</td>
<td class="fielddoc">
name of the mutex <p>String with a human readable name of the mutex object. </p>
</td></tr>
<tr><td class="fieldtype">
<a class="anchor" id="a6e93b49cb79c12f768d72580c7731f30"></a>uint32_t</td>
<td class="fieldname">
attr_bits</td>
<td class="fielddoc">
attribute bits <p>The following predefined bit masks can be assigned to set options for a mutex object.</p>
<table class="doxtable">
<tr>
<th align="left">Bit Mask </th><th align="left">Description  </th></tr>
<tr>
<td align="left"><span class="XML-Token">osMutexRecursive</span> </td><td align="left">Mutex is recursive. The same thread can consume a mutex multiple times without locking itself. </td></tr>
<tr>
<td align="left"><span class="XML-Token">osMutexPrioInherit</span> </td><td align="left">Priority inheritance protocol. While a thread owns this mutex it cannot be preempted by a higher priority thread to avoid starvation. </td></tr>
<tr>
<td align="left"><span class="XML-Token">osMutexRobust</span> </td><td align="left">Robust mutex. Notify threads that acquire a mutex if the previous owner was terminated. </td></tr>
</table>
</td></tr>
<tr><td class="fieldtype">
<a class="anchor" id="a1e100dc33d403841ed3c344e3397868e"></a>void *</td>
<td class="fieldname">
cb_mem</td>
<td class="fielddoc">
memory for control block <p>Pointer to a memory location for the mutex object. This can optionally be used for custom memory management systems. Specify NULL to use the kernel memory management. </p>
</td></tr>
<tr><td class="fieldtype">
<a class="anchor" id="aa55a4335d12dc2785dc00fdc292d1159"></a>uint32_t</td>
<td class="fieldname">
cb_size</td>
<td class="fielddoc">
size of provided memory for control block <p>The size of the memory block passed with <a class="el" href="group__CMSIS__RTOS__MutexMgmt.html#a1e100dc33d403841ed3c344e3397868e">cb_mem</a>. Must be the size of a mutex object or larger. </p>
</td></tr>
</table>

</div>
</div>
<h2 class="groupheader">Macro Definition Documentation</h2>
<a class="anchor" id="ga65c2482cc64a35d03871f3180f305926"></a>
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">#define osMutexRecursive&#160;&#160;&#160;0x00000001U</td>
        </tr>
      </table>
</div><div class="memdoc">
<p>Recursive mutex.</p>
<ul>
<li><a class="el" href="group__CMSIS__RTOS__MutexMgmt.html#structosMutexAttr__t">osMutexAttr_t</a> </li>
</ul>

</div>
</div>
<a class="anchor" id="ga40fba270cb31a977b3bd551d41eb9599"></a>
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">#define osMutexPrioInherit&#160;&#160;&#160;0x00000002U</td>
        </tr>
      </table>
</div><div class="memdoc">
<ul>
<li><a class="el" href="group__CMSIS__RTOS__MutexMgmt.html#structosMutexAttr__t">osMutexAttr_t</a> </li>
</ul>

</div>
</div>
<a class="anchor" id="gaf0e1dee376798b4d516d164981526780"></a>
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">#define osMutexRobust&#160;&#160;&#160;0x00000008U</td>
        </tr>
      </table>
</div><div class="memdoc">
<ul>
<li><a class="el" href="group__CMSIS__RTOS__MutexMgmt.html#structosMutexAttr__t">osMutexAttr_t</a> </li>
</ul>

</div>
</div>
<h2 class="groupheader">Typedef Documentation</h2>
<a class="anchor" id="ga313801836c62deb23055efb55a420e42"></a>
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname"><a class="el" href="group__CMSIS__RTOS__MutexMgmt.html#ga313801836c62deb23055efb55a420e42">osMutexId_t</a></td>
        </tr>
      </table>
</div><div class="memdoc">
<p>Mutex ID identifies the mutex. </p>

</div>
</div>
<h2 class="groupheader">Function Documentation</h2>
<a class="anchor" id="gab90920022ab944296821368ef6bb52f8"></a>
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname"><a class="el" href="group__CMSIS__RTOS__MutexMgmt.html#ga313801836c62deb23055efb55a420e42">osMutexId_t</a> osMutexNew </td>
          <td>(</td>
          <td class="paramtype">const <a class="el" href="group__CMSIS__RTOS__MutexMgmt.html#structosMutexAttr__t">osMutexAttr_t</a> *&#160;</td>
          <td class="paramname"><em>attr</em></td><td>)</td>
          <td></td>
        </tr>
      </table>
</div><div class="memdoc">
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramdir">[in]</td><td class="paramname">attr</td><td>mutex attributes; NULL: default values. </td></tr>
  </table>
  </dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>mutex ID for reference by other functions or NULL in case of error.</dd></dl>
<p>The function <b>osMutexNew</b> creates and initializes a new mutex object and returns the pointer to the mutex object identifier or <span class="XML-Token">NULL</span> in case of an error.</p>
<p>The parameter <em>attr</em> sets the mutex object attributes (refer to <a class="el" href="group__CMSIS__RTOS__MutexMgmt.html#structosMutexAttr__t">osMutexAttr_t</a>). Default attributes will be used if set to <span class="XML-Token">NULL</span>.</p>
<dl class="section note"><dt>Note</dt><dd>This function <b>cannot</b> be called from <a class="el" href="theory_of_operation.html#CMSIS_RTOS_ISR_Calls">Interrupt Service Routines</a>.</dd></dl>
<p><b>Code Example</b> </p>
<div class="fragment"><div class="line"><span class="preprocessor">#include &quot;<a class="code" href="cmsis__os2_8h.html">cmsis_os2.h</a>&quot;</span></div>
<div class="line">  </div>
<div class="line"><a class="code" href="group__CMSIS__RTOS__MutexMgmt.html#ga313801836c62deb23055efb55a420e42">osMutexId_t</a> mutex_id;  </div>
<div class="line">  </div>
<div class="line"><span class="keyword">const</span> <a class="code" href="group__CMSIS__RTOS__MutexMgmt.html#structosMutexAttr__t">osMutexAttr_t</a> Thread_Mutex_attr = {</div>
<div class="line">  <span class="stringliteral">&quot;myThreadMutex&quot;</span>,                          <span class="comment">// human readable mutex name</span></div>
<div class="line">  <a class="code" href="group__CMSIS__RTOS__MutexMgmt.html#ga65c2482cc64a35d03871f3180f305926">osMutexRecursive</a> | <a class="code" href="group__CMSIS__RTOS__MutexMgmt.html#ga40fba270cb31a977b3bd551d41eb9599">osMutexPrioInherit</a>,    <span class="comment">// attr_bits</span></div>
<div class="line">  NULL,                                     <span class="comment">// memory for control block   </span></div>
<div class="line">  NULL                                      <span class="comment">// size for control block</span></div>
<div class="line">  };</div>
<div class="line">  </div>
<div class="line"><span class="keywordtype">void</span> CreateMutex (<span class="keywordtype">void</span>)  {</div>
<div class="line"> </div>
<div class="line">  mutex_id = <a class="code" href="group__CMSIS__RTOS__MutexMgmt.html#gab90920022ab944296821368ef6bb52f8">osMutexNew</a>(&amp;Thread_Mutex_attr);</div>
<div class="line">  <span class="keywordflow">if</span> (mutex_id != NULL)  {</div>
<div class="line">    <span class="comment">// Mutex object created</span></div>
<div class="line">  }   </div>
<div class="line">}</div>
</div><!-- fragment --> 
</div>
</div>
<a class="anchor" id="ga00b5e58cd247a412d1afd18732d8b752"></a>
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">*const char * osMutexGetName </td>
          <td>(</td>
          <td class="paramtype"><a class="el" href="group__CMSIS__RTOS__MutexMgmt.html#ga313801836c62deb23055efb55a420e42">osMutexId_t</a>&#160;</td>
          <td class="paramname"><em>mutex_id</em></td><td>)</td>
          <td></td>
        </tr>
      </table>
</div><div class="memdoc">
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramdir">[in]</td><td class="paramname">mutex_id</td><td>mutex ID obtained by <a class="el" href="group__CMSIS__RTOS__MutexMgmt.html#gab90920022ab944296821368ef6bb52f8">osMutexNew</a>. </td></tr>
  </table>
  </dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>name as NULL terminated string.</dd></dl>
<p>The function <b>osMutexGetName</b> returns the pointer to the name string of the mutex identified by parameter <em>mutex_id</em> or <span class="XML-Token">NULL</span> in case of an error.</p>
<dl class="section note"><dt>Note</dt><dd>This function <b>cannot</b> be called from <a class="el" href="theory_of_operation.html#CMSIS_RTOS_ISR_Calls">Interrupt Service Routines</a>. </dd></dl>

</div>
</div>
<a class="anchor" id="gabc54686ea0fc281823b1763422d2a924"></a>
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname"><a class="el" href="group__CMSIS__RTOS__Definitions.html#ga6c0dbe6069e4e7f47bb4cd32ae2b813e">osStatus_t</a> osMutexAcquire </td>
          <td>(</td>
          <td class="paramtype"><a class="el" href="group__CMSIS__RTOS__MutexMgmt.html#ga313801836c62deb23055efb55a420e42">osMutexId_t</a>&#160;</td>
          <td class="paramname"><em>mutex_id</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">uint32_t&#160;</td>
          <td class="paramname"><em>timeout</em>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
</div><div class="memdoc">
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramdir">[in]</td><td class="paramname">mutex_id</td><td>mutex ID obtained by <a class="el" href="group__CMSIS__RTOS__MutexMgmt.html#gab90920022ab944296821368ef6bb52f8">osMutexNew</a>. </td></tr>
    <tr><td class="paramdir">[in]</td><td class="paramname">timeout</td><td><a class="el" href="theory_of_operation.html#CMSIS_RTOS_TimeOutValue">Timeout Value</a> or 0 in case of no time-out. </td></tr>
  </table>
  </dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>status code that indicates the execution status of the function.</dd></dl>
<p>The blocking function <b>osMutexAcquire</b> waits until a mutex object specified by parameter <em>mutex_id</em> becomes available. If no other thread has obtained the mutex, the function instantly returns and blocks the mutex object.</p>
<p>The parameter <em>timeout</em> specifies how long the system waits to acquire the mutex. While the system waits, the thread that is calling this function is put into the <b>BLOCKED</b> state. The parameter <a class="el" href="theory_of_operation.html#CMSIS_RTOS_TimeOutValue">timeout</a> can have the following values:</p>
<ul>
<li>when <em>timeout</em> is <span class="XML-Token">0</span>, the function returns instantly.</li>
<li>when <em>timeout</em> is set to <b>osWaitForever</b> the function will wait for an infinite time until the mutex becomes available.</li>
<li>all other values specify a time in kernel ticks for a timeout.</li>
</ul>
<p>Possible <a class="el" href="group__CMSIS__RTOS__Definitions.html#ga6c0dbe6069e4e7f47bb4cd32ae2b813e">osStatus_t</a> return values:</p>
<ul>
<li><em>osOK:</em> the mutex has been obtained.</li>
<li><em>osErrorTimeout:</em> the mutex could not be obtained in the given time.</li>
<li><em>osErrorParameter:</em> parameter <em>mutex_id</em> is <span class="XML-Token">NULL</span> or invalid.</li>
<li><em>osErrorResource:</em> the mutex specified by parameter <em>mutex_id</em> is in an invalid mutex state or the mutex could not be obtained when no <em>timeout</em> was specified.</li>
<li><em>osErrorISR:</em> cannot be called from interrupt service routines.</li>
</ul>
<dl class="section note"><dt>Note</dt><dd>This function <b>cannot</b> be called from <a class="el" href="theory_of_operation.html#CMSIS_RTOS_ISR_Calls">Interrupt Service Routines</a>.</dd></dl>
<p><b>Code Example</b> </p>
<div class="fragment"><div class="line"><span class="preprocessor">#include &quot;<a class="code" href="cmsis__os2_8h.html">cmsis_os2.h</a>&quot;</span></div>
<div class="line">  </div>
<div class="line"><span class="keywordtype">void</span> WaitMutex (<span class="keywordtype">void</span>)  {</div>
<div class="line"><a class="code" href="group__CMSIS__RTOS__MutexMgmt.html#ga313801836c62deb23055efb55a420e42">osMutexId_t</a> mutex_id;   </div>
<div class="line"><a class="code" href="group__CMSIS__RTOS__Definitions.html#ga6c0dbe6069e4e7f47bb4cd32ae2b813e">osStatus_t</a>  status;</div>
<div class="line"> </div>
<div class="line">  mutex_id = <a class="code" href="group__CMSIS__RTOS__MutexMgmt.html#gab90920022ab944296821368ef6bb52f8">osMutexNew</a>(NULL);</div>
<div class="line">  <span class="keywordflow">if</span> (mutex_id != NULL)  {</div>
<div class="line">    status  = <a class="code" href="group__CMSIS__RTOS__MutexMgmt.html#gabc54686ea0fc281823b1763422d2a924">osMutexAcquire</a>(mutex_id, 0);</div>
<div class="line">    <span class="keywordflow">if</span> (status != <a class="code" href="cmsis__os2_8h.html#ga6c0dbe6069e4e7f47bb4cd32ae2b813ea9e1c9e2550bb4de8969a935acffc968f">osOK</a>)  {</div>
<div class="line">      <span class="comment">// handle failure code</span></div>
<div class="line">    }</div>
<div class="line">  }</div>
<div class="line">}</div>
</div><!-- fragment --> 
</div>
</div>
<a class="anchor" id="gaea629705703580ff58776bf73c8db915"></a>
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname"><a class="el" href="group__CMSIS__RTOS__Definitions.html#ga6c0dbe6069e4e7f47bb4cd32ae2b813e">osStatus_t</a> osMutexRelease </td>
          <td>(</td>
          <td class="paramtype"><a class="el" href="group__CMSIS__RTOS__MutexMgmt.html#ga313801836c62deb23055efb55a420e42">osMutexId_t</a>&#160;</td>
          <td class="paramname"><em>mutex_id</em></td><td>)</td>
          <td></td>
        </tr>
      </table>
</div><div class="memdoc">
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramdir">[in]</td><td class="paramname">mutex_id</td><td>mutex ID obtained by <a class="el" href="group__CMSIS__RTOS__MutexMgmt.html#gab90920022ab944296821368ef6bb52f8">osMutexNew</a>. </td></tr>
  </table>
  </dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>status code that indicates the execution status of the function.</dd></dl>
<p>The function <b>osMutexRelease</b> releases a mutex specified by parameter <em>mutex_id</em>. Other threads that currently wait for this mutex will be put into the <b>READY</b> state.</p>
<p>Possible <a class="el" href="group__CMSIS__RTOS__Definitions.html#ga6c0dbe6069e4e7f47bb4cd32ae2b813e">osStatus_t</a> return values:</p>
<ul>
<li><em>osOK:</em> the mutex has been correctly released.</li>
<li><em>osErrorParameter:</em> parameter <em>mutex_id</em> is <span class="XML-Token">NULL</span> or invalid.</li>
<li><em>osErrorResource:</em> the mutex specified by parameter <em>mutex_id</em> is in an invalid mutex state or the mutex was not obtained before/the current thread is not the owner of the mutex.</li>
<li><em>osErrorISR:</em> <b>osMutexRelease</b> cannot be called from interrupt service routines.</li>
</ul>
<dl class="section note"><dt>Note</dt><dd>This function <b>cannot</b> be called from <a class="el" href="theory_of_operation.html#CMSIS_RTOS_ISR_Calls">Interrupt Service Routines</a>.</dd></dl>
<p><b>Code Example</b> </p>
<div class="fragment"><div class="line"><span class="preprocessor">#include &quot;<a class="code" href="cmsis__os2_8h.html">cmsis_os2.h</a>&quot;</span></div>
<div class="line">  </div>
<div class="line"><a class="code" href="group__CMSIS__RTOS__MutexMgmt.html#ga313801836c62deb23055efb55a420e42">osMutexId_t</a> mutex_id;                                        <span class="comment">// Mutex id populated by the function osMutexNew()</span></div>
<div class="line"> </div>
<div class="line"><span class="keywordtype">void</span> ReleaseMutex (<a class="code" href="group__CMSIS__RTOS__MutexMgmt.html#ga313801836c62deb23055efb55a420e42">osMutexId_t</a> mutex_id)  {</div>
<div class="line"><a class="code" href="group__CMSIS__RTOS__Definitions.html#ga6c0dbe6069e4e7f47bb4cd32ae2b813e">osStatus_t</a> status;</div>
<div class="line">  </div>
<div class="line">  <span class="keywordflow">if</span> (mutex_id != NULL)  {</div>
<div class="line">    status = <a class="code" href="group__CMSIS__RTOS__MutexMgmt.html#gaea629705703580ff58776bf73c8db915">osMutexRelease</a>(mutex_id);</div>
<div class="line">    <span class="keywordflow">if</span> (status != <a class="code" href="cmsis__os2_8h.html#ga6c0dbe6069e4e7f47bb4cd32ae2b813ea9e1c9e2550bb4de8969a935acffc968f">osOK</a>)  {</div>
<div class="line">      <span class="comment">// handle failure code</span></div>
<div class="line">    }</div>
<div class="line">  }</div>
<div class="line">}</div>
</div><!-- fragment --> 
</div>
</div>
<a class="anchor" id="ga7f9a7666df0978738cd570cb700b83fb"></a>
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname"><a class="el" href="group__CMSIS__RTOS__ThreadMgmt.html#gaa6c32fe2a3e0a2e01f212d55b02e51c7">osThreadId_t</a> osMutexGetOwner </td>
          <td>(</td>
          <td class="paramtype"><a class="el" href="group__CMSIS__RTOS__MutexMgmt.html#ga313801836c62deb23055efb55a420e42">osMutexId_t</a>&#160;</td>
          <td class="paramname"><em>mutex_id</em></td><td>)</td>
          <td></td>
        </tr>
      </table>
</div><div class="memdoc">
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramdir">[in]</td><td class="paramname">mutex_id</td><td>mutex ID obtained by <a class="el" href="group__CMSIS__RTOS__MutexMgmt.html#gab90920022ab944296821368ef6bb52f8">osMutexNew</a>. </td></tr>
  </table>
  </dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>thread ID of owner thread or NULL when mutex was not acquired.</dd></dl>
<p>The function <b>osMutexGetOwner</b> returns the thread object ID of the thread that acquired a mutex specified by parameter <em>mutex_id</em>. In case of an error or if the mutex is not owned by the thread, it returns <span class="XML-Token">NULL</span>.</p>
<dl class="section note"><dt>Note</dt><dd>This function <b>cannot</b> be called from <a class="el" href="theory_of_operation.html#CMSIS_RTOS_ISR_Calls">Interrupt Service Routines</a>. </dd></dl>

</div>
</div>
<a class="anchor" id="gabee73ad227ba4587d3db12ef9bd582bc"></a>
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname"><a class="el" href="group__CMSIS__RTOS__Definitions.html#ga6c0dbe6069e4e7f47bb4cd32ae2b813e">osStatus_t</a> osMutexDelete </td>
          <td>(</td>
          <td class="paramtype"><a class="el" href="group__CMSIS__RTOS__MutexMgmt.html#ga313801836c62deb23055efb55a420e42">osMutexId_t</a>&#160;</td>
          <td class="paramname"><em>mutex_id</em></td><td>)</td>
          <td></td>
        </tr>
      </table>
</div><div class="memdoc">
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramdir">[in]</td><td class="paramname">mutex_id</td><td>mutex ID obtained by <a class="el" href="group__CMSIS__RTOS__MutexMgmt.html#gab90920022ab944296821368ef6bb52f8">osMutexNew</a>. </td></tr>
  </table>
  </dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>status code that indicates the execution status of the function.</dd></dl>
<p>The function <b>osMutexDelete</b> deletes a mutex object specified by parameter <em>mutex_id</em>. It releases internal memory obtained for mutex handling. After this call, the <em>mutex_id</em> is no longer valid and cannot be used. The mutex may be created again using the function <a class="el" href="group__CMSIS__RTOS__MutexMgmt.html#gab90920022ab944296821368ef6bb52f8">osMutexNew</a>.</p>
<p>Possible <a class="el" href="group__CMSIS__RTOS__Definitions.html#ga6c0dbe6069e4e7f47bb4cd32ae2b813e">osStatus_t</a> return values:</p>
<ul>
<li><em>osOK:</em> the mutex object has been deleted.</li>
<li><em>osErrorParameter:</em> parameter <em>mutex_id</em> is <span class="XML-Token">NULL</span> or invalid.</li>
<li><em>osErrorResource:</em> the mutex specified by parameter <em>mutex_id</em> is in an invalid mutex state.</li>
<li><em>osErrorISR:</em> <b>osMutexDelete</b> cannot be called from interrupt service routines.</li>
</ul>
<dl class="section note"><dt>Note</dt><dd>This function <b>cannot</b> be called from <a class="el" href="theory_of_operation.html#CMSIS_RTOS_ISR_Calls">Interrupt Service Routines</a>.</dd></dl>
<p><b>Code Example</b> </p>
<div class="fragment"><div class="line"><span class="preprocessor">#include &quot;<a class="code" href="cmsis__os2_8h.html">cmsis_os2.h</a>&quot;</span></div>
<div class="line">  </div>
<div class="line"><a class="code" href="group__CMSIS__RTOS__MutexMgmt.html#ga313801836c62deb23055efb55a420e42">osMutexId_t</a> mutex_id;                            <span class="comment">// Mutex id populated by the function osMutexNew()</span></div>
<div class="line"> </div>
<div class="line"><span class="keywordtype">void</span> DeleteMutex (<a class="code" href="group__CMSIS__RTOS__MutexMgmt.html#ga313801836c62deb23055efb55a420e42">osMutexId_t</a> mutex_id)  {</div>
<div class="line"><a class="code" href="group__CMSIS__RTOS__Definitions.html#ga6c0dbe6069e4e7f47bb4cd32ae2b813e">osStatus_t</a> status;</div>
<div class="line">  </div>
<div class="line">  <span class="keywordflow">if</span> (mutex_id != NULL)  {</div>
<div class="line">    status = <a class="code" href="group__CMSIS__RTOS__MutexMgmt.html#gabee73ad227ba4587d3db12ef9bd582bc">osMutexDelete</a>(mutex_id);</div>
<div class="line">    <span class="keywordflow">if</span> (status != <a class="code" href="cmsis__os2_8h.html#ga6c0dbe6069e4e7f47bb4cd32ae2b813ea9e1c9e2550bb4de8969a935acffc968f">osOK</a>)  {</div>
<div class="line">      <span class="comment">// handle failure code</span></div>
<div class="line">    }</div>
<div class="line">  }</div>
<div class="line">}</div>
</div><!-- fragment --> 
</div>
</div>
</div><!-- contents -->
</div><!-- doc-content -->
<!-- start footer part -->
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
  <ul>
    <li class="footer">Generated on Wed Feb 8 2017 10:21:04 for CMSIS-RTOS2 by ARM Ltd. All rights reserved.
	<!--
    <a href="http://www.doxygen.org/index.html">
    <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.8.6 
	-->
	</li>
  </ul>
</div>
</body>
</html>