Skip to content

Commit

Permalink
fix unique_lock starvation and extension loading
Browse files Browse the repository at this point in the history
  • Loading branch information
Artikash committed Feb 13, 2019
1 parent 4eefafe commit 855f8eb
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions GUI/extenwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,18 @@ namespace
wchar_t*(*callback)(wchar_t*, const InfoForExtension*);
};

class : std::shared_mutex
{
public:
void lock() { ++queuedWrites; shared_mutex::lock(); }
void unlock() { --queuedWrites; shared_mutex::unlock(); }
void lock_shared() { while (queuedWrites) Sleep(100); shared_mutex::lock_shared(); }
void unlock_shared() { shared_mutex::unlock_shared(); }

private:
std::atomic<int> queuedWrites = 0;
} extenMutex;
std::vector<Extension> extensions;
std::shared_mutex extenMutex;

void Load(QString extenName)
{
Expand All @@ -44,7 +54,7 @@ namespace
{
std::scoped_lock writeLock(extenMutex);
std::vector<Extension> extensions;
for (auto extenName : extenNames)
for (auto extenName : extenNames)
extensions.push_back(*std::find_if(::extensions.begin(), ::extensions.end(), [&](auto extension) { return extension.name == S(extenName); }));
::extensions = extensions;
}
Expand Down Expand Up @@ -105,7 +115,7 @@ void ExtenWindow::Sync()
void ExtenWindow::Add(QFileInfo extenFile)
{
if (extenFile.suffix() != "dll") return;
QFile::copy(extenFile.fileName(), extenFile.absoluteFilePath());
QFile::copy(extenFile.absoluteFilePath(), extenFile.fileName());
Load(extenFile.completeBaseName());
Sync();
}
Expand Down

0 comments on commit 855f8eb

Please sign in to comment.