Main Page | Modules | Alphabetical List | Data Structures | Directories | File List | Data Fields | Globals | Related Pages | Examples

thread.c File Reference


Detailed Description

Multi-threading support.

This kernel module implements the platform independent part of the Nut/OS cooperative multi-threading.

 *
 * $Log: thread.c,v $
 * Revision 1.28  2006/09/29 12:24:14  haraldkipp
 * Stack allocation code moved from thread module to heap module.
 * All code should use dedicated stack allocation routines. For targets
 * allocating stack from the normal heap the API calls are remapped by
 * preprocessor macros.
 *
 * Revision 1.27  2006/06/28 14:39:41  haraldkipp
 * Event and timer handling re-design, again.
 *
 * Revision 1.26  2006/03/16 15:25:36  haraldkipp
 * Changed human readable strings from u_char to char to stop GCC 4 from
 * nagging about signedness.
 *
 * Revision 1.25  2006/03/02 23:57:54  hwmaier
 * Fixed bug NutStackHeap* functions. The availabe variable was not
 * taken into account.
 *
 * Revision 1.24  2006/02/08 15:20:56  haraldkipp
 * ATmega2561 Support
 *
 * Revision 1.23  2006/01/26 15:34:49  going_nuts
 * adapted to new interrupt handling scheme for unix emulation
 * now uses Unix timer and runs without interrupts unless you emulate other hardware
 *
 * Revision 1.22  2005/10/04 05:14:49  hwmaier
 * Added support for separating stack and conventional heap as required by AT09CAN128 MCUs
 *
 * Revision 1.21  2005/07/26 16:00:16  haraldkipp
 * Cygwin added.
 * Platform dependent part is now located in arch/(target)/context.c
 *
 * Revision 1.20  2005/07/14 08:57:54  freckle
 * Rewrote CS in NutThreadSetPriority
 *
 * Revision 1.19  2005/07/12 13:57:56  freckle
 * Fixed bug in thread not waking up on NutSleep
 *
 * Revision 1.18  2005/06/12 16:56:20  haraldkipp
 * Calls new function to process elapsed timers.
 *
 * Revision 1.17  2005/05/27 17:30:26  drsung
 * Platform dependant files were moved to /arch directory.
 *
 * Revision 1.16  2005/04/19 14:15:28  phblum
 * Moved trace macro to avoid jamming the buffer with yields that do not switch to another thread (e.g. idle thread does so all the time).
 *
 * Revision 1.15  2005/02/21 12:37:57  phblum
 * Removed tabs and added semicolons after NUTTRACER macros
 *
 * Revision 1.14  2005/02/21 00:53:57  hwmaier
 * Changes to incorporate support for AT90CAN128 CPU
 *
 * Revision 1.13  2005/02/17 14:44:39  phblum
 * Removed volatile declarations of runQueue since it is not touched from interrupt context. Same for nutThreadList, runningThread and killedThreads.
 * As runQueue is not modified by interrupts, runningThread == runQueue always. Therefore removed obsolete comparison in NutThreadYield().
 * Removed unnecessary critical section in NutThreadYield.
 * Put NutThreadSwitch call of NutThreadResume into critical section.
 *
 * Revision 1.12  2005/02/16 19:53:17  haraldkipp
 * Ready-to-run queue handling removed from interrupt context.
 *
 * Revision 1.11  2005/01/24 22:34:36  freckle
 * Added new tracer by Phlipp Blum <blum@tik.ee.ethz.ch>
 *
 * Revision 1.10  2005/01/02 10:07:10  haraldkipp
 * Replaced platform dependant formats in debug outputs.
 *
 * Revision 1.9  2004/08/05 12:13:57  freckle
 * Added unix emulation hook in NutThreadYield to safely process
 * NutPostEventAsync calls occuring in non Nut/OS threads.
 * Rewrote the unix read function again using the new unix NutThreadYield hook
 * to call the NutPostEventAsync function safely (fast & correct).
 * _write(nf, 0, 0) aka fflush is ignored on unix emulation.
 *
 * Revision 1.8  2004/04/07 12:13:58  haraldkipp
 * Matthias Ringwald's *nix emulation added
 *
 * Revision 1.7  2004/03/19 09:05:12  jdubiec
 * Fixed format strings declarations for AVR.
 *
 * Revision 1.6  2004/03/16 16:48:45  haraldkipp
 * Added Jan Dubiec's H8/300 port.
 *
 * Revision 1.5  2004/02/01 18:49:48  haraldkipp
 * Added CPU family support
 *
 * Revision 1.4  2003/12/15 19:31:46  haraldkipp
 * Ralph Mason's thread termination and reduced stack frame.
 *
 * Revision 1.3  2003/11/19 12:06:23  drsung
 * CR/LF issue corrected
 *
 * Revision 1.2  2003/11/18 22:18:40  drsung
 * thread name with 8 characters fixed.
 *
 * Revision 1.1.1.1  2003/05/09 14:41:54  haraldkipp
 * Initial using 3.2.1
 *
 * Revision 1.23  2003/05/06 18:56:24  harald
 * Avoid inlining with GCC optimizations
 *
 * Revision 1.22  2003/03/31 14:39:43  harald
 * *** empty log message ***
 *
 * Revision 1.21  2003/02/04 18:15:57  harald
 * Version 3 released
 *
 * Revision 1.20  2002/10/29 15:36:59  harald
 * New function retrieves thread by name
 *
 * Revision 1.19  2002/08/08 17:31:47  harald
 * Imagecraft support by Klaus Ummenhofer
 *
 * Revision 1.18  2002/07/03 16:45:42  harald
 * Using GCC 3.2
 *
 * Revision 1.17  2002/06/26 17:29:44  harald
 * First pre-release with 2.4 stack
 *
 * 


Functions

void NutThreadAddPriQueue (NUTTHREADINFO *td, NUTTHREADINFO *volatile *tqpp)
 Add a thread to a prioritiy ordered queue.
void NutThreadRemoveQueue (NUTTHREADINFO *td, NUTTHREADINFO *volatile *tqpp)
 Remove a thread from a specified queue.
void NutThreadResume (void)
 Continue with the highest priority thread, which is ready to run.
void NutThreadWake (HANDLE timer, HANDLE th)
 Resume a previously suspended thread.
void NutThreadYield (void)
 Give up the CPU.
u_char NutThreadSetPriority (u_char level)
 Set the current thread's priority.
void NutThreadExit (void)
 End the current thread.
void NutThreadDestroy (void)
 Free a thread that was previously killed and release memory back to the OS.
void NutThreadKill (void)
 Kill the running thread.
HANDLE GetThreadByName (char *name)
 Query handle of a thread with a specific name.

Variables

NUTTHREADINFOrunningThread
 Currently running thread.
NUTTHREADINFOkilledThread
 Thread to be killed.
NUTTHREADINFOnutThreadList
 List of all created threads.
NUTTHREADINFOrunQueue
 List of ready-to-run threads.


© 2000-2006 by egnite Software GmbH - visit http://www.ethernut.de/