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

📄 kernel-thread-info.html

📁 有关ecos2。0介绍了实时嵌入式的结构以及线程调度的实现和内存的管理等
💻 HTML
字号:
<!-- Copyright (C) 2003 Red Hat, Inc.                                --><!-- This material may be distributed only subject to the terms      --><!-- and conditions set forth in the Open Publication License, v1.0  --><!-- or later (the latest version is presently available at          --><!-- http://www.opencontent.org/openpub/).                           --><!-- Distribution of the work or derivative of the work in any       --><!-- standard (paper) book form is prohibited unless prior           --><!-- permission is obtained from the copyright holder.               --><HTML><HEAD><TITLE>Thread information</TITLE><meta name="MSSmartTagsPreventParsing" content="TRUE"><METANAME="GENERATOR"CONTENT="Modular DocBook HTML Stylesheet Version 1.76b+"><LINKREL="HOME"TITLE="eCos Reference Manual"HREF="ecos-ref.html"><LINKREL="UP"TITLE="The eCos Kernel"HREF="kernel.html"><LINKREL="PREVIOUS"TITLE="Thread creation"HREF="kernel-thread-create.html"><LINKREL="NEXT"TITLE="Thread control"HREF="kernel-thread-control.html"></HEAD><BODYCLASS="REFENTRY"BGCOLOR="#FFFFFF"TEXT="#000000"LINK="#0000FF"VLINK="#840084"ALINK="#0000FF"><DIVCLASS="NAVHEADER"><TABLESUMMARY="Header navigation table"WIDTH="100%"BORDER="0"CELLPADDING="0"CELLSPACING="0"><TR><THCOLSPAN="3"ALIGN="center">eCos Reference Manual</TH></TR><TR><TDWIDTH="10%"ALIGN="left"VALIGN="bottom"><AHREF="kernel-thread-create.html"ACCESSKEY="P">Prev</A></TD><TDWIDTH="80%"ALIGN="center"VALIGN="bottom"></TD><TDWIDTH="10%"ALIGN="right"VALIGN="bottom"><AHREF="kernel-thread-control.html"ACCESSKEY="N">Next</A></TD></TR></TABLE><HRALIGN="LEFT"WIDTH="100%"></DIV><H1><ANAME="KERNEL-THREAD-INFO">Thread information</H1><DIVCLASS="REFNAMEDIV"><ANAME="AEN356"></A><H2>Name</H2>cyg_thread_self, cyg_thread_idle_thread, cyg_thread_get_stack_base, cyg_thread_get_stack_size, cyg_thread_measure_stack_usage, cyg_thread_get_next, cyg_thread_get_info, cyg_thread_find&nbsp;--&nbsp;Get basic thread information</DIV><DIVCLASS="REFSYNOPSISDIV"><ANAME="AEN366"><H2>Synopsis</H2><DIVCLASS="FUNCSYNOPSIS"><ANAME="AEN367"><P></P><TABLEBORDER="5"BGCOLOR="#E0E0F0"WIDTH="70%"><TR><TD><PRECLASS="FUNCSYNOPSISINFO">#include &lt;cyg/kernel/kapi.h&gt;    	</PRE></TD></TR></TABLE><P><CODE><CODECLASS="FUNCDEF">cyg_handle_t cyg_thread_self</CODE>(void);</CODE></P><P><CODE><CODECLASS="FUNCDEF">cyg_handle_t cyg_thread_idle_thread</CODE>(void);</CODE></P><P><CODE><CODECLASS="FUNCDEF">cyg_addrword_t cyg_thread_get_stack_base</CODE>(cyg_handle_t thread);</CODE></P><P><CODE><CODECLASS="FUNCDEF">cyg_uint32 cyg_thread_get_stack_size</CODE>(cyg_handle_t thread);</CODE></P><P><CODE><CODECLASS="FUNCDEF">cyg_uint32 cyg_thread_measure_stack_usage</CODE>(cyg_handle_t thread);</CODE></P><P><CODE><CODECLASS="FUNCDEF">cyg_bool cyg_thread_get_next</CODE>(cyg_handle_t *thread, cyg_uint16 *id);</CODE></P><P><CODE><CODECLASS="FUNCDEF">cyg_bool cyg_thread_get_info</CODE>(cyg_handle_t thread, cyg_uint16 id, cyg_thread_info *info);</CODE></P><P><CODE><CODECLASS="FUNCDEF">cyg_handle_t cyg_thread_find</CODE>(cyg_uint16 id);</CODE></P><P></P></DIV></DIV><DIVCLASS="REFSECT1"><ANAME="KERNEL-THREAD-INFO-DESCRIPTION"></A><H2>Description</H2><P>These functions can be used to obtain some basic information aboutvarious threads in the system. Typically they serve little or nopurpose in real applications, but they can be useful during debugging.      </P><P><TTCLASS="FUNCTION">cyg_thread_self</TT> returns a handle correspondingto the current thread. It will be the same as the value filled in by<TTCLASS="FUNCTION">cyg_thread_create</TT> when the current thread wascreated. This handle can then be passed to other functions such as<TTCLASS="FUNCTION">cyg_thread_get_priority</TT>.      </P><P><TTCLASS="FUNCTION">cyg_thread_idle_thread</TT> returns the handlecorresponding to the idle thread. This thread is created automaticallyby the kernel, so application-code has no other way of getting hold ofthis information.      </P><P><TTCLASS="FUNCTION">cyg_thread_get_stack_base</TT> and<TTCLASS="FUNCTION">cyg_thread_get_stack_size</TT> return informationabout a specific thread's stack. The values returned will match thevalues passed to <TTCLASS="FUNCTION">cyg_thread_create</TT> when thisthread was created.      </P><P><TTCLASS="FUNCTION">cyg_thread_measure_stack_usage</TT> is only availableif the configuration option<TTCLASS="VARNAME">CYGFUN_KERNEL_THREADS_STACK_MEASUREMENT</TT> is enabled.The return value is the maximum number of bytes of stack space used sofar by the specified thread. Note that this should not be considered atrue upper bound, for example it is possible that in the current testrun the specified thread has not yet been interrupted at the deepestpoint in the function call graph. Never the less the value returnedcan give some useful indication of the thread's stack requirements.      </P><P><TTCLASS="FUNCTION">cyg_thread_get_next</TT> is used to enumerate all thecurrent threads in the system. It should be called initially with thelocations pointed to by <TTCLASS="PARAMETER"><I>thread</I></TT> and<TTCLASS="PARAMETER"><I>id</I></TT> set to zero. On return these will be set tothe handle and ID of the first thread. On subsequent calls, theseparameters should be left set to the values returned by the previouscall.  The handle and ID of the next thread in the system will beinstalled each time, until a <TTCLASS="LITERAL">false</TT> return valueindicates the end of the list.      </P><P><TTCLASS="FUNCTION">cyg_thread_get_info</TT> fills in the<SPANCLASS="TYPE">cyg_thread_info</SPAN> structure with information about thethread described by the <TTCLASS="PARAMETER"><I>thread</I></TT> and<TTCLASS="PARAMETER"><I>id</I></TT> arguments. The information returned includesthe thread's handle and id, its state and name, priorities and stackparameters. If the thread does not exist the function returns<TTCLASS="LITERAL">false</TT>.    </P><P>The <SPANCLASS="TYPE">cyg_thread_info</SPAN> structure is defined as follows by&lt;<TTCLASS="FILENAME">cyg/kernel/kapi.h</TT>&gt;, but maybe extended in future with additional members, and so its size shouldnot be relied upon:<TABLEBORDER="5"BGCOLOR="#E0E0F0"WIDTH="70%"><TR><TD><PRECLASS="PROGRAMLISTING">typedef struct{    <SPANCLASS="TYPE">cyg_handle_t</SPAN>        <TTCLASS="STRUCTFIELD"><I>handle</I></TT>;    <SPANCLASS="TYPE">cyg_uint16</SPAN>          <TTCLASS="STRUCTFIELD"><I>id</I></TT>;    <SPANCLASS="TYPE">cyg_uint32</SPAN>          <TTCLASS="STRUCTFIELD"><I>state</I></TT>;    <SPANCLASS="TYPE">char</SPAN>                <TTCLASS="STRUCTFIELD"><I>*name</I></TT>;    <SPANCLASS="TYPE">cyg_priority_t</SPAN>      <TTCLASS="STRUCTFIELD"><I>set_pri</I></TT>;    <SPANCLASS="TYPE">cyg_priority_t</SPAN>      <TTCLASS="STRUCTFIELD"><I>cur_pri</I></TT>;    <SPANCLASS="TYPE">cyg_addrword_t</SPAN>      <TTCLASS="STRUCTFIELD"><I>stack_base</I></TT>;    <SPANCLASS="TYPE">cyg_uint32</SPAN>          <TTCLASS="STRUCTFIELD"><I>stack_size</I></TT>;    <SPANCLASS="TYPE">cyg_uint32</SPAN>          <TTCLASS="STRUCTFIELD"><I>stack_used</I></TT>;} cyg_thread_info;</PRE></TD></TR></TABLE>    </P><P><TTCLASS="FUNCTION">cyg_thread_find</TT> returns a handle for the threadwhose ID is <TTCLASS="PARAMETER"><I>id</I></TT>. If no such thread exists, azero handle is returned.    </P></DIV><DIVCLASS="REFSECT1"><ANAME="KERNEL-THREAD-INFO-CONTEXT"></A><H2>Valid contexts</H2><P><TTCLASS="FUNCTION">cyg_thread_self</TT> may only be called from threadcontext. <TTCLASS="FUNCTION">cyg_thread_idle_thread</TT> may be calledfrom thread or DSR context, but only after the system has beeninitialized. <TTCLASS="FUNCTION">cyg_thread_get_stack_base</TT>,<TTCLASS="FUNCTION">cyg_thread_get_stack_size</TT> and<TTCLASS="FUNCTION">cyg_thread_measure_stack_usage</TT> may be calledany time after the specified thread has been created, but measuringstack usage involves looping over at least part of the thread's stackso this should normally only be done from thread context.      </P></DIV><DIVCLASS="REFSECT1"><ANAME="KERNEL-THREAD-INFO-EXAMPLES"></A><H2>Examples</H2><P>A simple example of the use of the<TTCLASS="FUNCTION">cyg_thread_get_next</TT> and<TTCLASS="FUNCTION">cyg_thread_get_info</TT> follows:            </P><TABLEBORDER="5"BGCOLOR="#E0E0F0"WIDTH="70%"><TR><TD><PRECLASS="PROGRAMLISTING">&#13;#include &lt;cyg/kernel/kapi.h&gt;#include &lt;stdio.h&gt;void show_threads(void){    cyg_handle_t thread = 0;    cyg_uint16 id = 0;    while( cyg_thread_get_next( &amp;thread, &amp;id ) )    {        cyg_thread_info info;        if( !cyg_thread_get_info( thread, id, &amp;info ) )            break;        printf("ID: %04x name: %10s pri: %d\n",                info.id, info.name?info.name:"----", info.set_pri );    }}      </PRE></TD></TR></TABLE></DIV><DIVCLASS="NAVFOOTER"><HRALIGN="LEFT"WIDTH="100%"><TABLESUMMARY="Footer navigation table"WIDTH="100%"BORDER="0"CELLPADDING="0"CELLSPACING="0"><TR><TDWIDTH="33%"ALIGN="left"VALIGN="top"><AHREF="kernel-thread-create.html"ACCESSKEY="P">Prev</A></TD><TDWIDTH="34%"ALIGN="center"VALIGN="top"><AHREF="ecos-ref.html"ACCESSKEY="H">Home</A></TD><TDWIDTH="33%"ALIGN="right"VALIGN="top"><AHREF="kernel-thread-control.html"ACCESSKEY="N">Next</A></TD></TR><TR><TDWIDTH="33%"ALIGN="left"VALIGN="top">Thread creation</TD><TDWIDTH="34%"ALIGN="center"VALIGN="top"><AHREF="kernel.html"ACCESSKEY="U">Up</A></TD><TDWIDTH="33%"ALIGN="right"VALIGN="top">Thread control</TD></TR></TABLE></DIV></BODY></HTML>

⌨️ 快捷键说明

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