mirror of
https://github.com/mawww/kakoune.git
synced 2024-11-15 18:15:53 +03:00
Defer deletion of buffers to after the event loop
We can have SelectionList in flights on the buffer, so mark it for deletion by moving it in a buffer trash, and effectively delete it later, at a point where there should not be any further access to it.
This commit is contained in:
parent
e2b3dd0ca4
commit
2204b7cf06
@ -41,6 +41,14 @@ void BufferManager::unregister_buffer(Buffer& buffer)
|
||||
return;
|
||||
}
|
||||
}
|
||||
for (auto it = m_buffer_trash.begin(); it != m_buffer_trash.end(); ++it)
|
||||
{
|
||||
if (*it == &buffer)
|
||||
{
|
||||
m_buffer_trash.erase(it);
|
||||
return;
|
||||
}
|
||||
}
|
||||
kak_assert(false);
|
||||
}
|
||||
|
||||
@ -52,7 +60,9 @@ void BufferManager::delete_buffer(Buffer& buffer)
|
||||
{
|
||||
if (ClientManager::has_instance())
|
||||
ClientManager::instance().ensure_no_client_uses_buffer(buffer);
|
||||
delete it->get();
|
||||
|
||||
m_buffers.erase(it);
|
||||
m_buffer_trash.emplace_back(&buffer);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -121,4 +131,10 @@ CandidateList BufferManager::complete_buffer_name(StringView prefix,
|
||||
return result.empty() ? subsequence_result : result;
|
||||
}
|
||||
|
||||
void BufferManager::clear_buffer_trash()
|
||||
{
|
||||
while (not m_buffer_trash.empty())
|
||||
delete m_buffer_trash.back().get();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -37,8 +37,10 @@ public:
|
||||
CandidateList complete_buffer_name(StringView prefix,
|
||||
ByteCount cursor_pos = -1);
|
||||
|
||||
void clear_buffer_trash();
|
||||
private:
|
||||
BufferList m_buffers;
|
||||
BufferList m_buffer_trash;
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -39,6 +39,9 @@ public:
|
||||
Context& context() { return m_input_handler.context(); }
|
||||
const Context& context() const { return m_input_handler.context(); }
|
||||
|
||||
InputHandler& input_handler() { return m_input_handler; }
|
||||
const InputHandler& input_handler() const { return m_input_handler; }
|
||||
|
||||
void change_buffer(Buffer& buffer);
|
||||
|
||||
const String& get_env_var(const String& name) const;
|
||||
|
@ -170,6 +170,12 @@ void ClientManager::redraw_clients() const
|
||||
client->redraw_ifn();
|
||||
}
|
||||
|
||||
void ClientManager::clear_mode_trashes() const
|
||||
{
|
||||
for (auto& client : m_clients)
|
||||
client->input_handler().clear_mode_trash();
|
||||
}
|
||||
|
||||
CandidateList ClientManager::complete_client_name(StringView prefix,
|
||||
ByteCount cursor_pos) const
|
||||
{
|
||||
|
@ -34,6 +34,7 @@ public:
|
||||
void add_free_window(std::unique_ptr<Window>&& window, SelectionList selections);
|
||||
|
||||
void redraw_clients() const;
|
||||
void clear_mode_trashes() const;
|
||||
|
||||
Client* get_client_ifp(const String& name);
|
||||
Client& get_client(const String& name);
|
||||
|
@ -1,5 +1,4 @@
|
||||
#include "event_manager.hh"
|
||||
#include "client_manager.hh"
|
||||
|
||||
#include <poll.h>
|
||||
|
||||
@ -82,9 +81,6 @@ void EventManager::handle_next_events()
|
||||
if (timer->next_date() <= now)
|
||||
timer->run();
|
||||
}
|
||||
|
||||
if (ClientManager::has_instance())
|
||||
ClientManager::instance().redraw_clients();
|
||||
}
|
||||
|
||||
void EventManager::force_signal(int fd)
|
||||
|
@ -421,7 +421,12 @@ int kakoune(const ParametersParser& parser)
|
||||
create_local_client(init_command);
|
||||
|
||||
while (not terminate and (not client_manager.empty() or daemon))
|
||||
{
|
||||
event_manager.handle_next_events();
|
||||
client_manager.clear_mode_trashes();
|
||||
buffer_manager.clear_buffer_trash();
|
||||
client_manager.redraw_clients();
|
||||
}
|
||||
|
||||
{
|
||||
Context empty_context;
|
||||
|
Loading…
Reference in New Issue
Block a user