Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

strange switch in Linux

I have some question about the following switch in Linux Kernel, somebody can explain please the last case, why do I need this case at all, if it is empty? thanks in advance

switch (prev->state) {
    case TASK_INTERRUPTIBLE:
        if (unlikely(signal_pending(prev))) {
            prev->state = TASK_RUNNING;
            break;
        }
    default:
        deactivate_task(prev, rq);
    case TASK_RUNNING:
        ;
    }

EDITED

I took it from linux 2.4.18, which I'm currently learning, there is no comment there about, why this way

like image 312
likeIT Avatar asked Jan 19 '23 22:01

likeIT


2 Answers

If prev->state == TASK_RUNNING and you don't have the last case, then deactivate_task will be called, which is presumably not desired here. This is just a quick way of doing something special for TASK_INTERRUPTIBLE and something different for every other state but TASK_RUNNING.

like image 148
sjr Avatar answered Jan 22 '23 11:01

sjr


Following is what they do there:

If prev->state == TASK_RUNNING -> do nothing.
If prev->state == TASK_INTERRUPTIBLE - > signal_pending() and then possibly deactivate_task()
In any other case just deactivate_task().
like image 44
c-smile Avatar answered Jan 22 '23 10:01

c-smile