Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 26 additions & 2 deletions src/common/ThreadStart.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -219,9 +219,19 @@ ThreadId Thread::getId()
#endif
}

ThreadId Thread::getIdFromHandle(Handle threadHandle)
{
return threadHandle;
}

bool Thread::isCurrent(InternalId iid)
{
return pthread_equal(iid, pthread_self());
}

bool Thread::isCurrent()
{
return pthread_equal(internalId, pthread_self());
return isCurrent(internalId);
}

void Thread::sleep(unsigned milliseconds)
Expand Down Expand Up @@ -363,9 +373,19 @@ ThreadId Thread::getId()
return GetCurrentThreadId();
}

ThreadId Thread::getIdFromHandle(Handle threadHandle)
{
return GetThreadId(threadHandle);
}

bool Thread::isCurrent(InternalId iid)
{
return GetCurrentThreadId() == iid;
}

bool Thread::isCurrent()
{
return GetCurrentThreadId() == internalId;
return isCurrent(internalId);
}

void Thread::sleep(unsigned milliseconds)
Expand Down Expand Up @@ -410,6 +430,10 @@ Thread::Handle Thread::getId()
{
}

Thread::Handle Thread::getIdFromHandle(Handle)
{
}

void Thread::sleep(unsigned milliseconds)
{
}
Expand Down
2 changes: 2 additions & 0 deletions src/common/ThreadStart.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,12 @@ class Thread
static void kill(Handle& handle);

static ThreadId getId();
static ThreadId getIdFromHandle(Handle threadHandle);

static void sleep(unsigned milliseconds);
static void yield();

static bool isCurrent(InternalId iid);
bool isCurrent();

Thread()
Expand Down
4 changes: 4 additions & 0 deletions src/jrd/CryptoManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,10 @@ class CryptoManager final : public Firebird::PermanentStorage, public BarSync::I
UCHAR getCurrentState(thread_db* tdbb) const;
const char* getKeyName() const;
const char* getPluginName() const;
Thread::Handle getCryptThreadHandle() const
{
return cryptThreadId;
}

private:
enum IoResult {SUCCESS_ALL, FAILED_CRYPT, FAILED_IO};
Expand Down
16 changes: 14 additions & 2 deletions src/jrd/jrd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7755,14 +7755,26 @@ void release_attachment(thread_db* tdbb, Jrd::Attachment* attachment, XThreadEns

Sync sync(&dbb->dbb_sync, "jrd.cpp: release_attachment");

// dummy mutex is used to avoid races with crypto thread
XThreadMutex dummy_mutex;
XThreadEnsureUnlock dummyGuard(dummy_mutex, FB_FUNCTION);

// avoid races with special threads
// take into an account lock earlier taken in DROP DATABASE
XThreadEnsureUnlock threadGuard(dbb->dbb_thread_mutex, FB_FUNCTION);
XThreadEnsureUnlock* activeThreadGuard = dropGuard;
if (!activeThreadGuard)
{
threadGuard.enter();
activeThreadGuard = &threadGuard;
if (dbb->dbb_crypto_manager
&& Thread::isCurrent(Thread::getIdFromHandle(dbb->dbb_crypto_manager->getCryptThreadHandle())))
{
activeThreadGuard = &dummyGuard;
}
else
{
activeThreadGuard = &threadGuard;
}
activeThreadGuard->enter();
}

sync.lock(SYNC_EXCLUSIVE);
Expand Down
Loading