GLAST / LAT > DAQ and FSW > FSW > Doxygen Index> PBS / V2-12-1 > pbs / rhel6-32
#include <errno.h>
#include <stdio.h>
#include <PBS/BUG.h>
#include <PBI/PTR.h>
#include <sched.h>
#include <semaphore.h>
Functions | |
void * | TASK_wrapper (TASK_tcb *tcb) |
Pseudo entry to launch the user's routine from. | |
int | TASK_tcb_sizeof (void) |
Returns the size, in bytes, of a TCB to be used when creating or spawning a TASK. | |
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. | |
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. | |
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. | |
const char * | TASK_name (const TASK_tcb *tcb) |
Returns a pointer to the task's name. | |
int | TASK_join (TASK_tcb *tcb, void **exit_value) |
Blocks the calling task until the specified task completes. | |
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_destroy (TASK_tcb *tcb) |
Destroys, ie deletes, a previously created task. | |
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_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_unblock (TASK_block_handle tbh) |
Unblocks a task blocked on a call to TASK_block. |
CVS $Id: TASK.c.px-xxx-xxx,v 1.10 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_wcb::activated, BUG_check(), _TASK_wcb::cond, _TASK_wcb::mutex, and _TASK_tcb::wcb.
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); }
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.
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::entry_point, _TASK_attr::name, _TASK_tcb::ncb, _TASK_tcb::parameter, _TASK_tcb::pcb, _TASK_attr::priority, TASK_priority_set(), _TASK_tcb::tid, and _TASK_tcb::wcb.
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. |
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_revert(), and _TASK_tcb::tid.
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_revert().
Referenced by wut_sys_kill().
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::tid.
Referenced by FORK_join(), and wut_sys_shutdown().
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_ncb::name, _TASK_tcb::ncb, and TASK_self().
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_PRINTF, and _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 BUG_check(), _TASK_wcb::cond, _TASK_wcb::mutex, _TASK_wcb::suspend, TASK__self(), and _TASK_tcb::wcb.
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::wcb.
Referenced by TASK_destroy(), TASK_exit(), and 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. |
Referenced by FORK_create(), and wut_sys_connect().
int TASK_suspend | ( | TASK_tcb * | tcb | ) |
Suspends a task.
tcb | The Task Control Block of the task to suspend |
References BUG_check(), _TASK_wcb::cond, _TASK_wcb::mutex, _TASK_wcb::suspend, TASK__self(), and _TASK_tcb::wcb.
Referenced by FORK_suspend().
int TASK_sys_init | ( | void | ) |
Performs one time only initialization of the TASK facility.
Referenced by PBS_initialize2().
int TASK_sys_shutdown | ( | void | ) |
Performs the shutdown of the TASK facility. This essentially undoes what TASK_sys_init did.
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_unblock | ( | TASK_block_handle | tbh | ) |
Unblocks a task blocked on a call to TASK_block.
tbh | The task blocking handle |
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 BUG_check(), _TASK_wcb::cond, _TASK_wcb::mutex, TASK__self(), TOV_NSECS, TOV_SECS, and _TASK_tcb::wcb.
Referenced by TASK_pause().
void * TASK_wrapper | ( | TASK_tcb * | tcb | ) |
Pseudo entry to launch the user's routine from.
tcb | The task control |
Another design decision could have been to abandon the concept of task/thread creation without activation. In VxWorks, this concept proves useful when debugging. If there is an error in the task's initialization code, one needs to create the task first, then attach the debugger before activating the task. The ordering is important, since the debugger attachs by the task's id (TID). This must exist before it can be used.
References _TASK_wcb::activated, BUG_check(), _TASK_wcb::cond, _TASK_tcb::entry_point, _TASK_wcb::mutex, _TASK_tcb::parameter, _TASK_tcb::pcb, and _TASK_tcb::wcb.
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().