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.
This commit is contained in:
parent
f1d06396a7
commit
ea2ced6b9f
@ -12,7 +12,7 @@
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_URING
|
||||
#include "UringManager.hxx"
|
||||
#include "uring/Manager.hxx"
|
||||
#include "util/PrintException.hxx"
|
||||
#include <stdio.h>
|
||||
#endif
|
||||
|
@ -1,39 +0,0 @@
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
// Copyright The Music Player Daemon Project
|
||||
|
||||
#include "UringManager.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(OnSocketReady),
|
||||
GetFileDescriptor()),
|
||||
idle_event(event_loop, BIND_THIS_METHOD(OnIdle))
|
||||
{
|
||||
event.ScheduleRead();
|
||||
}
|
||||
|
||||
void
|
||||
Manager::OnSocketReady(unsigned) noexcept
|
||||
{
|
||||
try {
|
||||
DispatchCompletions();
|
||||
} catch (...) {
|
||||
PrintException(std::current_exception());
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
Manager::OnIdle() noexcept
|
||||
{
|
||||
try {
|
||||
Queue::Submit();
|
||||
} catch (...) {
|
||||
PrintException(std::current_exception());
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace Uring
|
@ -1,29 +0,0 @@
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
// Copyright The Music Player Daemon Project
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "PipeEvent.hxx"
|
||||
#include "IdleEvent.hxx"
|
||||
#include "io/uring/Queue.hxx"
|
||||
|
||||
namespace Uring {
|
||||
|
||||
class Manager final : public Queue {
|
||||
PipeEvent event;
|
||||
IdleEvent idle_event;
|
||||
|
||||
public:
|
||||
explicit Manager(EventLoop &event_loop,
|
||||
unsigned entries=1024, unsigned flags=0);
|
||||
|
||||
void Submit() override {
|
||||
idle_event.Schedule();
|
||||
}
|
||||
|
||||
private:
|
||||
void OnSocketReady(unsigned flags) noexcept;
|
||||
void OnIdle() noexcept;
|
||||
};
|
||||
|
||||
} // namespace Uring
|
@ -8,7 +8,7 @@ configure_file(output: 'Features.h', configuration: event_features)
|
||||
event_sources = []
|
||||
|
||||
if uring_dep.found()
|
||||
event_sources += 'UringManager.cxx'
|
||||
event_sources += 'uring/Manager.cxx'
|
||||
endif
|
||||
|
||||
if is_windows
|
||||
|
62
src/event/uring/Manager.cxx
Normal file
62
src/event/uring/Manager.cxx
Normal file
@ -0,0 +1,62 @@
|
||||
// SPDX-License-Identifier: BSD-2-Clause
|
||||
// Copyright CM4all GmbH
|
||||
// author: Max Kellermann <mk@cm4all.com>
|
||||
|
||||
#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
|
53
src/event/uring/Manager.hxx
Normal file
53
src/event/uring/Manager.hxx
Normal file
@ -0,0 +1,53 @@
|
||||
// SPDX-License-Identifier: BSD-2-Clause
|
||||
// Copyright CM4all GmbH
|
||||
// author: Max Kellermann <mk@cm4all.com>
|
||||
|
||||
#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
|
Loading…
x
Reference in New Issue
Block a user