Seastar
High performance C++ framework for concurrent servers
task.hh
1/*
2 * This file is open source software, licensed to you under the terms
3 * of the Apache License, Version 2.0 (the "License"). See the NOTICE file
4 * distributed with this work for additional information regarding copyright
5 * ownership. You may not use this file except in compliance with the License.
6 *
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing,
12 * software distributed under the License is distributed on an
13 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 * KIND, either express or implied. See the License for the
15 * specific language governing permissions and limitations
16 * under the License.
17 */
18/*
19 * Copyright (C) 2015 Cloudius Systems, Ltd.
20 */
21
22#pragma once
23
25#include <seastar/util/backtrace.hh>
26
27#ifndef SEASTAR_MODULE
28#include <utility>
29#endif
30
31namespace seastar {
32
33SEASTAR_MODULE_EXPORT
34class task {
35protected:
37private:
38#ifdef SEASTAR_TASK_BACKTRACE
40#endif
41protected:
42 // Task destruction is performed by run_and_dispose() via a concrete type,
43 // so no need for a virtual destructor here. Derived classes that implement
44 // run_and_dispose() should be declared final to avoid losing concrete type
45 // information via inheritance.
46 ~task() = default;
47
48 scheduling_group set_scheduling_group(scheduling_group new_sg) noexcept{
49 return std::exchange(_sg, new_sg);
50 }
51public:
52 explicit task(scheduling_group sg = current_scheduling_group()) noexcept : _sg(sg) {}
53 virtual void run_and_dispose() noexcept = 0;
55 virtual task* waiting_task() noexcept = 0;
56 scheduling_group group() const { return _sg; }
57 shared_backtrace get_backtrace() const;
58#ifdef SEASTAR_TASK_BACKTRACE
59 void make_backtrace() noexcept;
60#else
61 void make_backtrace() noexcept {}
62#endif
63};
64
65inline
66shared_backtrace task::get_backtrace() const {
67#ifdef SEASTAR_TASK_BACKTRACE
68 return _bt;
69#else
70 return {};
71#endif
72}
73
74SEASTAR_MODULE_EXPORT_BEGIN
75
76void schedule(task* t) noexcept;
77void schedule_checked(task* t) noexcept;
78void schedule_urgent(task* t) noexcept;
79
80SEASTAR_MODULE_EXPORT_END
81}
Definition: shared_ptr.hh:268
Identifies function calls that are accounted as a group.
Definition: scheduling.hh:285
Definition: task.hh:34
virtual task * waiting_task() noexcept=0
Returns the next task which is waiting for this task to complete execution, or nullptr.
Seastar API namespace.
Definition: abort_on_ebadf.hh:26
scheduling_group current_scheduling_group() noexcept
Returns the current scheduling group.
Definition: scheduling.hh:397