8
0
mirror of https://github.com/FirebirdSQL/firebird.git synced 2025-01-22 23:23:02 +01:00

Fixed issues with shutdown thread, reported by Ilya Eremin privately

(cherry picked from commit dd1593b67d)
This commit is contained in:
AlexPeshkoff 2022-07-21 14:47:12 +03:00
parent 06e9f5daae
commit 4c4d0b142b
3 changed files with 24 additions and 4 deletions

View File

@ -936,6 +936,11 @@ public:
iter.remove();
}
bool hasData() const
{
return m_attachments.hasData();
}
private:
AttachmentsRefHolder(const AttachmentsRefHolder&);

View File

@ -118,13 +118,13 @@ namespace Jrd {
while (thr.hasData())
{
FB_SIZE_T n = thr.getCount() - 1;
Thrd& t = thr[n];
Thrd t = thr[n];
thr.remove(n);
{
Firebird::MutexUnlockGuard u(threadsMutex, FB_FUNCTION);
Thread::waitForCompletion(t.hndl);
fb_assert(t.ending);
}
thr.remove(n);
}
}

View File

@ -482,7 +482,7 @@ namespace
struct AttShutParams
{
Semaphore thdStartedSem;
Semaphore thdStartedSem, startCallCompleteSem;
Thread::Handle thrHandle;
AttachmentsRefHolder* attachments;
};
@ -8699,6 +8699,17 @@ namespace
AttShutParams* params = static_cast<AttShutParams*>(arg);
AttachmentsRefHolder* attachments = params->attachments;
try
{
params->startCallCompleteSem.enter();
}
catch (const Exception& ex)
{
iscLogException("attachmentShutdownThread", ex);
return 0;
}
Thread::Handle th = params->thrHandle;
fb_assert(th);
@ -9550,6 +9561,8 @@ void JRD_shutdown_attachment(Attachment* attachment)
AttShutParams params;
params.attachments = queue;
Thread::start(attachmentShutdownThread, &params, THREAD_high, &params.thrHandle);
params.startCallCompleteSem.release();
queue.release();
shutThreadCollect->houseKeeping();
params.thdStartedSem.enter();
@ -9600,11 +9613,13 @@ void JRD_shutdown_attachments(Database* dbb)
}
}
if (queue.hasData())
if (queue->hasData())
{
AttShutParams params;
params.attachments = queue;
Thread::start(attachmentShutdownThread, &params, THREAD_high, &params.thrHandle);
params.startCallCompleteSem.release();
queue.release();
shutThreadCollect->houseKeeping();
params.thdStartedSem.enter();