GLAST / LAT > DAQ and FSW > FSW > Doxygen Index> PBS / dev > pbs / mv2304
#include <semLib.h>
#include <intLib.h>
#include <taskHookLib.h>
#include <PBS/MBA.h>
#include <PBS/WUT.h>
#include <PBS/WUT_tmr.h>
Defines | |
#define | TASK_K_DEFAULT_STACK_SIZE 20000 |
Sets the stack size if the user does not explicitly declare one. | |
Functions | |
static void | task_create_hook (WIND_TCB *tcb) |
Performs additional per task creation functions. | |
static void | task_delete_hook (WIND_TCB *tcb) |
Performs per task deletion functions. | |
static void | task_entry_safe (int options, TASK_entry usr_entry, TASK_parameter usr_parameter, TASK_tcb *tcb) |
Task entry point when the task is being started in a task delete safe fashion. | |
static void | task_entry_unsafe (int options, TASK_entry usr_entry, TASK_parameter usr_parameter, TASK_tcb *tcb) |
Task entry point when the task is being started in a task delete unsafe fashion. | |
static WUT_cb_status | task_wakeup (void *semaphore, WUT_tmr *tmr) |
Timer callback routine used in implementing TASK_wait. | |
int | TASK_tcb_sizeof (void) |
Returns the size, in bytes, of a TCB to be used when creating or spawning a TASK. | |
int | TASK_xtcb_sizeof () |
Returns the size, in bytes, of a TCB to be used when converting an existing (platform native task) to a TASK type task. | |
int | TASK_activate (TASK_tcb *tcb) |
Activates a previously created task. | |
int | TASK_create (TASK_tcb *tcb, const TASK_attr *attributes, TASK_entry entry_point, TASK_parameter parameter) |
Creates, but does not activate a task. | |
int | TASK_convert (TASK_tcb *tcb, const TASK_attr *attributes, TASK_entry entry_point, TASK_parameter parameter) |
Converts an existing VxWorks task to a TASK. | |
int | TASK_revert (TASK_tcb *tcb) |
Strips a task/thread of its TASK functionality. | |
void | TASK_exit (void *exit_value) |
Causes the calling task to delete itself and allows notification to another task, via TASK_join() that the calling task has deleted itself. | |
int | TASK_join (TASK_tcb *tcb, void **exit_value) |
Blocks the calling task until the specified task completes. | |
const char * | TASK_name (const TASK_tcb *tcb) |
Returns a pointer to the task's name. | |
int | TASK_resume (TASK_tcb *tcb) |
Resumes a previously suspended task. | |
int | TASK_suspend (TASK_tcb *tcb) |
Suspends a task. | |
int | TASK_wait (const TOV tov) |
Causes the calling task to wait (pause) until the specified timeout is reached. | |
int | TASK_destroy (TASK_tcb *tcb) |
Destroys, ie deletes, a previously created task. | |
int | TASK_spawn (TASK_tcb *tcb, const TASK_attr *attributes, TASK_entry entry_point, TASK_parameter parameter) |
Convenience routine to both create and activate a task. | |
int | TASK_priority_get (const TASK_tcb *tcb) |
Gets the current priority of the specified task. The priority is returned expressed in the native tasking model's scheme. | |
int | TASK_priority_set (TASK_tcb *tcb, int priority) |
Sets priority of the specified task to the specified value. | |
int | TASK_block (TASK_block_handle *tbh, TASK_block_cb rtn, void *prm) |
Provides a simple way to turn an asynchronous routine into a synchronous routine. | |
int | TASK_sys_init (void) |
Performs one time only initialization of the TASK facility. | |
int | TASK_sys_shutdown (void) |
Performs the shutdown of the TASK facility. This essentially undoes what TASK_sys_init did. |
CVS $Id: TASK.c.vx-xxx-xxx,v 1.9 2011/03/24 23:05:47 apw Exp $
int TASK_activate | ( | TASK_tcb * | tcb | ) |
Activates a previously created task.
tcb | The task control block of the task to activate. |
References _TASK_tcb::tid.
Referenced by TASK_spawn().
int TASK_block | ( | TASK_block_handle * | tbh, | |
TASK_block_cb | rtn, | |||
void * | prm | |||
) |
Provides a simple way to turn an asynchronous routine into a synchronous routine.
tbh | Pointer to a location to hold the task blocking handle This is must be passed to TASK_unblock to unblock the TASK upon completion of the routine. | |
rtn | The asynchronous callback routine to execute | |
prm | A parameter to be passed to the above routine. |
struct Synch { TASK_block_handle tbh; char buf[100]; void nbytes; SynchRtn synch_rtn; } synch; synch->synch_rtn = read_synch; status = TASK_block (&synch->tbh, read_it, &synch);
int read_synch (Synch *synch) { return TASK_unblock (synch->tbh); }
int TASK_convert | ( | TASK_tcb * | tcb, | |
const TASK_attr * | attributes, | |||
TASK_entry | entry_point, | |||
TASK_parameter | parameter | |||
) |
Converts an existing VxWorks task to a TASK.
tcb | The task control block to initialize | |
attributes | The task attributes block. This may be NULL, in which case the system defaults are used. | |
entry_point | The task's new entry point address. If this is non-NULL this will act as a user callback routine with the flow of control being passed onto this routine with parameter being passed to this routine. If NULL, control will pass back to the caller. | |
parameter | A parameter passed transparently to the entry_point routine. |
TASK_resume (), etc.
nbytes = TASK_xtcb_sizeof (); // Get the size of a conversion block tcb = MBA_alloc (nbytes); // Allocate memory for it // Give control to TASK, it will just call (*myRoutine)(myParameter) // then return when that routine is down status = TASK_convert (tcb, NULL, myRoutine, myParameter); // Strip this task of TASK functionality status = TASK_revert (tcb); // Return the TASK resources MBA_free (tcb); // Free the memory for the tcb
The second usage is when doing informal coding in the shell.
nbytes = TASK_xtcb_sizeof (); // Get the size of a conversion block tcb = MBA_alloc (nbytes); // Allocate memory for it // Just create and initialize the tcb status = TASK_convert (tcb, NULL, NULL, NULL); ... lots of code // Strip this task of TASK functionality status = TASK_revert (tcb); // Return the TASK resources MBA_free (tcb); // Free the memory for the tcb
Naturally the above example (the one without the user callback routine can be used in the other case also, but, style-wise, usage of the calback is structurally cleaner.
TASK_rvt(). TASK_cvt combines the sizing and memory allocation with TASK_convert(), while, at least currently TASK_rvt() returns the memory and calls TASK_revert(). The rule is always pair TASK_convert/TASK_revert or TASK_cvt/TASK_rvt
References _TASK_tcb::pcb, _TASK_attr::priority, TASK_priority_set(), and _TASK_tcb::tid.
Referenced by TASK_cvt().
int TASK_create | ( | TASK_tcb * | tcb, | |
const TASK_attr * | attributes, | |||
TASK_entry | entry_point, | |||
TASK_parameter | parameter | |||
) |
Creates, but does not activate a task.
tcb | The task control block of the task to create | |
attributes | A collection of attributes used to exactly specify the task. This parameter may be specified as NULL. In this case, a platform dependent set of attributes is assigned. | |
entry_point | The address of the entry point of the newly created task. See TASK_entry for the call signature. | |
parameter | A parameter which is passed transparently to the newly created task's entry point. |
References _TASK_tcb::ecb, MBA_alloc(), _TASK_attr::name, _TASK_attr::options, _TASK_attr::priority, _TASK_ecb::semaphore, _TASK_ecb::stack, _TASK_attr::stack_addr, _TASK_attr::stack_size, task_entry_safe(), task_entry_unsafe(), TASK_K_STACK_SIZE_DEFAULT, TASK_K_STACK_SIZE_MINIMUM, TASK_M_OPTIONS_DETACH, _TASK_tcb::tid, and _TASK_ecb::value.
Referenced by TASK_spawn().
static void task_create_hook | ( | WIND_TCB * | tcb | ) | [static] |
Performs additional per task creation functions.
tcb | The VxWorks task control block |
Referenced by TASK_sys_init(), and TASK_sys_shutdown().
static void task_delete_hook | ( | WIND_TCB * | tcb | ) | [static] |
Performs per task deletion functions.
tcb | The VxWorks tasck control block |
Referenced by TASK_sys_init(), and TASK_sys_shutdown().
int TASK_destroy | ( | TASK_tcb * | tcb | ) |
Destroys, ie deletes, a previously created task.
tcb | The task control block of the task to destroy. |
References _TASK_tcb::tid.
static void task_entry_safe | ( | int | options, | |
TASK_entry | usr_entry, | |||
TASK_parameter | usr_parameter, | |||
TASK_tcb * | tcb | |||
) | [static] |
Task entry point when the task is being started in a task delete safe fashion.
options | Task startup options | |
usr_entry | The user entry point | |
usr_parameter | The user parameter | |
tcb | The task's tcb |
References _TASK_tcb::pcb, and TASK_exit().
Referenced by TASK_create().
static void task_entry_unsafe | ( | int | options, | |
TASK_entry | usr_entry, | |||
TASK_parameter | usr_parameter, | |||
TASK_tcb * | tcb | |||
) | [static] |
Task entry point when the task is being started in a task delete unsafe fashion.
options | Task startup options | |
usr_entry | The user entry point | |
usr_parameter | The user parameter | |
tcb | The task's tcb |
References _TASK_tcb::pcb.
Referenced by TASK_create().
void TASK_exit | ( | void * | exit_value | ) |
Causes the calling task to delete itself and allows notification to another task, via TASK_join() that the calling task has deleted itself.
exit_value | An arbitrary 32-bit value passed to TASK_join(). |
Note that the status value is a void *, so a pointer to any piece of information can be supplied with the usual caveat that the memory the pointer is aimed at remains valid until read.
References _TASK_tcb::ecb, _TASK_ecb::semaphore, TASK__self(), and _TASK_ecb::value.
Referenced by task_entry_safe().
int TASK_join | ( | TASK_tcb * | tcb, | |
void ** | exit_value | |||
) |
Blocks the calling task until the specified task completes.
tcb | The task to join | |
exit_value | Location to receive the exiting task's completion value. |
References _TASK_tcb::ecb, MBA_free(), _TASK_ecb::semaphore, _TASK_ecb::stack, _TASK_tcb::tid, and _TASK_ecb::value.
Referenced by FORK_join().
const char* TASK_name | ( | const TASK_tcb * | tcb | ) |
Returns a pointer to the task's name.
tcb | The tcb of the task |
ISR>,of | tcb is specified as NULL, but in interrupt context | |
UND>,if | tcb is non-NULL and not in interrupt context but no name is associated with the task. |
References _TASK_tcb::tid.
int TASK_priority_get | ( | const TASK_tcb * | tcb | ) |
Gets the current priority of the specified task. The priority is returned expressed in the native tasking model's scheme.
tcb | The task control block of which task to query. If specified as NULL, the current task's priority. |
References _TASK_tcb::tid.
Referenced by TASK_priority_number_compute().
int TASK_priority_set | ( | TASK_tcb * | tcb, | |
int | priority | |||
) |
Sets priority of the specified task to the specified value.
tcb | The Task Control Block of the task to change the priority. If NULL, then the current task. | |
priority | The priority to set the task to. |
References _TASK_tcb::tid.
Referenced by TASK_convert().
int TASK_resume | ( | TASK_tcb * | tcb | ) |
Resumes a previously suspended task.
tcb | The Task Control Block of the task to resume |
References _TASK_tcb::tid.
Referenced by FORK_resume().
int TASK_revert | ( | TASK_tcb * | tcb | ) |
Strips a task/thread of its TASK functionality.
tcb | The Task Control Block. This may be NULL, in which case the current task is reverted. |
Although this call can be used with TASK_create() and TASK_spawn(), it is most usually called after TASK_convert().
References _TASK_tcb::pcb, TASK_self(), and _TASK_tcb::tid.
Referenced by TASK_rvt().
int TASK_spawn | ( | TASK_tcb * | tcb, | |
const TASK_attr * | attributes, | |||
TASK_entry | entry_point, | |||
TASK_parameter | parameter | |||
) |
Convenience routine to both create and activate a task.
tcb | The task control block of the task to spawn | |
attributes | A collection of attributes used to exactly specify the task. This parameter may be specified as NULL. In this case, a platform dependent set of attributes is assigned. | |
entry_point | The address of the entry point of the newly created task. See TASK_entry for the call signature. | |
parameter | A parameter which is passed transparently to the newly created task's entry point. |
References TASK_activate(), and TASK_create().
Referenced by FORK_create().
int TASK_suspend | ( | TASK_tcb * | tcb | ) |
Suspends a task.
tcb | The Task Control Block of the task to suspend |
References _TASK_tcb::tid.
Referenced by FORK_suspend().
int TASK_sys_init | ( | void | ) |
Performs one time only initialization of the TASK facility.
References task_create_hook(), and task_delete_hook().
Referenced by PBS_initialize2().
int TASK_sys_shutdown | ( | void | ) |
Performs the shutdown of the TASK facility. This essentially undoes what TASK_sys_init did.
References task_create_hook(), and task_delete_hook().
Referenced by PBS_shutdown().
int TASK_tcb_sizeof | ( | void | ) |
Returns the size, in bytes, of a TCB to be used when creating or spawning a TASK.
Referenced by FORK_create(), and FORK_fcb_sizeof().
int TASK_wait | ( | const TOV | tov | ) |
Causes the calling task to wait (pause) until the specified timeout is reached.
tov | The timeout value to wait until |
References _WUT_tmr::state, task_wakeup(), WUT_cancel(), WUT_INIT, WUT_K_EXPIRED, WUT_K_QUEUED, and WUT_start().
Referenced by TASK_pause().
static WUT_cb_status task_wakeup | ( | void * | semaphore, | |
WUT_tmr * | tmr | |||
) | [static] |
Timer callback routine used in implementing TASK_wait.
semaphore | The semaphore to give, thus unblocking the task. | |
tmr | The WUT timer handle |
References WUT_K_STATE_CHANGE_NO.
Referenced by TASK_wait().
int TASK_xtcb_sizeof | ( | void | ) |
Returns the size, in bytes, of a TCB to be used when converting an existing (platform native task) to a TASK type task.
Referenced by TASK_cvt().