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 93 94 95 96 97 98 99 100 101 102 103
|
<!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: sigxcpu.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>sigxcpu.c</h1><div class="fragment"><pre class="fragment"><span class="preprocessor">#include <unistd.h></span>
<span class="preprocessor">#include <stdlib.h></span>
<span class="preprocessor">#include <stdio.h></span>
<span class="preprocessor">#include <string.h></span>
<span class="preprocessor">#include <signal.h></span>
<span class="preprocessor">#include <getopt.h></span>
<span class="preprocessor">#include <execinfo.h></span>
<span class="preprocessor">#include <<a class="code" href="task_8h.html" title="This file is part of the Xenomai project.">native/task.h</a>></span>
RT_TASK task;
<span class="keywordtype">void</span> task_body (<span class="keywordtype">void</span> *cookie)
{
<span class="comment">/* Ask Xenomai to warn us upon switches to secondary mode. */</span>
<a name="a0"></a><a class="code" href="group__task.html#g915e7edfb0aaddb643794d7abc7093bf" title="Change task mode bits.">rt_task_set_mode</a>(0, <a name="a1"></a><a class="code" href="group__native__task__status.html#g725324cb26d8b5835c0818acb738bfe6" title="See XNTRAPSW.">T_WARNSW</a>, NULL);
<span class="comment">/* A real-time task always starts in primary mode. */</span>
<span class="keywordflow">for</span> (;;) {
<a name="a2"></a><a class="code" href="group__task.html#gd5225e5fb8d583fbdfa5299f322b8366" title="Delay the calling task (relative).">rt_task_sleep</a>(1000000000);
<span class="comment">/* Running in primary mode... */</span>
printf(<span class="stringliteral">"Switched to secondary mode\n"</span>);
<span class="comment">/* ...printf() => write(2): we have just switched to secondary</span>
<span class="comment"> mode: SIGXCPU should have been sent to us by now. */</span>
}
}
<span class="keywordtype">void</span> warn_upon_switch(<span class="keywordtype">int</span> sig __attribute__((unused)))
{
<span class="keywordtype">void</span> *bt[32];
<span class="keywordtype">int</span> nentries;
<span class="comment">/* Dump a backtrace of the frame which caused the switch to</span>
<span class="comment"> secondary mode: */</span>
nentries = backtrace(bt,<span class="keyword">sizeof</span>(bt) / <span class="keyword">sizeof</span>(bt[0]));
backtrace_symbols_fd(bt,nentries,fileno(stdout));
}
<span class="keywordtype">int</span> main (<span class="keywordtype">int</span> argc, <span class="keywordtype">char</span> **argv)
{
<span class="keywordtype">int</span> err;
signal(SIGXCPU, warn_upon_switch);
err = <a name="a3"></a><a class="code" href="group__task.html#g03387550693c21d0223f739570ccd992" title="Create a new real-time task.">rt_task_create</a>(&task,<span class="stringliteral">"mytask"</span>,0,1,T_FPU);
<span class="keywordflow">if</span> (err)
{
fprintf(stderr,<span class="stringliteral">"failed to create task, code %d\n"</span>,err);
<span class="keywordflow">return</span> 0;
}
err = <a name="a4"></a><a class="code" href="group__task.html#gc9638918b8310a430088f5c9a04d2bb7" title="Start a real-time task.">rt_task_start</a>(&task,&task_body,NULL);
<span class="keywordflow">if</span> (err)
{
fprintf(stderr,<span class="stringliteral">"failed to start task, code %d\n"</span>,err);
<span class="keywordflow">return</span> 0;
}
pause();
<span class="keywordflow">return</span> 0;
}
</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>
|