Nut/OS  4.10.3
API Reference
thread.h File Reference

Thread management definitions. More...

#include <compiler.h>
#include <sys/types.h>
#include <cfg/memory.h>
#include <stdint.h>
Include dependency graph for thread.h:

Go to the source code of this file.

Data Structures

 Thread information structure. More...


#define SLEEP_MODE_NONE   0xff
 Stack size factor.
 Stack size summand.
#define THREAD(threadfn, arg)
 Macro for thread entry definitions.




void NutThreadInit (void)
uint8_t NutThreadSetSleepMode (uint8_t mode)
 Sets the sleep mode to enter in Idle thread.
HANDLE NutThreadCreate (char *name, void(*fn)(void *), void *arg, size_t stackSize)
 Create a new thread.
uint8_t NutThreadSetPriority (uint8_t level)
 Set the current thread's priority.
void NutThreadKill (void)
 Kill the running thread.
void NutThreadDestroy (void)
 Free a thread that was previously killed and release memory back to the OS.
void NutThreadExit (void)
 End the current thread.
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.
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 NutThreadSwitch (void)
 Switch to another thread.
HANDLE GetThreadByName (char *name)
 Query handle of a thread with a specific name.
NUTTHREADINFONutThreadStackCheck (size_t minsiz)
size_t NutThreadStackAvailable (char *name)


 Currently running thread.
 List of all created threads.
 List of ready-to-run threads.

Thread States

#define TDS_TERM   0
#define TDS_RUNNING   1
#define TDS_READY   2
#define TDS_SLEEP   3

Detailed Description

