- case SILC_TASK_PRI_HIGH:
- /* High priority. The task is added before lower priority tasks
- but after tasks with higher priority. */
- while(prev != task) {
-
- /* If we have longer timeout than with the task head of us
- we have found our spot. */
- if (silc_task_timeout_compare(&prev->timeout, &new->timeout))
- break;
-
- /* If we are equal size of timeout, priority kicks in place. */
- if (!silc_task_timeout_compare(&new->timeout, &prev->timeout))
- if (prev->priority >= SILC_TASK_PRI_HIGH)
- break;
-
- /* We have shorter timeout or higher priority, compare to next one. */
- prev = prev->prev;
- }
- /* Found a spot from the list, add the task to the list. */
- next = prev->next;
- new->prev = prev;
- new->next = next;
- prev->next = new;
- next->prev = new;
-
- if (prev == task) {
- /* Check if we are going to be the first task in the queue */
- if (silc_task_timeout_compare(&prev->timeout, &new->timeout))
- break;
- if (!silc_task_timeout_compare(&new->timeout, &prev->timeout))
- if (prev->priority >= SILC_TASK_PRI_HIGH)
- break;
-
- /* We are now the first task in queue */
- queue->task = new;
- }
- break;
- case SILC_TASK_PRI_REALTIME:
- /* Highest priority. The task is added at the head of the list.
- The last registered task is added to the very head of the list
- thus we get the LIFO (Last-In-First-Out) order. */
- next = task->next;
- while(next != task) {
-
- /* If we have shorter timeout than the next task we've found
- our spot. */
- if (silc_task_timeout_compare(&new->timeout, &next->timeout))
- break;
-
- /* If we are equal size of timeout we will be first. */
- if (!silc_task_timeout_compare(&next->timeout, &new->timeout))
- break;
-
- /* We have longer timeout, compare to next one. */
- next = next->next;
- }
- /* Found a spot from the list, add the task to the list. */
- prev = next->prev;
- new->next = next;
- new->prev = prev;
- prev->next = new;
- next->prev = new;
-
- if (next == task) {
- /* Check if we are going to be the first task in the queue */
- if (silc_task_timeout_compare(&next->timeout, &new->timeout))
- break;
-
- /* We are now the first task in queue */
- queue->task = new;
- }