Lines Matching defs:completion

6 #include "completion.h"
24 * vdo_work_queue which holds vdo_completions that are to be run in that zone. A completion may
27 * At each step of a multi-threaded operation, the completion performing the operation is given a
28 * callback, error handler, and thread id for the next step. A completion is "run" when it is
32 * will be invoked. Generally, a completion will not be run directly, but rather will be
35 * completion's "callback_thread_id". When it is dequeued, it will be on the correct thread, and
36 * will get run. In some cases, the completion should get queued instead of running immediately,
39 * the completion's "requeue" field should be set to true. Doing so will skip the current thread
40 * check and simply enqueue the completion.
42 * A completion may be "finished," in which case its "complete" field will be set to true before it
43 * is next run. It is a bug to attempt to set the result or re-finish a finished completion.
44 * Because a completion's fields are not safe to examine from any thread other than the one on
45 * which the completion is currently operating, this field is used only to aid in detecting
47 * A completion must be "reset" before it can be reused after it has been finished. Resetting will
51 void vdo_initialize_completion(struct vdo_completion *completion,
55 memset(completion, 0, sizeof(*completion));
56 completion->vdo = vdo;
57 completion->type = type;
58 vdo_reset_completion(completion);
61 static inline void assert_incomplete(struct vdo_completion *completion)
63 VDO_ASSERT_LOG_ONLY(!completion->complete, "completion is not complete");
67 * vdo_set_completion_result() - Set the result of a completion.
71 void vdo_set_completion_result(struct vdo_completion *completion, int result)
73 assert_incomplete(completion);
74 if (completion->result == VDO_SUCCESS)
75 completion->result = result;
79 * vdo_launch_completion_with_priority() - Run or enqueue a completion.
80 * @priority: The priority at which to enqueue the completion.
82 * If called on the correct thread (i.e. the one specified in the completion's callback_thread_id
83 * field) and not marked for requeue, the completion will be run immediately. Otherwise, the
84 * completion will be enqueued on the specified thread.
86 void vdo_launch_completion_with_priority(struct vdo_completion *completion,
89 thread_id_t callback_thread = completion->callback_thread_id;
91 if (completion->requeue || (callback_thread != vdo_get_callback_thread_id())) {
92 vdo_enqueue_completion(completion, priority);
96 vdo_run_completion(completion);
99 /** vdo_finish_completion() - Mark a completion as complete and then launch it. */
100 void vdo_finish_completion(struct vdo_completion *completion)
102 assert_incomplete(completion);
103 completion->complete = true;
104 if (completion->callback != NULL)
105 vdo_launch_completion(completion);
108 void vdo_enqueue_completion(struct vdo_completion *completion,
111 struct vdo *vdo = completion->vdo;
112 thread_id_t thread_id = completion->callback_thread_id;
115 "thread_id %u (completion type %d) is less than thread count %u",
116 thread_id, completion->type,
120 completion->requeue = false;
121 completion->priority = priority;
122 completion->my_queue = NULL;
123 vdo_enqueue_work_queue(vdo->threads[thread_id].queue, completion);
127 * vdo_requeue_completion_if_needed() - Requeue a completion if not called on the specified thread.
129 * Return: True if the completion was requeued; callers may not access the completion in this case.
131 bool vdo_requeue_completion_if_needed(struct vdo_completion *completion,
137 completion->callback_thread_id = callback_thread_id;
138 vdo_enqueue_completion(completion, VDO_WORK_Q_DEFAULT_PRIORITY);