-
Notifications
You must be signed in to change notification settings - Fork 358
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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.
- Loading branch information
1 parent
f1d0639
commit ea2ced6
Showing
6 changed files
with
117 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
// SPDX-License-Identifier: BSD-2-Clause | ||
// Copyright CM4all GmbH | ||
// author: Max Kellermann <[email protected]> | ||
|
||
#include "Manager.hxx" | ||
#include "util/PrintException.hxx" | ||
|
||
namespace Uring { | ||
|
||
Manager::Manager(EventLoop &event_loop, | ||
unsigned entries, unsigned flags) | ||
:Queue(entries, flags), | ||
event(event_loop, BIND_THIS_METHOD(OnReady), GetFileDescriptor()) | ||
{ | ||
event.ScheduleRead(); | ||
} | ||
|
||
Manager::Manager(EventLoop &event_loop, | ||
unsigned entries, struct io_uring_params ¶ms) | ||
:Queue(entries, params), | ||
event(event_loop, BIND_THIS_METHOD(OnReady), GetFileDescriptor()) | ||
{ | ||
event.ScheduleRead(); | ||
} | ||
|
||
void | ||
Manager::Submit() | ||
{ | ||
/* defer in "idle" mode to allow accumulation of more | ||
events */ | ||
defer_submit_event.ScheduleIdle(); | ||
} | ||
|
||
void | ||
Manager::DispatchCompletions() noexcept | ||
{ | ||
try { | ||
Queue::DispatchCompletions(); | ||
} catch (...) { | ||
PrintException(std::current_exception()); | ||
} | ||
|
||
CheckVolatileEvent(); | ||
} | ||
|
||
inline void | ||
Manager::OnReady(unsigned) noexcept | ||
{ | ||
DispatchCompletions(); | ||
} | ||
|
||
void | ||
Manager::DeferredSubmit() noexcept | ||
{ | ||
try { | ||
Queue::Submit(); | ||
} catch (...) { | ||
PrintException(std::current_exception()); | ||
} | ||
} | ||
|
||
} // namespace Uring |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// SPDX-License-Identifier: BSD-2-Clause | ||
// Copyright CM4all GmbH | ||
// author: Max Kellermann <[email protected]> | ||
|
||
#pragma once | ||
|
||
#include "io/uring/Queue.hxx" | ||
#include "event/DeferEvent.hxx" | ||
#include "event/PipeEvent.hxx" | ||
|
||
namespace Uring { | ||
|
||
class Manager final : public Queue { | ||
PipeEvent event; | ||
|
||
/** | ||
* Responsible for invoking Queue::Submit() only once per | ||
* #EventLoop iteration. | ||
*/ | ||
DeferEvent defer_submit_event{GetEventLoop(), BIND_THIS_METHOD(DeferredSubmit)}; | ||
|
||
bool volatile_event = false; | ||
|
||
public: | ||
explicit Manager(EventLoop &event_loop, | ||
unsigned entries=1024, unsigned flags=0); | ||
explicit Manager(EventLoop &event_loop, | ||
unsigned entries, struct io_uring_params ¶ms); | ||
|
||
EventLoop &GetEventLoop() const noexcept { | ||
return event.GetEventLoop(); | ||
} | ||
|
||
void SetVolatile() noexcept { | ||
volatile_event = true; | ||
CheckVolatileEvent(); | ||
} | ||
|
||
// virtual methods from class Uring::Queue | ||
void Submit() override; | ||
|
||
private: | ||
void CheckVolatileEvent() noexcept { | ||
if (volatile_event && !HasPending()) | ||
event.Cancel(); | ||
} | ||
|
||
void DispatchCompletions() noexcept; | ||
void OnReady(unsigned events) noexcept; | ||
void DeferredSubmit() noexcept; | ||
}; | ||
|
||
} // namespace Uring |