1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-11-23 17:30:17 +01:00

Bug 2673 - Win: Mixer Board problem on Windows - causes crash

This commit is contained in:
Leland Lucius
2021-02-22 19:27:02 -06:00
parent 463058e20c
commit 53f7cacdb2
2 changed files with 15 additions and 21 deletions

View File

@@ -165,12 +165,15 @@ bool DBConnection::Close()
mCheckpointThread.join(); mCheckpointThread.join();
// We're done with the prepared statements // We're done with the prepared statements
{
std::lock_guard<std::mutex> guard(mStatementMutex);
for (auto stmt : mStatements) for (auto stmt : mStatements)
{ {
// No need to check return code. // No need to check return code.
sqlite3_finalize(stmt.second); sqlite3_finalize(stmt.second);
} }
mStatements.clear(); mStatements.clear();
}
// Close the DB // Close the DB
rc = sqlite3_close(mDB); rc = sqlite3_close(mDB);
@@ -248,10 +251,13 @@ const wxString DBConnection::GetLastMessage() const
sqlite3_stmt *DBConnection::Prepare(enum StatementID id, const char *sql) sqlite3_stmt *DBConnection::Prepare(enum StatementID id, const char *sql)
{ {
std::lock_guard<std::mutex> guard(mStatementMutex);
int rc; int rc;
StatementIndex ndx(id, std::this_thread::get_id());
// Return an existing statement if it's already been prepared // Return an existing statement if it's already been prepared
auto iter = mStatements.find(id); auto iter = mStatements.find(ndx);
if (iter != mStatements.end()) if (iter != mStatements.end())
{ {
return iter->second; return iter->second;
@@ -267,24 +273,11 @@ sqlite3_stmt *DBConnection::Prepare(enum StatementID id, const char *sql)
} }
// And remember it // And remember it
mStatements.insert({id, stmt}); mStatements.insert({ndx, stmt});
return stmt; return stmt;
} }
sqlite3_stmt *DBConnection::GetStatement(enum StatementID id)
{
// Look it up
auto iter = mStatements.find(id);
// It should always be there
wxASSERT(iter != mStatements.end());
// Return it
return iter->second;
}
void DBConnection::CheckpointThread() void DBConnection::CheckpointThread()
{ {
// Open another connection to the DB to prevent blocking the main thread. // Open another connection to the DB to prevent blocking the main thread.

View File

@@ -76,7 +76,6 @@ public:
GetRootPage, GetRootPage,
GetDBPage GetDBPage
}; };
sqlite3_stmt *GetStatement(enum StatementID id);
sqlite3_stmt *Prepare(enum StatementID id, const char *sql); sqlite3_stmt *Prepare(enum StatementID id, const char *sql);
void SetBypass( bool bypass ); void SetBypass( bool bypass );
@@ -109,7 +108,9 @@ private:
std::atomic_bool mCheckpointPending{ false }; std::atomic_bool mCheckpointPending{ false };
std::atomic_bool mCheckpointActive{ false }; std::atomic_bool mCheckpointActive{ false };
std::map<enum StatementID, sqlite3_stmt *> mStatements; std::mutex mStatementMutex;
using StatementIndex = std::pair<enum StatementID, std::thread::id>;
std::map<StatementIndex, sqlite3_stmt *> mStatements;
std::shared_ptr<DBConnectionErrors> mpErrors; std::shared_ptr<DBConnectionErrors> mpErrors;
CheckpointFailureCallback mCallback; CheckpointFailureCallback mCallback;