CCF
Loading...
Searching...
No Matches
task.h
Go to the documentation of this file.
1// Copyright (c) Microsoft Corporation. All rights reserved.
2// Licensed under the Apache 2.0 License.
3#pragma once
4
5#include "tasks/resumable.h"
6
7#include <atomic>
8#include <functional>
9#include <memory>
10#include <string>
11
12namespace ccf::tasks
13{
14 struct BaseTask
15 {
16 private:
17 std::atomic<bool> cancelled = false;
18
20 virtual ccf::tasks::Resumable pause();
21
22 protected:
23 virtual void do_task_implementation() = 0;
24
25 public:
26 virtual ~BaseTask() = default;
27
28 void do_task();
29
30 [[nodiscard]] virtual const std::string& get_name() const = 0;
31
32 void cancel_task();
33 bool is_cancelled();
34 };
35
36 using Task = std::shared_ptr<BaseTask>;
37}
Definition basic_task.h:8
Resumable pause_current_task()
Definition task_system.cpp:90
std::shared_ptr< BaseTask > Task
Definition task.h:36
std::unique_ptr< IResumable > Resumable
Definition resumable.h:24
Definition task.h:15
void do_task()
Definition task_system.cpp:23
virtual const std::string & get_name() const =0
virtual void do_task_implementation()=0
void cancel_task()
Definition task_system.cpp:42
bool is_cancelled()
Definition task_system.cpp:47
virtual ~BaseTask()=default