@@ -8,9 +8,6 @@
static bool task_is_idle(struct rxe_task *task)
{
- if (task->destroyed)
- return false;
-
spin_lock_bh(&task->lock);
switch (task->state) {
case TASK_STATE_IDLE:
@@ -19,12 +16,8 @@ static bool task_is_idle(struct rxe_task *task)
return true;
case TASK_STATE_BUSY:
task->state = TASK_STATE_ARMED;
- fallthrough;
- case TASK_STATE_ARMED:
- case TASK_STATE_PAUSED:
break;
default:
- WARN_ON(1);
break;
}
spin_unlock_bh(&task->lock);
@@ -41,7 +34,8 @@ static void do_task(struct rxe_task *task)
/* flush out pending tasks */
spin_lock_bh(&task->lock);
- if (task->state == TASK_STATE_PAUSED) {
+ if (task->state == TASK_STATE_PAUSED ||
+ task->state == TASK_STATE_INVALID) {
spin_unlock_bh(&task->lock);
return;
}
@@ -69,10 +63,7 @@ static void do_task(struct rxe_task *task)
task->state = TASK_STATE_BUSY;
cont = 1;
break;
- case TASK_STATE_PAUSED:
- break;
default:
- WARN_ON(1);
break;
}
spin_unlock_bh(&task->lock);
@@ -87,14 +78,16 @@ static void do_task(struct rxe_task *task)
static void disable_task(struct rxe_task *task)
{
spin_lock_bh(&task->lock);
- task->state = TASK_STATE_PAUSED;
+ if (task->state != TASK_STATE_INVALID)
+ task->state = TASK_STATE_PAUSED;
spin_unlock_bh(&task->lock);
}
static void enable_task(struct rxe_task *task)
{
spin_lock_bh(&task->lock);
- task->state = TASK_STATE_IDLE;
+ if (task->state != TASK_STATE_INVALID)
+ task->state = TASK_STATE_IDLE;
spin_unlock_bh(&task->lock);
/* restart task in case */
@@ -104,16 +97,16 @@ static void enable_task(struct rxe_task *task)
/* busy wait until any previous tasks are done */
static void cleanup_task(struct rxe_task *task)
{
- bool idle;
-
- task->destroyed = true;
+ bool busy;
do {
spin_lock_bh(&task->lock);
- idle = (task->state == TASK_STATE_IDLE ||
- task->state == TASK_STATE_PAUSED);
+ busy = (task->state == TASK_STATE_BUSY ||
+ task->state == TASK_STATE_ARMED);
+ if (!busy)
+ task->state = TASK_STATE_INVALID;
spin_unlock_bh(&task->lock);
- } while (!idle);
+ } while (busy);
}
/* silently treat schedule as inline for inline tasks */
@@ -131,14 +124,12 @@ static void inline_run(struct rxe_task *task)
static void inline_disable(struct rxe_task *task)
{
- if (!task->destroyed)
- disable_task(task);
+ disable_task(task);
}
static void inline_enable(struct rxe_task *task)
{
- if (!task->destroyed)
- enable_task(task);
+ enable_task(task);
}
static void inline_cleanup(struct rxe_task *task)
@@ -168,10 +159,7 @@ static void tsklet_sched(struct rxe_task *task)
static void tsklet_do_task(struct tasklet_struct *tasklet)
{
- struct rxe_task *task = container_of(tasklet, typeof(*task), tasklet);
-
- if (!task->destroyed)
- do_task(task);
+ do_task(container_of(tasklet, struct rxe_task, tasklet));
}
static void tsklet_run(struct rxe_task *task)
@@ -182,14 +170,12 @@ static void tsklet_run(struct rxe_task *task)
static void tsklet_disable(struct rxe_task *task)
{
- if (!task->destroyed)
- disable_task(task);
+ disable_task(task);
}
static void tsklet_enable(struct rxe_task *task)
{
- if (!task->destroyed)
- enable_task(task);
+ enable_task(task);
}
static void tsklet_cleanup(struct rxe_task *task)
@@ -217,7 +203,6 @@ int rxe_init_task(struct rxe_task *task, void *arg, int (*func)(void *),
{
task->arg = arg;
task->func = func;
- task->destroyed = false;
task->type = type;
task->state = TASK_STATE_IDLE;
@@ -27,6 +27,7 @@ enum {
TASK_STATE_BUSY = 1,
TASK_STATE_ARMED = 2,
TASK_STATE_PAUSED = 3,
+ TASK_STATE_INVALID = 4,
};
/*
@@ -41,7 +42,7 @@ struct rxe_task {
void *arg;
int (*func)(void *arg);
int ret;
- bool destroyed;
+ bool invalid;
const struct rxe_task_ops *ops;
enum rxe_task_type type;
};