File: mutex_8c-example.html

package info (click to toggle)
xenomai 2.5.4-3squeeze1
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 36,140 kB
  • ctags: 35,509
  • sloc: ansic: 109,084; sh: 11,745; makefile: 2,205; xml: 1,356; asm: 613; php: 316; perl: 155
file content (69 lines) | stat: -rw-r--r-- 3,378 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title>Xenomai API: mutex.c</title>
<link href="doxygen.css" rel="stylesheet" type="text/css">
<link href="tabs.css" rel="stylesheet" type="text/css">
</head><body>
<!-- Generated by Doxygen 1.5.6 -->
<div class="navigation" id="top">
  <div class="tabs">
    <ul>
      <li><a href="main.html"><span>Main&nbsp;Page</span></a></li>
      <li><a href="pages.html"><span>Related&nbsp;Pages</span></a></li>
      <li><a href="modules.html"><span>Modules</span></a></li>
      <li><a href="annotated.html"><span>Data&nbsp;Structures</span></a></li>
      <li><a href="files.html"><span>Files</span></a></li>
      <li><a href="examples.html"><span>Examples</span></a></li>
    <li>
      <form action="search.php" method="get">
        <table cellspacing="0" cellpadding="0" border="0">
          <tr>
            <td><label>&nbsp;<u>S</u>earch&nbsp;for&nbsp;</label></td>
            <td><input type="text" name="query" value="" size="20" accesskey="s"/></td>
          </tr>
        </table>
      </form>
    </li>
    </ul>
  </div>
</div>
<div class="contents">
<h1>mutex.c</h1><div class="fragment"><pre class="fragment"><span class="preprocessor">#include &lt;<a class="code" href="include_2native_2mutex_8h.html" title="This file is part of the Xenomai project.">native/mutex.h</a>&gt;</span>

RT_MUTEX mutex_desc;

<span class="keywordtype">int</span> main (<span class="keywordtype">int</span> argc, <span class="keywordtype">char</span> *argv[])

{
    <span class="keywordtype">int</span> err;

    <span class="comment">/* Create a mutex; we could also have attempted to bind to some</span>
<span class="comment">       pre-existing object, using rt_mutex_bind() and rt_mutex_bind()</span>
<span class="comment">       instead of creating it. In any case, priority inheritance is</span>
<span class="comment">       automatically enforced for mutual exclusion locks. */</span>

    err = <a name="a0"></a><a class="code" href="group__mutex.html#gc89c13a781e4636acf9e66f02d9feb83" title="Create a mutex.">rt_mutex_create</a>(&amp;mutex_desc,<span class="stringliteral">"MyMutex"</span>);

    <span class="comment">/* Now, grab the mutex lock, run the critical section, then</span>
<span class="comment">       release the lock: */</span>

    <a name="a1"></a><a class="code" href="group__mutex.html#g8a087d5bfeaaf10b6f0a924b272d72c9" title="Acquire a mutex.">rt_mutex_acquire</a>(&amp;mutex_desc,TM_INFINITE);

    <span class="comment">/* ... Critical section ... */</span>
    
    <a name="a2"></a><a class="code" href="group__mutex.html#gc87911b7279f55ef2f5f9aefe36ff070" title="Unlock mutex.">rt_mutex_release</a>(&amp;mutex_desc);

    <span class="comment">/* ... */</span>
}

<span class="keywordtype">void</span> cleanup (<span class="keywordtype">void</span>)

{
    <a name="a3"></a><a class="code" href="group__mutex.html#gd0c2342227f821bd09f580b6a9684179" title="Delete a mutex.">rt_mutex_delete</a>(&amp;mutex_desc);
}
</pre></div> </div>
<hr size="1"><address style="text-align: right;"><small>Generated on Mon Aug 2 12:48:36 2010 for Xenomai API by&nbsp;
<a href="http://www.doxygen.org/index.html">
<img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.5.6 </small></address>
</body>
</html>