File tree Expand file tree Collapse file tree 1 file changed +8
-6
lines changed Expand file tree Collapse file tree 1 file changed +8
-6
lines changed Original file line number Diff line number Diff line change @@ -30,9 +30,7 @@ ConnectionState::~ConnectionState() {
3030}
3131
3232void ConnectionState::clearLock () {
33- if (!workQueue.empty ()) {
34- waitFinished ();
35- }
33+ waitFinished ();
3634 _currentLockId = EMPTY_LOCK_ID;
3735}
3836
@@ -47,9 +45,7 @@ bool ConnectionState::matchesLock(const ConnectionLockId &lockId) {
4745bool ConnectionState::isEmptyLock () { return _currentLockId == EMPTY_LOCK_ID; }
4846
4947void ConnectionState::close () {
50- if (!workQueue.empty ()) {
51- waitFinished ();
52- }
48+ waitFinished ();
5349 // So that the thread can stop (if not already)
5450 threadDone = true ;
5551 sqlite3_close_v2 (connection);
@@ -94,12 +90,18 @@ void ConnectionState::doWork() {
9490 --threadBusy;
9591 // Need to notify in order for waitFinished to be updated when
9692 // the queue is empty and not busy
93+ {
94+ std::unique_lock<std::mutex> g (workQueueMutex);
9795 workQueueConditionVariable.notify_all ();
96+ }
9897 }
9998}
10099
101100void ConnectionState::waitFinished () {
102101 std::unique_lock<std::mutex> g (workQueueMutex);
102+ if (workQueue.empty ()) {
103+ return ;
104+ }
103105 workQueueConditionVariable.wait (
104106 g, [&] { return workQueue.empty () && (threadBusy == 0 ); });
105107}
You can’t perform that action at this time.
0 commit comments