Nut/OS  5.0.5
API Reference
Context Switching for Linux Emulation

Context Switching for the UNIX emulator. More...

Collaboration diagram for Context Switching for Linux Emulation:

Functions

void NutThreadInit (void)
 Initialize thread handling in the Linux emulation.
void NutThreadSwitch (void)
 Switch to another thread.
HANDLE NutThreadCreate (char *name, void(*fn)(void *), void *arg, size_t stackSize)
 Create a new thread.

Variables

pthread_attr_t attr
pthread_mutex_t thread_mutex
pthread_cond_t main_cv
uint16_t main_cs_level

Detailed Description

Context Switching for the UNIX emulator.


Function Documentation

void NutThreadInit ( void  )

Initialize thread handling in the Linux emulation.

Used in the Liux emulation only. Has to be initialized once.

References attr, main_cv, NULL, and thread_mutex.

Referenced by main().

void NutThreadSwitch ( void  )

Switch to another thread.

Stop the current thread, saving its context. Then start the one with the highest priority, which is ready to run.

Application programs typically do not call this function.

Note:
CPU interrupts must be disabled before calling this function.

References runningThread, runQueue, _NUTTHREADINFO::td_sp, _NUTTHREADINFO::td_state, and TDS_RUNNING.

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

HANDLE NutThreadCreate ( char *  name,
void(*)(void *)  fn,
void *  arg,
size_t  stackSize 
)

Create a new thread.

If the current thread's priority is lower or equal than the default priority (64), then the current thread is stopped and the new one is started.

Parameters:
nameString containing the symbolic name of the new thread, up to 8 characters long.
fnThe thread's entry point, typically created by the THREAD macro.
argArgument pointer passed to the new thread.
stackSizeNumber of bytes of the stack space allocated for the new thread.
Note:
On ARM some targets the thread must run in ARM mode. Thumb mode is not supported.
Returns:
Pointer to the NUTTHREADINFO structure or NULL to indicate an error.

If the current thread's priority is lower or equal than the default priority (64), then the current thread is stopped and the new one is started.

Parameters:
nameString containing the symbolic name of the new thread, up to 8 characters long.
fnThe thread's entry point, typically created by the THREAD macro.
argArgument pointer passed to the new thread.
stackSizeNumber of bytes of the stack space allocated for the new thread.
Note:
The thread must run in ARM mode. Thumb mode is not supported.
Returns:
Pointer to the NUTTHREADINFO structure or 0 to indicate an error.

References __os_trf, __os_trs, attr, fprintf(), irq_signal, main_cv, memcpy(), NULL, NutDumpThreadList(), NutEnterCritical, NutExitCritical, NutHeapAlloc, NutThreadAddPriQueue(), nutThreadList, NutThreadSwitch(), printf, runningThread, runQueue, _NUTTHREADINFO::td_name, _NUTTHREADINFO::td_next, _NUTTHREADINFO::td_priority, _NUTTHREADINFO::td_queue, _NUTTHREADINFO::td_state, _NUTTHREADINFO::td_timer, TDS_READY, TDS_RUNNING, and thread_mutex.

Referenced by AhdlcAt91Init(), AhdlcAvrInit(), AsixInit(), cs8900Init(), CSNicInit(), DmInit(), EmacInit(), IDEInit(), LancInit(), Lpc17xxEmacInit(), main(), NicInit(), NutIdle(), NutInit(), NutPppInitStateMachine(), NutRegisterDiscovery(), NutRegisterKey(), NutRegisterLed(), NutSNTPStartThread(), NutTcpInitStateMachine(), Sc16is752UsartInit(), SJAInit(), upnp_Init(), and wlandrv_Init().

Here is the call graph for this function:


Variable Documentation

pthread_attr_t attr
pthread_mutex_t thread_mutex

Referenced by NutThreadCreate(), and NutThreadInit().

pthread_cond_t main_cv

Referenced by NutThreadCreate(), and NutThreadInit().