Skip to content

Commit

Permalink
event/UringManager: replace with new Uring::Manager class
Browse files Browse the repository at this point in the history
From https://github.com/CM4all/libcommon - the new class is mostly
identical, and I want to maintain only one of them.
  • Loading branch information
MaxKellermann committed Jan 29, 2025
1 parent f1d0639 commit ea2ced6
Show file tree
Hide file tree
Showing 6 changed files with 117 additions and 70 deletions.
2 changes: 1 addition & 1 deletion src/event/Loop.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#endif

#ifdef HAVE_URING
#include "UringManager.hxx"
#include "uring/Manager.hxx"
#include "util/PrintException.hxx"
#include <stdio.h>
#endif
Expand Down
39 changes: 0 additions & 39 deletions src/event/UringManager.cxx

This file was deleted.

29 changes: 0 additions & 29 deletions src/event/UringManager.hxx

This file was deleted.

2 changes: 1 addition & 1 deletion src/event/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
62 changes: 62 additions & 0 deletions src/event/uring/Manager.cxx
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 &params)
: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 changes: 53 additions & 0 deletions src/event/uring/Manager.hxx
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 &params);

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

0 comments on commit ea2ced6

Please sign in to comment.