Skip to content

Commit

Permalink
Test: Call repo->load in main thread
Browse files Browse the repository at this point in the history
  • Loading branch information
jrohel committed Feb 21, 2023
1 parent fcc85a3 commit bb204ba
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions libdnf/repo/repo_sack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -198,14 +198,15 @@ void RepoSack::update_and_load_repos(libdnf::repo::RepoQuery & repos) {
std::vector<libdnf::repo::Repo *> prepared_repos; // array of repositories prepared to load into solv sack
std::mutex prepared_repos_mutex; // mutex for the array
std::condition_variable signal_prepared_repo; // signals that next item is added into array
std::size_t num_repos_loaded{0}; // number of repositories already loaded into solv sack
//std::size_t num_repos_loaded{0}; // number of repositories already loaded into solv sack

prepared_repos.reserve(repos.size() + 1); // optimization: preallocate memory to avoid realocations, +1 stop tag

// This thread loads prepared repositories into solvable sack
std::thread thread_sack_loader([&]() {
try {
while (true) {
return;
/*while (true) {
std::unique_lock<std::mutex> lock(prepared_repos_mutex);
while (prepared_repos.size() <= num_repos_loaded) {
signal_prepared_repo.wait(lock);
Expand All @@ -219,7 +220,7 @@ void RepoSack::update_and_load_repos(libdnf::repo::RepoQuery & repos) {
repo->load();
++num_repos_loaded;
}
}*/
} catch (std::runtime_error & ex) {
// The thread must not throw exceptions. Pass them to the main thread using exception_ptr.
except_ptr = std::current_exception();
Expand Down Expand Up @@ -250,6 +251,7 @@ void RepoSack::update_and_load_repos(libdnf::repo::RepoQuery & repos) {
// If the input RepoQuery contains a system repo, we load the system repo first.
for (auto & repo : repos) {
if (repo->get_type() == libdnf::repo::Repo::Type::SYSTEM) {
repo->load();
{
std::lock_guard<std::mutex> lock(prepared_repos_mutex);
prepared_repos.push_back(repo.get());
Expand All @@ -268,7 +270,7 @@ void RepoSack::update_and_load_repos(libdnf::repo::RepoQuery & repos) {
catch_thread_sack_loader_exceptions();
try {
repo->fetch_metadata();

repo->load();
{
std::lock_guard<std::mutex> lock(prepared_repos_mutex);
prepared_repos.push_back(repo.get());
Expand Down

0 comments on commit bb204ba

Please sign in to comment.