There are 4 variables that constitute the state of the CrossWorks Tasking Library.

    extern CTL_TASK_t *ctl_task_executing;
    extern CTL_TASK_t *ctl_task_list;
    extern unsigned ctl_interrupt_count;
    extern CTL_TIME_t ctl_current_time;
    extern CTL_EVENT_SET_t ctl_libc_mutex;

The ctl_task_executing variable points to the CTL_TASK_t structure of the current executing task. The priority field is the only one of the CTL_TASK_t structure that is defined for the task that is executing. This variable should never be 0.

The ctl_task_list variable points to the highest priority task that isn't executing. This variable should never be 0.

The ctl_interrupt_count variable contains a count of the interrupt nesting level. This is used to enable an ISR to call the ctl_set_clear_events functions.

The ctl_current_time contains the current time value.

The ctl_lib_mutex is the event set used to serialise access to C library resources. The event set is used as follows:

- bit 0 - used by malloc and free.
- bit 1 - used by printf.
- bit 2 - used by scanf.
- bit 3 - used by debug IO operations.