Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Lifetime issues in the file manager #257

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions parser_library/src/workspaces/file_manager_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ namespace hlasm_plugin::parser_library::workspaces {
// Implementation of the file_manager interface.
class file_manager_impl : public file_manager, public diagnosable_impl
{
mutable std::mutex files_mutex;
mutable std::mutex virtual_files_mutex;
std::atomic<bool>* cancel_;

public:
file_manager_impl(std::atomic<bool>* cancel = nullptr)
: cancel_(cancel) {};
Expand Down Expand Up @@ -66,15 +70,11 @@ class file_manager_impl : public file_manager, public diagnosable_impl
std::string get_virtual_file(unsigned long long id) const override;

protected:
std::unordered_map<std::string, std::shared_ptr<file_impl>> files_;
std::unordered_map<unsigned long long, std::string> m_virtual_files;
// m_virtual_files must outlive the files_
std::unordered_map<std::string, std::shared_ptr<file_impl>> files_;

private:
mutable std::mutex files_mutex;
mutable std::mutex virtual_files_mutex;

std::atomic<bool>* cancel_;

processor_file_ptr change_into_processor_file_if_not_already_(std::shared_ptr<file_impl>& ret);
void prepare_file_for_change_(std::shared_ptr<file_impl>& file);
};
Expand Down
10 changes: 10 additions & 0 deletions parser_library/test/workspace/virtual_files_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,3 +163,13 @@ TEST(virtual_files, workspace)
wm.did_open_file("ws/file", 1, input.data(), input.size());
wm.did_close_file("ws/file");
}

TEST(virtual_files, workspace_auto_cleanup)
{
workspace_manager wm;
wm.add_workspace("ws", "ws");
std::string_view input = R"(
AINSERT 'A DC H',BACK
)";
wm.did_open_file("ws/file", 1, input.data(), input.size());
}