task_register() conversion: grab client task
[paraslash.git] / grab_client.c
index 672c96f1d6b42ac8fd75418486cdb02ce2d24395..4f9b40418592d422e580051a19207da031421117 100644 (file)
@@ -54,7 +54,7 @@ struct grab_client {
        /** The point of the grab client's node in the buffer tree. */
        struct btr_node *btrn;
        /* The task of this grab client. */
-       struct task task;
+       struct task *task;
        /** Belongs to either the active or the inactive list. */
        struct list_head node;
 };
@@ -94,7 +94,7 @@ err:
 
 static void gc_pre_select(struct sched *s, struct task *t)
 {
-       struct grab_client *gc = container_of(t, struct grab_client, task);
+       struct grab_client *gc = task_context(t);
        int ret = btr_node_status(gc->btrn, 0, BTR_NT_LEAF);
 
        if (ret == 0)
@@ -129,12 +129,13 @@ static void gc_activate(struct grab_client *gc, struct sched *s)
        list_move(&gc->node, &active_grab_client_list);
        gc->btrn = btr_new_node(&(struct btr_node_description)
                EMBRACE(.name = name, .parent = parent));
-       gc->task.pre_select = gc_pre_select;
-       gc->task.post_select = gc_post_select;
-       snprintf(gc->task.status, sizeof(gc->task.status) - 1, "%s", name);
-       gc->task.status[sizeof(gc->task.status) - 1] = '\0';
-       gc->task.error = 0;
-       register_task(s, &gc->task);
+
+       gc->task = task_register(&(struct task_info) {
+               .name = name,
+               .pre_select = gc_pre_select,
+               .post_select = gc_post_select,
+               .context = gc,
+       }, s);
 }
 
 /**
@@ -186,7 +187,7 @@ static int gc_close(struct grab_client *gc, int err)
 
 static int gc_post_select(__a_unused struct sched *s, struct task *t)
 {
-       struct grab_client *gc = container_of(t, struct grab_client, task);
+       struct grab_client *gc = task_context(t);
        struct btr_node *btrn = gc->btrn;
        int ret;
        size_t sz;