Valid contexts, Examples – Comtrol eCos User Manual

Page 44

Advertising
background image

Thread information

handle and ID of the next thread in the system will be installed each time, until a

false

return value indicates the

end of the list.

cyg_thread_get_info

fills in the cyg_thread_info structure with information about the thread described by the

thread

and

id

arguments. The information returned includes the thread’s handle and id, its state and name,

priorities and stack parameters. If the thread does not exist the function returns

false

.

The cyg_thread_info structure is defined as follows by <

cyg/kernel/kapi.h

>, but may be extended in future

with additional members, and so its size should not be relied upon:

typedef struct

{

cyg_handle_t

handle;

cyg_uint16

id;

cyg_uint32

state;

char

*name;

cyg_priority_t

set_pri;

cyg_priority_t

cur_pri;

cyg_addrword_t

stack_base;

cyg_uint32

stack_size;

cyg_uint32

stack_used;

} cyg_thread_info;

cyg_thread_find

returns a handle for the thread whose ID is

id

. If no such thread exists, a zero handle is

returned.

Valid contexts

cyg_thread_self

may only be called from thread context.

cyg_thread_idle_thread

may be called from

thread or DSR context, but only after the system has been initialized.

cyg_thread_get_stack_base

,

cyg_thread_get_stack_size

and

cyg_thread_measure_stack_usage

may be called any time after the

specified thread has been created, but measuring stack usage involves looping over at least part of the thread’s
stack so this should normally only be done from thread context.

Examples

A simple example of the use of the

cyg_thread_get_next

and

cyg_thread_get_info

follows:

#include

<

cyg/kernel/kapi.h

>

#include

<

stdio.h

>

void show_threads(void)

{

cyg_handle_t thread = 0;

cyg_uint16 id = 0;

while( cyg_thread_get_next( &thread, &id ) )

{

cyg_thread_info info;

44

Advertising