Mercurial > nand-ecoscentric
diff packages/kernel/current/src/common/kapi.cxx @ 460:a65a4055f146
* src/common/kapi.cxx:
* include/kapi.h:
Added function cyg_thread_get_next(), cyg_thread_find() and
cyg_thread_get_info() to allow the current set of threads to be
enumerated, and per-thread information to be retrieved safely.
* doc/kernel.sgml: Documented new KAPI calls.
* src/common/thread.cxx: Zero unique_id in thread destructor so
that a stale thread pointer can be checked for validity.
* include/instrmnt.h:
Added cyg_instrument_state() to report the current state of an
instrumentation flag.
Moved ifdef for CYGDBG_KERNEL_INSTRUMENT_MSGS out of within FLAGS
ifdef. We can have messages without flags.
* src/instrmnt/meminst.cxx:
Added cyg_instrument_state() to report the current state of an
instrumentation flag.
Modified cyg_instrument_msg() in line with header and table
changes.
* host/instr/dump_instr.c:
* host/instr/instrument.sh:
* include/instrument_desc.h:
Added a final NULL element to the generated table in
instrument_desc.h to mark its end. Otherwise code that does not
have access to the table definition cannot find its end. Also
added ifdefs to allow instrument_desc.h to be used to acquire the
structure definition and table pointer.
| author | nickg |
|---|---|
| date | Thu, 12 Dec 2002 18:31:34 +0000 |
| parents | d2c90368aeef |
| children | bd1ddaaaf796 |
line wrap: on
line diff
--- a/packages/kernel/current/src/common/kapi.cxx +++ b/packages/kernel/current/src/common/kapi.cxx @@ -9,6 +9,7 @@ // ------------------------------------------- // This file is part of eCos, the Embedded Configurable Operating System. // Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc. +// Copyright (C) 2002 Nick Garnett // // eCos is free software; you can redistribute it and/or modify it under // the terms of the GNU General Public License as published by the Free @@ -309,6 +310,101 @@ externC cyg_uint32 cyg_thread_measure_st #endif /*---------------------------------------------------------------------------*/ +/* Thread enumeration and information */ + +#ifdef CYGVAR_KERNEL_THREADS_LIST + +cyg_bool_t cyg_thread_get_next( cyg_handle_t *current, cyg_uint16 *id ) +{ + cyg_bool_t result = true; + + Cyg_Scheduler::lock(); + + Cyg_Thread *thread = (Cyg_Thread *)*current; + + if( *current == 0 ) + { + thread = Cyg_Thread::get_list_head(); + *current = (cyg_handle_t)thread; + *id = thread->get_unique_id(); + } + else if( (thread->get_unique_id() == *id) && + (thread = thread->get_list_next()) != NULL ) + { + *current = (cyg_handle_t)thread; + *id = thread->get_unique_id(); + } + else + { + *current = 0; + *id = 0; + result = false; + } + + Cyg_Scheduler::unlock(); + + return result; +} + +cyg_handle_t cyg_thread_find( cyg_uint16 id ) +{ + Cyg_Scheduler::lock(); + + Cyg_Thread *thread = Cyg_Thread::get_list_head(); + + while( thread != NULL ) + { + if( thread->get_unique_id() == id ) + break; + + thread = thread->get_list_next(); + } + + Cyg_Scheduler::unlock(); + + return (cyg_handle_t)thread; +} + +#endif + +cyg_bool_t cyg_thread_get_info( cyg_handle_t threadh, + cyg_uint16 id, + cyg_thread_info *info ) +{ + cyg_bool_t result = true; + Cyg_Thread *thread = (Cyg_Thread *)threadh; + + Cyg_Scheduler::lock(); + + if( thread->get_unique_id() == id && info != NULL ) + { + info->handle = threadh; + info->id = id; + info->state = thread->get_state(); +#ifdef CYGVAR_KERNEL_THREADS_NAME + info->name = thread->get_name(); +#else + info->name = NULL; +#endif + info->set_pri = thread->get_priority(); + info->cur_pri = thread->get_current_priority(); + info->stack_base = thread->get_stack_base(); + info->stack_size = thread->get_stack_size(); + +#ifdef CYGFUN_KERNEL_THREADS_STACK_MEASUREMENT + info->stack_used = thread->measure_stack_usage(); +#else + info->stack_used = 0; +#endif + } + else result = false; + + Cyg_Scheduler::unlock(); + + return result; +} + +/*---------------------------------------------------------------------------*/ /* Per-thread data */ #ifdef CYGVAR_KERNEL_THREADS_DATA
