Make commandline state thread safe

Today the reader exposes its internals directly, e.g. to the commandline
builtin. This is of course not thread safe. For example in concurrent
execution, running `commandline` twice in separate threads would cause a
race and likely a crash.

Fix this by factoring all the commandline state into a new type
'commandline_state_t'. Make it a singleton (there is only one command
line
after all) and protect it with a lock.

No user visible change here.
This commit is contained in:
ridiculousfish
2021-07-20 13:18:03 -07:00
parent 49c8ed9765
commit a32248277f
8 changed files with 146 additions and 122 deletions

View File

@@ -729,7 +729,7 @@ maybe_t<env_var_t> env_scoped_impl_t::try_get_computed(const wcstring &key) cons
return none();
}
std::shared_ptr<history_t> history = reader_get_history();
std::shared_ptr<history_t> history = commandline_get_state().history;
if (!history) {
history = history_t::with_name(history_session_id(*this));
}