Seastar
High performance C++ framework for concurrent servers
io_intent.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 2021 ScyllaDB
20 */
21
22#pragma once
23
24#include <seastar/core/internal/io_intent.hh>
25#include <seastar/core/io_priority_class.hh>
26#include <seastar/util/modules.hh>
27#ifndef SEASTAR_MODULE
28#include <boost/container/small_vector.hpp>
29#endif
30
31namespace seastar {
32
43SEASTAR_MODULE_EXPORT
44class io_intent {
45 struct intents_for_queue {
46 dev_t dev;
47 io_priority_class_id qid;
48 internal::cancellable_queue cq;
49
50 intents_for_queue(dev_t dev_, io_priority_class_id qid_) noexcept
51 : dev(dev_), qid(qid_), cq() {}
52
53 intents_for_queue(intents_for_queue&&) noexcept = default;
54 intents_for_queue& operator=(intents_for_queue&&) noexcept = default;
55 };
56
57 struct references {
58 internal::intent_reference::container_type list;
59
60 references(references&& o) noexcept : list(std::move(o.list)) {}
61 references() noexcept : list() {}
62 ~references() { clear(); }
63
64 void clear() {
65 list.clear_and_dispose([] (internal::intent_reference* r) { r->on_cancel(); });
66 }
67
68 void bind(internal::intent_reference& iref) noexcept {
69 list.push_back(iref);
70 }
71 };
72
73 boost::container::small_vector<intents_for_queue, 1> _intents;
74 references _refs;
75 friend internal::intent_reference::intent_reference(io_intent*) noexcept;
76
77public:
78 io_intent() = default;
79 ~io_intent() = default;
80
81 io_intent(const io_intent&) = delete;
82 io_intent& operator=(const io_intent&) = delete;
83 io_intent& operator=(io_intent&&) = delete;
84 io_intent(io_intent&& o) noexcept : _intents(std::move(o._intents)), _refs(std::move(o._refs)) {
85 for (auto&& r : _refs.list) {
86 r._intent = this;
87 }
88 }
89
93 void cancel() noexcept {
94 _refs.clear();
95 _intents.clear();
96 }
97
99 internal::cancellable_queue& find_or_create_cancellable_queue(dev_t dev, io_priority_class_id qid) {
100 for (auto&& i : _intents) {
101 if (i.dev == dev && i.qid == qid) {
102 return i.cq;
103 }
104 }
105
106 _intents.emplace_back(dev, qid);
107 return _intents.back().cq;
108 }
109};
110
111} // namespace seastar
Definition: io_intent.hh:44
void cancel() noexcept
Definition: io_intent.hh:93
Seastar API namespace.
Definition: abort_on_ebadf.hh:26