Skip to content

Commit ea2ced6

Browse files
committed
event/UringManager: replace with new Uring::Manager class
From https://github.com/CM4all/libcommon - the new class is mostly identical, and I want to maintain only one of them.
1 parent f1d0639 commit ea2ced6

File tree

6 files changed

+117
-70
lines changed

6 files changed

+117
-70
lines changed

src/event/Loop.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
#endif
1313

1414
#ifdef HAVE_URING
15-
#include "UringManager.hxx"
15+
#include "uring/Manager.hxx"
1616
#include "util/PrintException.hxx"
1717
#include <stdio.h>
1818
#endif

src/event/UringManager.cxx

Lines changed: 0 additions & 39 deletions
This file was deleted.

src/event/UringManager.hxx

Lines changed: 0 additions & 29 deletions
This file was deleted.

src/event/meson.build

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ configure_file(output: 'Features.h', configuration: event_features)
88
event_sources = []
99

1010
if uring_dep.found()
11-
event_sources += 'UringManager.cxx'
11+
event_sources += 'uring/Manager.cxx'
1212
endif
1313

1414
if is_windows

src/event/uring/Manager.cxx

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
// SPDX-License-Identifier: BSD-2-Clause
2+
// Copyright CM4all GmbH
3+
// author: Max Kellermann <mk@cm4all.com>
4+
5+
#include "Manager.hxx"
6+
#include "util/PrintException.hxx"
7+
8+
namespace Uring {
9+
10+
Manager::Manager(EventLoop &event_loop,
11+
unsigned entries, unsigned flags)
12+
:Queue(entries, flags),
13+
event(event_loop, BIND_THIS_METHOD(OnReady), GetFileDescriptor())
14+
{
15+
event.ScheduleRead();
16+
}
17+
18+
Manager::Manager(EventLoop &event_loop,
19+
unsigned entries, struct io_uring_params &params)
20+
:Queue(entries, params),
21+
event(event_loop, BIND_THIS_METHOD(OnReady), GetFileDescriptor())
22+
{
23+
event.ScheduleRead();
24+
}
25+
26+
void
27+
Manager::Submit()
28+
{
29+
/* defer in "idle" mode to allow accumulation of more
30+
events */
31+
defer_submit_event.ScheduleIdle();
32+
}
33+
34+
void
35+
Manager::DispatchCompletions() noexcept
36+
{
37+
try {
38+
Queue::DispatchCompletions();
39+
} catch (...) {
40+
PrintException(std::current_exception());
41+
}
42+
43+
CheckVolatileEvent();
44+
}
45+
46+
inline void
47+
Manager::OnReady(unsigned) noexcept
48+
{
49+
DispatchCompletions();
50+
}
51+
52+
void
53+
Manager::DeferredSubmit() noexcept
54+
{
55+
try {
56+
Queue::Submit();
57+
} catch (...) {
58+
PrintException(std::current_exception());
59+
}
60+
}
61+
62+
} // namespace Uring

src/event/uring/Manager.hxx

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
// SPDX-License-Identifier: BSD-2-Clause
2+
// Copyright CM4all GmbH
3+
// author: Max Kellermann <mk@cm4all.com>
4+
5+
#pragma once
6+
7+
#include "io/uring/Queue.hxx"
8+
#include "event/DeferEvent.hxx"
9+
#include "event/PipeEvent.hxx"
10+
11+
namespace Uring {
12+
13+
class Manager final : public Queue {
14+
PipeEvent event;
15+
16+
/**
17+
* Responsible for invoking Queue::Submit() only once per
18+
* #EventLoop iteration.
19+
*/
20+
DeferEvent defer_submit_event{GetEventLoop(), BIND_THIS_METHOD(DeferredSubmit)};
21+
22+
bool volatile_event = false;
23+
24+
public:
25+
explicit Manager(EventLoop &event_loop,
26+
unsigned entries=1024, unsigned flags=0);
27+
explicit Manager(EventLoop &event_loop,
28+
unsigned entries, struct io_uring_params &params);
29+
30+
EventLoop &GetEventLoop() const noexcept {
31+
return event.GetEventLoop();
32+
}
33+
34+
void SetVolatile() noexcept {
35+
volatile_event = true;
36+
CheckVolatileEvent();
37+
}
38+
39+
// virtual methods from class Uring::Queue
40+
void Submit() override;
41+
42+
private:
43+
void CheckVolatileEvent() noexcept {
44+
if (volatile_event && !HasPending())
45+
event.Cancel();
46+
}
47+
48+
void DispatchCompletions() noexcept;
49+
void OnReady(unsigned events) noexcept;
50+
void DeferredSubmit() noexcept;
51+
};
52+
53+
} // namespace Uring

0 commit comments

Comments
 (0)