Skip to content

Commit

Permalink
Wip: Wip
Browse files Browse the repository at this point in the history
  • Loading branch information
ADKaster committed Jun 28, 2024
1 parent a24c08f commit fef9b03
Show file tree
Hide file tree
Showing 27 changed files with 504 additions and 284 deletions.
20 changes: 0 additions & 20 deletions Ladybird/AppKit/Application/ApplicationBridge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,26 +49,6 @@ ErrorOr<void> ApplicationBridge::launch_image_decoder()
{
m_impl->image_decoder_client = TRY(launch_new_image_decoder());

m_impl->image_decoder_client->on_death = [this] {
m_impl->image_decoder_client = nullptr;
if (auto err = this->launch_image_decoder(); err.is_error()) {
dbgln("Failed to restart image decoder: {}", err.error());
VERIFY_NOT_REACHED();
}

auto num_clients = WebView::WebContentClient::client_count();
auto new_sockets = m_impl->image_decoder_client->send_sync_but_allow_failure<Messages::ImageDecoderServer::ConnectNewClients>(num_clients);
if (!new_sockets || new_sockets->sockets().size() == 0) {
dbgln("Failed to connect {} new clients to ImageDecoder", num_clients);
VERIFY_NOT_REACHED();
}

WebView::WebContentClient::for_each_client([sockets = new_sockets->take_sockets()](WebView::WebContentClient& client) mutable {
client.async_connect_to_image_decoder(sockets.take_last());
return IterationDecision::Continue;
});
};

return {};
}

Expand Down
2 changes: 1 addition & 1 deletion Ladybird/AppKit/Application/ApplicationDelegate.mm
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ @interface ApplicationDelegate () <TaskManagerDelegate>
}

@property (nonatomic, strong) NSMutableArray<TabController*>* managed_tabs;
@property (nonatomic, strong) Tab* active_tab;
@property (nonatomic, weak) Tab* active_tab;

@property (nonatomic, strong) TaskManagerController* task_manager_controller;

Expand Down
11 changes: 8 additions & 3 deletions Ladybird/AppKit/Application/EventLoopImplementation.mm
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ bool have(int handler_id) const

SignalHandlers::SignalHandlers(int signal_number, CFFileDescriptorCallBack handle_signal)
: m_signal_number(signal_number)
, m_original_handler(signal(signal_number, SIG_IGN))
, m_original_handler(signal(signal_number, [](int) {}))
{
m_kevent_fd = kqueue();
if (m_kevent_fd < 0) {
Expand All @@ -100,14 +100,14 @@ bool have(int handler_id) const
}

struct kevent changes = {};
EV_SET(&changes, signal_number, EVFILT_SIGNAL, EV_ADD | EV_RECEIPT, NOTE_EXIT, 0, NULL);
EV_SET(&changes, signal_number, EVFILT_SIGNAL, EV_ADD | EV_RECEIPT, 0, 0, nullptr);
if (auto res = kevent(m_kevent_fd, &changes, 1, &changes, 1, NULL); res < 0) {
dbgln("Unable to register signal {}: {}", signal_number, strerror(errno));
VERIFY_NOT_REACHED();
}

CFFileDescriptorContext context = { 0, this, nullptr, nullptr, nullptr };
CFFileDescriptorRef kq_ref = CFFileDescriptorCreate(kCFAllocatorDefault, m_kevent_fd, TRUE, handle_signal, &context);
CFFileDescriptorRef kq_ref = CFFileDescriptorCreate(kCFAllocatorDefault, m_kevent_fd, FALSE, handle_signal, &context);

m_source = CFFileDescriptorCreateRunLoopSource(kCFAllocatorDefault, kq_ref, 0);
CFRunLoopAddSource(CFRunLoopGetMain(), m_source, kCFRunLoopDefaultMode);
Expand Down Expand Up @@ -137,6 +137,7 @@ bool have(int handler_id) const

void SignalHandlers::dispatch()
{
dbgln("Dispatching signal {}", m_signal_number);
TemporaryChange change(m_calling_handlers, true);
for (auto& handler : m_handlers)
handler.value(m_signal_number);
Expand All @@ -156,6 +157,7 @@ bool have(int handler_id) const

int SignalHandlers::add(Function<void(int)>&& handler)
{
dbgln("Add signal handler for {}", m_signal_number);
int id = ++signals_info()->next_signal_id; // TODO: worry about wrapping and duplicates?
if (m_calling_handlers)
m_handlers_pending.set(id, move(handler));
Expand All @@ -166,6 +168,7 @@ bool have(int handler_id) const

bool SignalHandlers::remove(int handler_id)
{
dbgln("remove signal handler for {}", m_signal_number);
VERIFY(handler_id != 0);
if (m_calling_handlers) {
auto it = m_handlers.find(handler_id);
Expand Down Expand Up @@ -316,6 +319,7 @@ static void socket_notifier(CFSocketRef socket, CFSocketCallBackType notificatio

static void handle_signal(CFFileDescriptorRef f, CFOptionFlags callback_types, void* info)
{
dbgln("Handle signal callback");
VERIFY(callback_types & kCFFileDescriptorReadCallBack);
auto* signal_handlers = static_cast<SignalHandlers*>(info);

Expand All @@ -330,6 +334,7 @@ static void handle_signal(CFFileDescriptorRef f, CFOptionFlags callback_types, v

int CFEventLoopManager::register_signal(int signal_number, Function<void(int)> handler)
{
dbgln("register signal {}", signal_number);
VERIFY(signal_number != 0);
auto& info = *signals_info();
auto handlers = info.signal_handlers.find(signal_number);
Expand Down
Loading

0 comments on commit fef9b03

Please sign in to comment.