#ifndef VDO_COMPLETION_H
#define VDO_COMPLETION_H
#include "permassert.h"
#include "status-codes.h"
#include "types.h"
static inline void vdo_run_completion(struct vdo_completion *completion)
{
if ((completion->result != VDO_SUCCESS) && (completion->error_handler != NULL)) {
completion->error_handler(completion);
return;
}
completion->callback(completion);
}
void vdo_set_completion_result(struct vdo_completion *completion, int result);
void vdo_initialize_completion(struct vdo_completion *completion, struct vdo *vdo,
enum vdo_completion_type type);
static inline void vdo_reset_completion(struct vdo_completion *completion)
{
completion->result = VDO_SUCCESS;
completion->complete = false;
}
void vdo_launch_completion_with_priority(struct vdo_completion *completion,
enum vdo_completion_priority priority);
static inline void vdo_launch_completion(struct vdo_completion *completion)
{
vdo_launch_completion_with_priority(completion, VDO_WORK_Q_DEFAULT_PRIORITY);
}
static inline void vdo_continue_completion(struct vdo_completion *completion, int result)
{
vdo_set_completion_result(completion, result);
vdo_launch_completion(completion);
}
void vdo_finish_completion(struct vdo_completion *completion);
static inline void vdo_fail_completion(struct vdo_completion *completion, int result)
{
vdo_set_completion_result(completion, result);
vdo_finish_completion(completion);
}
static inline int vdo_assert_completion_type(struct vdo_completion *completion,
enum vdo_completion_type expected)
{
return VDO_ASSERT(expected == completion->type,
"completion type should be %u, not %u", expected,
completion->type);
}
static inline void vdo_set_completion_callback(struct vdo_completion *completion,
vdo_action_fn callback,
thread_id_t callback_thread_id)
{
completion->callback = callback;
completion->callback_thread_id = callback_thread_id;
}
static inline void vdo_launch_completion_callback(struct vdo_completion *completion,
vdo_action_fn callback,
thread_id_t callback_thread_id)
{
vdo_set_completion_callback(completion, callback, callback_thread_id);
vdo_launch_completion(completion);
}
static inline void vdo_prepare_completion(struct vdo_completion *completion,
vdo_action_fn callback,
vdo_action_fn error_handler,
thread_id_t callback_thread_id, void *parent)
{
vdo_reset_completion(completion);
vdo_set_completion_callback(completion, callback, callback_thread_id);
completion->error_handler = error_handler;
completion->parent = parent;
}
static inline void vdo_prepare_completion_for_requeue(struct vdo_completion *completion,
vdo_action_fn callback,
vdo_action_fn error_handler,
thread_id_t callback_thread_id,
void *parent)
{
vdo_prepare_completion(completion, callback, error_handler,
callback_thread_id, parent);
completion->requeue = true;
}
void vdo_enqueue_completion(struct vdo_completion *completion,
enum vdo_completion_priority priority);
bool vdo_requeue_completion_if_needed(struct vdo_completion *completion,
thread_id_t callback_thread_id);
#endif