Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
14 changes: 0 additions & 14 deletions src/common/ThreadStart.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -219,11 +219,6 @@ ThreadId Thread::getId()
#endif
}

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

bool Thread::isCurrent(InternalId iid)
{
return pthread_equal(iid, pthread_self());
Expand Down Expand Up @@ -373,11 +368,6 @@ ThreadId Thread::getId()
return GetCurrentThreadId();
}

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

bool Thread::isCurrent(InternalId iid)
{
return GetCurrentThreadId() == iid;
Expand Down Expand Up @@ -430,10 +420,6 @@ Thread::Handle Thread::getId()
{
}

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

void Thread::sleep(unsigned milliseconds)
{
}
Expand Down
8 changes: 7 additions & 1 deletion src/common/ThreadStart.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,14 @@ class Thread
static void waitForCompletion(Handle& handle);
static void kill(Handle& handle);

// Returns TID of current OS thread
static ThreadId getId();
static ThreadId getIdFromHandle(Handle threadHandle);

// Returns internal ID of given thread instance
InternalId getInternalId() const
{
return internalId;
}

static void sleep(unsigned milliseconds);
static void yield();
Expand Down
5 changes: 4 additions & 1 deletion src/jrd/CryptoManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,8 @@ namespace Jrd {
flDown(false),
run(false)
{
memset(&cryptThreadId, 0, sizeof(cryptThreadId));

stateLock = FB_NEW_RPT(getPool(), 0)
Lock(tdbb, 0, LCK_crypt_status, this, blockingAstChangeCryptState);
threadLock = FB_NEW_RPT(getPool(), 0) Lock(tdbb, 0, LCK_crypt);
Expand Down Expand Up @@ -995,7 +997,8 @@ namespace Jrd {

// ready to go
guard.leave(); // release in advance to avoid races with cryptThread()
Thread::start(cryptThreadStatic, (THREAD_ENTRY_PARAM) this, THREAD_medium, &cryptThreadHandle);
const Thread& thread = Thread::start(cryptThreadStatic, (THREAD_ENTRY_PARAM) this, THREAD_medium, &cryptThreadHandle);
cryptThreadId = thread.getInternalId();
}
catch (const Firebird::Exception&)
{
Expand Down
7 changes: 5 additions & 2 deletions src/jrd/CryptoManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -302,9 +302,11 @@ class CryptoManager FB_FINAL : public Firebird::PermanentStorage, public BarSync
ULONG getCurrentPage(thread_db* tdbb) const;
UCHAR getCurrentState(thread_db* tdbb) const;
const char* getKeyName() const;
Thread::Handle getCryptThreadHandle() const

// Return true if crypt thread is running and it is the current thread.
bool isCryptThreadCurrent() const
{
return cryptThreadHandle;
return cryptThreadHandle && Thread::isCurrent(cryptThreadId);
}

private:
Expand Down Expand Up @@ -393,6 +395,7 @@ class CryptoManager FB_FINAL : public Firebird::PermanentStorage, public BarSync
Firebird::string hash;
Firebird::RefPtr<DbInfo> dbInfo;
Thread::Handle cryptThreadHandle;
Thread::InternalId cryptThreadId;
Firebird::IDbCryptPlugin* cryptPlugin;
Factory* checkFactory;
Database& dbb;
Expand Down
3 changes: 1 addition & 2 deletions src/jrd/jrd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6440,8 +6440,7 @@ static void release_attachment(thread_db* tdbb, Jrd::Attachment* attachment)
// avoid races with special threads
XThreadEnsureUnlock threadGuard(dbb->dbb_thread_mutex, FB_FUNCTION);
XThreadEnsureUnlock* activeThreadGuard = &threadGuard;
if (dbb->dbb_crypto_manager
&& Thread::isCurrent(Thread::getIdFromHandle(dbb->dbb_crypto_manager->getCryptThreadHandle())))
if (dbb->dbb_crypto_manager && dbb->dbb_crypto_manager->isCryptThreadCurrent())
{
activeThreadGuard = &dummyGuard;
}
Expand Down
Loading