⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cml__threads_8h-source.html

📁 美国COPLEY驱动器,程序开发工具之一.
💻 HTML
📖 第 1 页 / 共 2 页
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1"><title>Copley Motion Library: CML_Threads.h Source File</title><link href="doxygen.css" rel="stylesheet" type="text/css"></head><body><!-- Generated by Doxygen 1.4.4 --><div class="qindex"><a class="qindex" href="main.html">Main&nbsp;Page</a> | <a class="qindex" href="hierarchy.html">Class&nbsp;Hierarchy</a> | <a class="qindex" href="classes.html">Alphabetical&nbsp;List</a> | <a class="qindex" href="annotated.html">Class&nbsp;List</a> | <a class="qindex" href="dirs.html">Directories</a> | <a class="qindex" href="files.html">File&nbsp;List</a> | <a class="qindex" href="functions.html">Class&nbsp;Members</a> | <a class="qindex" href="globals.html">File&nbsp;Members</a></div><div class="nav"><a class="el" href="dir_000001.html">inc</a></div><h1>CML_Threads.h</h1><a href="CML__Threads_8h.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/************************************************************/</span><a name="l00002"></a>00002 <span class="comment">/*                                                          */</span><a name="l00003"></a>00003 <span class="comment">/*  Copley Motion Libraries                                 */</span><a name="l00004"></a>00004 <span class="comment">/*                                                          */</span><a name="l00005"></a>00005 <span class="comment">/*  Author: Stephen Glow                                    */</span><a name="l00006"></a>00006 <span class="comment">/*                                                          */</span><a name="l00007"></a>00007 <span class="comment">/*  Copyright (c) 2002-2005 Copley Controls Corp.           */</span><a name="l00008"></a>00008 <span class="comment">/*                          http://www.copleycontrols.com   */</span><a name="l00009"></a>00009 <span class="comment">/*                                                          */</span><a name="l00010"></a>00010 <span class="comment">/************************************************************/</span><a name="l00011"></a>00011 <span class="comment"></span><a name="l00012"></a>00012 <span class="comment">/** \file</span><a name="l00013"></a>00013 <span class="comment">The classes defined in this file provide an operating system independent</span><a name="l00014"></a>00014 <span class="comment">way of accessing multi-tasking system features.</span><a name="l00015"></a>00015 <span class="comment"></span><a name="l00016"></a>00016 <span class="comment">The implementation of these classes will be different for different</span><a name="l00017"></a>00017 <span class="comment">supported platforms.</span><a name="l00018"></a>00018 <span class="comment">*/</span><a name="l00019"></a>00019 <a name="l00020"></a>00020 <a name="l00021"></a>00021 <span class="preprocessor">#ifndef _DEF_INC_MULTITHREAD</span><a name="l00022"></a>00022 <span class="preprocessor"></span><span class="preprocessor">#define _DEF_INC_MULTITHREAD</span><a name="l00023"></a>00023 <span class="preprocessor"></span><a name="l00024"></a>00024 <span class="preprocessor">#include "<a class="code" href="CML__Settings_8h.html">CML_Settings.h</a>"</span><a name="l00025"></a>00025 <span class="preprocessor">#include "<a class="code" href="CML__Error_8h.html">CML_Error.h</a>"</span><a name="l00026"></a>00026 <a name="l00027"></a>00027 <a class="code" href="CML__Settings_8h.html#a11">CML_NAMESPACE_START</a>()<a name="l00028"></a>00028 <a name="l00029"></a>00029 <span class="comment">/***************************************************************************/</span><span class="comment"></span><a name="l00030"></a>00030 <span class="comment">/**</span><a name="l00031"></a>00031 <span class="comment">Errors related to the multi-threaded libraries.</span><a name="l00032"></a>00032 <span class="comment">*/</span><a name="l00033"></a>00033 <span class="comment">/***************************************************************************/</span><a name="l00034"></a><a class="code" href="classThreadError.html">00034</a> class <a class="code" href="classThreadError.html">ThreadError</a>: public <a class="code" href="classError.html">Error</a><a name="l00035"></a>00035 {<a name="l00036"></a>00036 <span class="keyword">public</span>:<span class="comment"></span><a name="l00037"></a>00037 <span class="comment">   /// Error starting the thread</span><a name="l00038"></a><a class="code" href="classThreadError.html#s0">00038</a> <span class="comment"></span>   <span class="keyword">static</span> <span class="keyword">const</span> <a class="code" href="classThreadError.html">ThreadError</a> Start;<a name="l00039"></a>00039 <span class="comment"></span><a name="l00040"></a>00040 <span class="comment">   /// Thread has already been started</span><a name="l00041"></a><a class="code" href="classThreadError.html#s1">00041</a> <span class="comment"></span>   <span class="keyword">static</span> <span class="keyword">const</span> <a class="code" href="classThreadError.html">ThreadError</a> Running;<a name="l00042"></a>00042 <span class="comment"></span><a name="l00043"></a>00043 <span class="comment">   /// Timeout waiting on semaphore</span><a name="l00044"></a><a class="code" href="classThreadError.html#s2">00044</a> <span class="comment"></span>   <span class="keyword">static</span> <span class="keyword">const</span> <a class="code" href="classThreadError.html">ThreadError</a> Timeout;   <a name="l00045"></a>00045 <span class="comment"></span><a name="l00046"></a>00046 <span class="comment">   /// General failure</span><a name="l00047"></a><a class="code" href="classThreadError.html#s3">00047</a> <span class="comment"></span>   <span class="keyword">static</span> <span class="keyword">const</span> <a class="code" href="classThreadError.html">ThreadError</a> General;   <a name="l00048"></a>00048 <span class="comment"></span><a name="l00049"></a>00049 <span class="comment">   /// Bad parameter passed to a thread function</span><a name="l00050"></a><a class="code" href="classThreadError.html#s4">00050</a> <span class="comment"></span>   <span class="keyword">static</span> <span class="keyword">const</span> <a class="code" href="classThreadError.html">ThreadError</a> BadParam;<a name="l00051"></a>00051 <span class="comment"></span><a name="l00052"></a>00052 <span class="comment">   /// Error allocating memory for thread data</span><a name="l00053"></a><a class="code" href="classThreadError.html#s5">00053</a> <span class="comment"></span>   <span class="keyword">static</span> <span class="keyword">const</span> <a class="code" href="classThreadError.html">ThreadError</a> Alloc;<a name="l00054"></a>00054 <a name="l00055"></a>00055 <span class="keyword">protected</span>:<a name="l00056"></a><a class="code" href="classThreadError.html#b0">00056</a>    <a class="code" href="classThreadError.html">ThreadError</a>( <a class="code" href="CML__Utils_8h.html#a8">uint16</a> <span class="keywordtype">id</span>, <span class="keyword">const</span> <span class="keywordtype">char</span> *desc ): Error( id, desc ){}<a name="l00057"></a>00057 };<a name="l00058"></a>00058 <a name="l00059"></a>00059 <a name="l00060"></a>00060 <span class="comment">/***************************************************************************/</span><span class="comment"></span><a name="l00061"></a>00061 <span class="comment">/**</span><a name="l00062"></a>00062 <span class="comment">Virtual class which provides multi-tasking.  To add a new thread to a program,</span><a name="l00063"></a>00063 <span class="comment">create a new class that is derived from Thread.  The new thread of execution</span><a name="l00064"></a>00064 <span class="comment">will start when the start() member function is called.  This new thread of </span><a name="l00065"></a>00065 <span class="comment">execution will start with the run() member function and will run concurrently</span><a name="l00066"></a>00066 <span class="comment">with the rest of the system.  When (if) the run method returns, the new thread</span><a name="l00067"></a>00067 <span class="comment">will be terminated.</span><a name="l00068"></a>00068 <span class="comment">*/</span><a name="l00069"></a>00069 <span class="comment">/***************************************************************************/</span><a name="l00070"></a><a class="code" href="classThread.html">00070</a> <span class="keyword">class </span><a class="code" href="classThread.html">Thread</a><a name="l00071"></a>00071 {<a name="l00072"></a>00072 <span class="keyword">public</span>:<span class="comment"></span><a name="l00073"></a>00073 <span class="comment">   /// Create a new thread.  The new thread will not start executing</span><a name="l00074"></a>00074 <span class="comment">   /// until the start member function of this class is called.</span><a name="l00075"></a>00075 <span class="comment">   /// The default thread priority will be set to 5.</span><a name="l00076"></a>00076 <span class="comment"></span>   <a class="code" href="classThread.html#a0">Thread</a>( <span class="keywordtype">void</span> );<a name="l00077"></a>00077 <span class="comment"></span><a name="l00078"></a>00078 <span class="comment">   /// Clean up any allocated resources</span><a name="l00079"></a>00079 <span class="comment"></span>   <span class="keyword">virtual</span> <a class="code" href="classThread.html#a1">~Thread</a>();<a name="l00080"></a>00080 <span class="comment"></span><a name="l00081"></a>00081 <span class="comment">   /// Set the thread priority.  This function should be called before</span><a name="l00082"></a>00082 <span class="comment">   /// the thread is started if the default priority (5) is not acceptable.</span><a name="l00083"></a>00083 <span class="comment">   /// @param pri The priority for this thread to run at.  The range is</span><a name="l00084"></a>00084 <span class="comment">   ///            0 to 9 where 0 is a very low priority task, and 9 is a </span><a name="l00085"></a>00085 <span class="comment">   ///            critically high priority.</span><a name="l00086"></a>00086 <span class="comment">   /// @return An error object is returned indicating the success of the call.</span><a name="l00087"></a>00087 <span class="comment"></span>   <span class="keyword">const</span> <a class="code" href="classError.html">Error</a> *<a class="code" href="classThread.html#a2">setPriority</a>( <span class="keywordtype">int</span> pri );<a name="l00088"></a>00088 <span class="comment"></span><a name="l00089"></a>00089 <span class="comment">   /// Make this thread eligible to run.  The new thread will be created</span><a name="l00090"></a>00090 <span class="comment">   /// if possible and identified to the operating system as eligible to run.</span><a name="l00091"></a>00091 <span class="comment">   /// When the thread actually starts, the run() method will be called.</span><a name="l00092"></a>00092 <span class="comment">   /// Note that depending on the priority of the thread and of the calling </span><a name="l00093"></a>00093 <span class="comment">   /// task, the run() function may or may not be called before start() returns.</span><a name="l00094"></a>00094 <span class="comment">   /// @return An error object is returned indicating the success of the call.</span><a name="l00095"></a>00095 <span class="comment"></span>   <span class="keyword">const</span> <a class="code" href="classError.html">Error</a> *<a class="code" href="classThread.html#a3">start</a>( <span class="keywordtype">void</span> );<a name="l00096"></a>00096 <span class="comment"></span><a name="l00097"></a>00097 <span class="comment">   /// Stop this thread.  The thread will have exited by the time this function</span><a name="l00098"></a>00098 <span class="comment">   /// returns.  If the calling thread is the thread being stopped, then this</span><a name="l00099"></a>00099 <span class="comment">   /// function will not return.</span><a name="l00100"></a>00100 <span class="comment">   /// @param timeout The amount of time to wait (milliseconds) for the thread</span><a name="l00101"></a>00101 <span class="comment">   ///        to stop before returning an error.</span><a name="l00102"></a>00102 <span class="comment">   /// @return An error object is returned indicating the success of the call.</span><a name="l00103"></a>00103 <span class="comment"></span>   <span class="keyword">const</span> <a class="code" href="classError.html">Error</a> *<a class="code" href="classThread.html#a4">stop</a>( <a class="code" href="CML__Utils_8h.html#a9">int32</a> timeout=1000 );<a name="l00104"></a>00104 <span class="comment"></span><a name="l00105"></a>00105 <span class="comment">   /// Cause the calling thread to sleep for a specified number of milliseconds.</span><a name="l00106"></a>00106 <span class="comment">   /// @param timeout The time to sleep, in milliseconds.</span><a name="l00107"></a>00107 <span class="comment">   /// @return An error object is returned indicating the success of the call.</span><a name="l00108"></a>00108 <span class="comment"></span>   <span class="keyword">static</span> <span class="keyword">const</span> <a class="code" href="classError.html">Error</a> *<a class="code" href="classThread.html#e0">sleep</a>( <a class="code" href="CML__Utils_8h.html#a9">int32</a> timeout );<a name="l00109"></a>00109 <span class="comment"></span><a name="l00110"></a>00110 <span class="comment">   /// When a new thread is started, this function will be called.  All of the </span><a name="l00111"></a>00111 <span class="comment">   /// thread specific code should be contained in this function.  If the run()</span><a name="l00112"></a>00112 <span class="comment">   /// method ever returns, the thread will be destroyed.</span><a name="l00113"></a>00113 <span class="comment"></span>   <span class="keyword">virtual</span> <span class="keywordtype">void</span> <a class="code" href="classThread.html#a5">run</a>( <span class="keywordtype">void</span> ) = 0;<a name="l00114"></a>00114 <span class="keyword">private</span>:<a name="l00115"></a>00115 <span class="comment"></span><a name="l00116"></a>00116 <span class="comment">   /// Holds the threads priority.</span><a name="l00117"></a>00117 <span class="comment"></span>   <span class="keywordtype">int</span> priority;<a name="l00118"></a>00118 <span class="comment"></span><a name="l00119"></a>00119 <span class="comment">   /// Holds system specific data necessary to implement the thread object.</span><a name="l00120"></a>00120 <span class="comment"></span><span class="preprocessor">#ifdef CML_EXTRA_THREAD_DATA</span><a name="l00121"></a>00121 <span class="preprocessor"></span>   <a class="code" href="CML__Utils_8h.html#a2">byte</a> data[ CML_EXTRA_THREAD_DATA ];<a name="l00122"></a>00122 <span class="preprocessor">#else</span><a name="l00123"></a>00123 <span class="preprocessor"></span>   <span class="keywordtype">void</span> *data;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -