mirror of
https://github.com/ceph/ceph
synced 2025-04-11 04:02:04 +00:00
Merge pull request #49 from cbodley/wip-remove-by-ptr
PriorityQueueBase uses RequestRef&& for remove_by callbacks
This commit is contained in:
commit
5538352024
@ -379,12 +379,12 @@ namespace crimson {
|
|||||||
|
|
||||||
// NB: because a deque is the underlying structure, this
|
// NB: because a deque is the underlying structure, this
|
||||||
// operation might be expensive
|
// operation might be expensive
|
||||||
bool remove_by_req_filter_fw(std::function<bool(R&&)> filter_accum) {
|
bool remove_by_req_filter_fw(std::function<bool(RequestRef&&)> filter_accum) {
|
||||||
bool any_removed = false;
|
bool any_removed = false;
|
||||||
for (auto i = requests.begin();
|
for (auto i = requests.begin();
|
||||||
i != requests.end();
|
i != requests.end();
|
||||||
/* no inc */) {
|
/* no inc */) {
|
||||||
if (filter_accum(std::move(*i->request))) {
|
if (filter_accum(std::move(i->request))) {
|
||||||
any_removed = true;
|
any_removed = true;
|
||||||
i = requests.erase(i);
|
i = requests.erase(i);
|
||||||
} else {
|
} else {
|
||||||
@ -396,12 +396,12 @@ namespace crimson {
|
|||||||
|
|
||||||
// NB: because a deque is the underlying structure, this
|
// NB: because a deque is the underlying structure, this
|
||||||
// operation might be expensive
|
// operation might be expensive
|
||||||
bool remove_by_req_filter_bw(std::function<bool(R&&)> filter_accum) {
|
bool remove_by_req_filter_bw(std::function<bool(RequestRef&&)> filter_accum) {
|
||||||
bool any_removed = false;
|
bool any_removed = false;
|
||||||
for (auto i = requests.rbegin();
|
for (auto i = requests.rbegin();
|
||||||
i != requests.rend();
|
i != requests.rend();
|
||||||
/* no inc */) {
|
/* no inc */) {
|
||||||
if (filter_accum(std::move(*i->request))) {
|
if (filter_accum(std::move(i->request))) {
|
||||||
any_removed = true;
|
any_removed = true;
|
||||||
i = decltype(i){ requests.erase(std::next(i).base()) };
|
i = decltype(i){ requests.erase(std::next(i).base()) };
|
||||||
} else {
|
} else {
|
||||||
@ -412,7 +412,7 @@ namespace crimson {
|
|||||||
}
|
}
|
||||||
|
|
||||||
inline bool
|
inline bool
|
||||||
remove_by_req_filter(std::function<bool(R&&)> filter_accum,
|
remove_by_req_filter(std::function<bool(RequestRef&&)> filter_accum,
|
||||||
bool visit_backwards) {
|
bool visit_backwards) {
|
||||||
if (visit_backwards) {
|
if (visit_backwards) {
|
||||||
return remove_by_req_filter_bw(filter_accum);
|
return remove_by_req_filter_bw(filter_accum);
|
||||||
@ -506,7 +506,7 @@ namespace crimson {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool remove_by_req_filter(std::function<bool(R&&)> filter_accum,
|
bool remove_by_req_filter(std::function<bool(RequestRef&&)> filter_accum,
|
||||||
bool visit_backwards = false) {
|
bool visit_backwards = false) {
|
||||||
bool any_removed = false;
|
bool any_removed = false;
|
||||||
DataGuard g(data_mtx);
|
DataGuard g(data_mtx);
|
||||||
@ -528,14 +528,14 @@ namespace crimson {
|
|||||||
|
|
||||||
|
|
||||||
// use as a default value when no accumulator is provide
|
// use as a default value when no accumulator is provide
|
||||||
static void request_sink(R&& req) {
|
static void request_sink(RequestRef&& req) {
|
||||||
// do nothing
|
// do nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void remove_by_client(const C& client,
|
void remove_by_client(const C& client,
|
||||||
bool reverse = false,
|
bool reverse = false,
|
||||||
std::function<void (R&&)> accum = request_sink) {
|
std::function<void (RequestRef&&)> accum = request_sink) {
|
||||||
DataGuard g(data_mtx);
|
DataGuard g(data_mtx);
|
||||||
|
|
||||||
auto i = client_map.find(client);
|
auto i = client_map.find(client);
|
||||||
@ -546,13 +546,13 @@ namespace crimson {
|
|||||||
for (auto j = i->second->requests.rbegin();
|
for (auto j = i->second->requests.rbegin();
|
||||||
j != i->second->requests.rend();
|
j != i->second->requests.rend();
|
||||||
++j) {
|
++j) {
|
||||||
accum(std::move(*j->request));
|
accum(std::move(j->request));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for (auto j = i->second->requests.begin();
|
for (auto j = i->second->requests.begin();
|
||||||
j != i->second->requests.end();
|
j != i->second->requests.end();
|
||||||
++j) {
|
++j) {
|
||||||
accum(std::move(*j->request));
|
accum(std::move(j->request));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -247,6 +247,7 @@ namespace crimson {
|
|||||||
|
|
||||||
using ClientId = int;
|
using ClientId = int;
|
||||||
using Queue = dmc::PullPriorityQueue<ClientId,MyReq>;
|
using Queue = dmc::PullPriorityQueue<ClientId,MyReq>;
|
||||||
|
using MyReqRef = typename Queue::RequestRef;
|
||||||
|
|
||||||
ClientId client1 = 17;
|
ClientId client1 = 17;
|
||||||
ClientId client2 = 98;
|
ClientId client2 = 98;
|
||||||
@ -277,15 +278,15 @@ namespace crimson {
|
|||||||
EXPECT_EQ(2u, pq.client_count());
|
EXPECT_EQ(2u, pq.client_count());
|
||||||
EXPECT_EQ(9u, pq.request_count());
|
EXPECT_EQ(9u, pq.request_count());
|
||||||
|
|
||||||
pq.remove_by_req_filter([](const MyReq& r) -> bool {return 1 == r.id % 2;});
|
pq.remove_by_req_filter([](MyReqRef&& r) -> bool {return 1 == r->id % 2;});
|
||||||
|
|
||||||
EXPECT_EQ(5u, pq.request_count());
|
EXPECT_EQ(5u, pq.request_count());
|
||||||
|
|
||||||
std::list<MyReq> capture;
|
std::list<MyReq> capture;
|
||||||
pq.remove_by_req_filter(
|
pq.remove_by_req_filter(
|
||||||
[&capture] (const MyReq& r) -> bool {
|
[&capture] (MyReqRef&& r) -> bool {
|
||||||
if (0 == r.id % 2) {
|
if (0 == r->id % 2) {
|
||||||
capture.push_front(r);
|
capture.push_front(*r);
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
@ -316,6 +317,7 @@ namespace crimson {
|
|||||||
|
|
||||||
using ClientId = int;
|
using ClientId = int;
|
||||||
using Queue = dmc::PullPriorityQueue<ClientId,MyReq>;
|
using Queue = dmc::PullPriorityQueue<ClientId,MyReq>;
|
||||||
|
using MyReqRef = typename Queue::RequestRef;
|
||||||
|
|
||||||
ClientId client1 = 17;
|
ClientId client1 = 17;
|
||||||
|
|
||||||
@ -346,9 +348,9 @@ namespace crimson {
|
|||||||
|
|
||||||
std::vector<MyReq> capture;
|
std::vector<MyReq> capture;
|
||||||
pq.remove_by_req_filter(
|
pq.remove_by_req_filter(
|
||||||
[&capture] (const MyReq& r) -> bool {
|
[&capture] (MyReqRef&& r) -> bool {
|
||||||
if (1 == r.id % 2) {
|
if (1 == r->id % 2) {
|
||||||
capture.push_back(r);
|
capture.push_back(*r);
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
@ -367,9 +369,9 @@ namespace crimson {
|
|||||||
|
|
||||||
std::vector<MyReq> capture2;
|
std::vector<MyReq> capture2;
|
||||||
pq.remove_by_req_filter(
|
pq.remove_by_req_filter(
|
||||||
[&capture2] (const MyReq& r) -> bool {
|
[&capture2] (MyReqRef&& r) -> bool {
|
||||||
if (0 == r.id % 2) {
|
if (0 == r->id % 2) {
|
||||||
capture2.insert(capture2.begin(), r);
|
capture2.insert(capture2.begin(), *r);
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
@ -398,6 +400,7 @@ namespace crimson {
|
|||||||
|
|
||||||
using ClientId = int;
|
using ClientId = int;
|
||||||
using Queue = dmc::PullPriorityQueue<ClientId,MyReq>;
|
using Queue = dmc::PullPriorityQueue<ClientId,MyReq>;
|
||||||
|
using MyReqRef = typename Queue::RequestRef;
|
||||||
|
|
||||||
ClientId client1 = 17;
|
ClientId client1 = 17;
|
||||||
|
|
||||||
@ -428,9 +431,9 @@ namespace crimson {
|
|||||||
|
|
||||||
std::vector<MyReq> capture;
|
std::vector<MyReq> capture;
|
||||||
pq.remove_by_req_filter(
|
pq.remove_by_req_filter(
|
||||||
[&capture] (const MyReq& r) -> bool {
|
[&capture] (MyReqRef&& r) -> bool {
|
||||||
if (1 == r.id % 2) {
|
if (1 == r->id % 2) {
|
||||||
capture.insert(capture.begin(), r);
|
capture.insert(capture.begin(), *r);
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
@ -448,9 +451,9 @@ namespace crimson {
|
|||||||
|
|
||||||
std::vector<MyReq> capture2;
|
std::vector<MyReq> capture2;
|
||||||
pq.remove_by_req_filter(
|
pq.remove_by_req_filter(
|
||||||
[&capture2] (const MyReq& r) -> bool {
|
[&capture2] (MyReqRef&& r) -> bool {
|
||||||
if (0 == r.id % 2) {
|
if (0 == r->id % 2) {
|
||||||
capture2.push_back(r);
|
capture2.push_back(*r);
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
@ -479,6 +482,7 @@ namespace crimson {
|
|||||||
|
|
||||||
using ClientId = int;
|
using ClientId = int;
|
||||||
using Queue = dmc::PullPriorityQueue<ClientId,MyReq>;
|
using Queue = dmc::PullPriorityQueue<ClientId,MyReq>;
|
||||||
|
using MyReqRef = typename Queue::RequestRef;
|
||||||
|
|
||||||
ClientId client1 = 17;
|
ClientId client1 = 17;
|
||||||
ClientId client2 = 98;
|
ClientId client2 = 98;
|
||||||
@ -513,8 +517,8 @@ namespace crimson {
|
|||||||
|
|
||||||
pq.remove_by_client(client1,
|
pq.remove_by_client(client1,
|
||||||
true,
|
true,
|
||||||
[&removed] (const MyReq& r) {
|
[&removed] (MyReqRef&& r) {
|
||||||
removed.push_front(r);
|
removed.push_front(*r);
|
||||||
});
|
});
|
||||||
|
|
||||||
EXPECT_EQ(3u, removed.size());
|
EXPECT_EQ(3u, removed.size());
|
||||||
|
Loading…
Reference in New Issue
Block a user