Thread management definitions.

 * $Log$
 * Revision 1.23  2009/03/05 22:16:57  freckle
 * use __NUT_EMULATION instead of __APPLE__, __linux__, or __CYGWIN__
 * Revision 1.22  2009/02/06 15:37:40  haraldkipp
 * Added stack space multiplier and addend. Adjusted stack space.
 * Revision 1.21  2009/01/19 18:55:12  haraldkipp
 * Added stack checking code.
 * Revision 1.20  2009/01/17 11:26:51  haraldkipp
 * Getting rid of two remaining BSD types in favor of stdint.
 * Replaced 'u_int' by 'unsinged int' and 'uptr_t' by 'uintptr_t'.
 * Revision 1.19  2008/08/11 07:00:28  haraldkipp
 * BSD types replaced by stdint types (feature request #1282721).
 * Revision 1.18  2008/06/15 17:05:52  haraldkipp
 * Rolled back to version 1.16.
 * Revision 1.16  2007/06/14 07:24:38  freckle
 * Disable ADC and buskeeper during idle thread sleep, if IDLE_THREAD_ADC_OFF and IDLE_THREAD_BUSKEEPER_OFF are defined
 * Revision 1.15  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.14  2006/06/29 03:52:19  hwmaier
 * Added include statement for cfg/memory.h so the macro
 * NUTMEM_STACKHEAP is found when compiling for the
 * AT90CAN128.
 * Revision 1.13  2006/06/28 14:35:31  haraldkipp
 * Event/thread/timer re-design.
 * Code indention corrected.
 * Volatile attribute removed from THREADINFO link pointer.
 * Revision 1.12  2006/03/16 15:25:34  haraldkipp
 * Changed human readable strings from u_char to char to stop GCC 4 from
 * nagging about signedness.
 * Revision 1.11  2005/10/07 21:48:25  hwmaier
 * Using __AVR_ENHANCED__ macro instead of __AVR_ATmega128__ to support also AT90CAN128 MCU
 * Revision 1.10  2005/10/04 05:25:17  hwmaier
 * Added support for separating stack and conventional heap as required by AT09CAN128 MCUs
 * Revision 1.9  2005/08/02 17:46:49  haraldkipp
 * Major API documentation update.
 * Revision 1.8  2005/07/26 15:49:59  haraldkipp
 * Cygwin support added.
 * Revision 1.7  2005/02/17 14:42:37  phblum
 * Removed volatile declarations of runQueue since it is not touched from interrupt context. Same for nutThreadList, runningThread and killedThreads.
 * Revision 1.6  2005/02/16 19:53:15  haraldkipp
 * Ready-to-run queue handling removed from interrupt context.
 * Revision 1.5  2004/07/09 19:51:34  freckle
 * Added new function NutThreadSetSleepMode to tell nut/os to set the MCU
 * into sleep mode when idle (avr-gcc && avr128 only)
 * Revision 1.4  2004/04/07 12:13:57  haraldkipp
 * Matthias Ringwald's *nix emulation added
 * Revision 1.3  2004/03/16 16:48:44  haraldkipp
 * Added Jan Dubiec's H8/300 port.
 * Revision 1.2  2003/12/15 19:28:26  haraldkipp
 * Kill function prototypes
 * Revision  2003/05/09 14:41:22  haraldkipp
 * Initial using 3.2.1
 * Revision 1.14  2003/02/04 18:00:54  harald
 * Version 3 released
 * Revision 1.13  2002/10/29 15:40:50  harald
 * *** empty log message ***
 * Revision 1.12  2002/06/26 17:29:29  harald
 * First pre-release with 2.4 stack

Definition in file thread.h.

Define Documentation


Definition at line 153 of file thread.h.

Referenced by NutDumpThreadList(), NutDumpThreadQueue(), and NutThreadCreate().

#define TDS_TERM   0

Thread has exited.

Definition at line 198 of file thread.h.

#define TDS_RUNNING   1

Thread is running.

Definition at line 199 of file thread.h.

Referenced by NutSleep(), NutThreadCreate(), NutThreadResume(), NutThreadSetPriority(), and NutThreadSwitch().

#define TDS_READY   2

Thread is ready to run.

Definition at line 200 of file thread.h.

Referenced by NutEventPostAsync(), NutEventTimeout(), NutThreadCreate(), NutThreadResume(), NutThreadSetPriority(), and NutThreadWake().

#define TDS_SLEEP   3

Thread is sleeping.

Definition at line 201 of file thread.h.

Referenced by NutEventWait(), and NutSleep().

#define SLEEP_MODE_NONE   0xff

Definition at line 204 of file thread.h.

Referenced by NutIdle().


Stack size factor.

Configured stack sizes are multiplied with this value.

All stack size settings of internal Nut/OS threads had been calculated for size optimized code. Probably more stack space is required with other compiler settings.

For example, when GCC generates non-optimized code for source code debugging, a factor of 3 should be applied to all stack sizes.

Application code may also make use of this macro.

 #include <sys/thread.h>


 NutThreadCreate("myth", ThreadFunc, 0, MY_THREAD_STACK);


Definition at line 231 of file thread.h.

Referenced by AhdlcAt91Init(), AhdlcAvrInit(), DmInit(), EmacInit(), LancInit(), main(), NicInit(), NutIdle(), NutInit(), NutPppInitStateMachine(), NutRegisterDiscovery(), NutSNTPStartThread(), and NutTcpInitStateMachine().


Stack size summand.

The specified value will be added to all configured stack sizes.


Definition at line 242 of file thread.h.

Referenced by AhdlcAt91Init(), AhdlcAvrInit(), DmInit(), EmacInit(), LancInit(), main(), NicInit(), NutIdle(), NutInit(), NutPppInitStateMachine(), NutRegisterDiscovery(), NutSNTPStartThread(), and NutTcpInitStateMachine().

#define THREAD (   threadfn,
void threadfn(void *arg) __attribute__ ((noreturn)); \
void threadfn(void *arg)

Macro for thread entry definitions.

events/events.c, ftpd/ftpserv.c, httpd/httpserv.c, httpd_upnp/httpserv.c, icmp-udp/icmp-udp.c, portdio/portdio.c, rs232d/rs232d.c, threads/threads.c, and timers/timers.c.

Definition at line 283 of file thread.h.

Function Documentation

void NutThreadInit ( void  )
NUTTHREADINFO* NutThreadStackCheck ( size_t  minsiz)
size_t NutThreadStackAvailable ( char *  name)

Referenced by NutDumpThreadList().