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 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
|
<!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: cond_var.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 Page</span></a></li>
<li><a href="pages.html"><span>Related Pages</span></a></li>
<li><a href="modules.html"><span>Modules</span></a></li>
<li><a href="annotated.html"><span>Data 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> <u>S</u>earch for </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>cond_var.c</h1><div class="fragment"><pre class="fragment"><span class="preprocessor">#include <<a class="code" href="include_2native_2mutex_8h.html" title="This file is part of the Xenomai project.">native/mutex.h</a>></span>
<span class="preprocessor">#include <<a class="code" href="include_2native_2cond_8h.html" title="This file is part of the Xenomai project.">native/cond.h</a>></span>
RT_COND cond_desc;
RT_MUTEX mutex_desc;
<span class="keywordtype">int</span> shared_event = 0;
<span class="keywordtype">void</span> foo (<span class="keywordtype">void</span>)
{
<span class="keywordtype">int</span> err;
<span class="comment">/* Create a condition variable and a mutex guarding it; we could</span>
<span class="comment"> also have attempted to bind to some pre-existing objects, using</span>
<span class="comment"> rt_cond_bind() and rt_mutex_bind() instead of creating them. */</span>
err = <a name="a0"></a><a class="code" href="group__mutex.html#gc89c13a781e4636acf9e66f02d9feb83" title="Create a mutex.">rt_mutex_create</a>(&mutex_desc,<span class="stringliteral">"MyCondMutex"</span>);
err = <a name="a1"></a><a class="code" href="group__cond.html#g04646a121e57765848eb2a51ed6be855" title="Create a condition variable.">rt_cond_create</a>(&cond_desc,<span class="stringliteral">"MyCondVar"</span>);
<span class="comment">/* Now, wait for some task to post the shared event... */</span>
<a name="a2"></a><a class="code" href="group__mutex.html#g8a087d5bfeaaf10b6f0a924b272d72c9" title="Acquire a mutex.">rt_mutex_acquire</a>(&mutex_desc,TM_INFINITE);
<span class="keywordflow">while</span> (!shared_event && !err)
err = <a name="a3"></a><a class="code" href="group__cond.html#g3aa51073817be2ffb2a880a7393502e8" title="Wait on a condition.">rt_cond_wait</a>(&cond_desc,&mutex_desc,TM_INFINITE);
<a name="a4"></a><a class="code" href="group__mutex.html#gc87911b7279f55ef2f5f9aefe36ff070" title="Unlock mutex.">rt_mutex_release</a>(&mutex_desc);
<span class="comment">/* ... */</span>
}
<span class="keywordtype">void</span> bar (<span class="keywordtype">void</span>)
{
<span class="comment">/* ... */</span>
<span class="comment">/* Post the shared event. */</span>
<a class="code" href="group__mutex.html#g8a087d5bfeaaf10b6f0a924b272d72c9" title="Acquire a mutex.">rt_mutex_acquire</a>(&mutex_desc,TM_INFINITE);
shared_event = 1;
<a name="a5"></a><a class="code" href="group__cond.html#gb7a59ee47db48a78ca45e4655b569dc9" title="Signal a condition variable.">rt_cond_signal</a>(&cond_desc);
<a class="code" href="group__mutex.html#gc87911b7279f55ef2f5f9aefe36ff070" title="Unlock mutex.">rt_mutex_release</a>(&mutex_desc);
<span class="comment">/* ... */</span>
}
<span class="keywordtype">void</span> cleanup (<span class="keywordtype">void</span>)
{
<a name="a6"></a><a class="code" href="group__cond.html#gba59b188f10b142b4f2500dd719aa35f" title="Delete a condition variable.">rt_cond_delete</a>(&cond_desc);
<a name="a7"></a><a class="code" href="group__mutex.html#gd0c2342227f821bd09f580b6a9684179" title="Delete a mutex.">rt_mutex_delete</a>(&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
<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>
|