Tuesday, November 19, 2013

Data Queue Vs Mailbox: Deletion

① Difference between deletion of Data Queue and Mailbox

Both processings are almost same except that in Data Queue both the send-wait and receive-wait queues need to be checked.

② ITRON implementation of delete Data Queue

ER del_dtq(ID dtqid)
{
        If (called from ISR)
                return E_CTX;
        Sanity check on arguments;
        enter critical section;
        if (data queue is full) {
                for (each task waiting in the send-wait queue) {
                        Get the task control block from the task ID
                        Assign E_DLT in the return error code of the task's context;
                        if task is waiting in Timeout
                                remove from timer queue
                        Set task status as Ready
                        if the task is NOT suspended {
                                Change the task to the Ready Queue of priority
                                If (the task priority is higher than the current)
                                        set the flag to call scheduler
                        } else {
                                Just delete the task from the send wait queue
                        }
                }
        }
        if (data queue is empty) {
                for (each task waiting in the receive-wait queue) {
                        Get the task control block from the task ID
                        Assign E_DLT in the return error code of the task's context;
                        if task is waiting in Timeout
                                remove from timer queue
                        Set task status as Ready
                        if the task is NOT suspended {
                                Change the task to the Ready Queue of priority
                                If (the task priority is higher than the current)
                                        set the flag to call scheduler
                        } else {
                                Just delete the task from the send wait queue
                        }
                }
        }
        Free all the memory allocated for the data queue;
        if (the flag to call scheduler is set) {
                call scheduler;
        } else {
                exit critical section and return E_OK;
        }
}
③ITRON implementation of delete Mailbox

ER del_mbx(ID mbxid)
{
        If (called from ISR)
                return E_CTX;
        Sanity check on arguments;
        enter critical section;
        for (each task waiting in the receive-wait queue) {
                Get the task control block from the task ID
                Assign E_DLT in the return error code of the task's context;
                if task is waiting in Timeout
                        remove from timer queue
                Set task status as Ready
                if the task is NOT suspended {
                        Change the task to the Ready Queue of priority
                        If (the task priority is higher than the current)
                                set the flag to call scheduler
                } else {
                        Just delete the task from the send wait queue
                }
        }
        Free all the memory allocated for the mailbox;
        if (the flag to call scheduler is set) {
                call scheduler;
        } else {
                exit critical section and return E_OK;
        }
}

Deletion - Wake up sleeping men and tell them the building no more exists, before burning the building.

No comments: