Skip to content

Commit e954fe0

Browse files
committed
Avoid implicit Handle(pthread_t) -> ThreadId(int) -> InternalId(pthread_t) conversions that does not work properly (it mangles the value on my Linux box, causing deadlocks in exactly the same place that was fixed by PR #8403)
1 parent a462bb8 commit e954fe0

File tree

3 files changed

+10
-24
lines changed

3 files changed

+10
-24
lines changed

src/common/ThreadStart.cpp

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -219,19 +219,15 @@ ThreadId Thread::getId()
219219
#endif
220220
}
221221

222-
ThreadId Thread::getIdFromHandle(Handle threadHandle)
222+
bool Thread::isCurrent(Handle threadHandle)
223223
{
224-
return threadHandle;
225-
}
226-
227-
bool Thread::isCurrent(InternalId iid)
228-
{
229-
return pthread_equal(iid, pthread_self());
224+
static_assert(std::is_same<Handle, InternalId>().value, "type mismatch");
225+
return pthread_equal(threadHandle, pthread_self());
230226
}
231227

232228
bool Thread::isCurrent()
233229
{
234-
return isCurrent(internalId);
230+
return pthread_equal(internalId, pthread_self());
235231
}
236232

237233
void Thread::sleep(unsigned milliseconds)
@@ -373,19 +369,14 @@ ThreadId Thread::getId()
373369
return GetCurrentThreadId();
374370
}
375371

376-
ThreadId Thread::getIdFromHandle(Handle threadHandle)
372+
bool Thread::isCurrent(Handle threadHandle)
377373
{
378-
return GetThreadId(threadHandle);
379-
}
380-
381-
bool Thread::isCurrent(InternalId iid)
382-
{
383-
return GetCurrentThreadId() == iid;
374+
return GetCurrentThreadId() == GetThreadId(threadHandle);
384375
}
385376

386377
bool Thread::isCurrent()
387378
{
388-
return isCurrent(internalId);
379+
return GetCurrentThreadId() == internalId;
389380
}
390381

391382
void Thread::sleep(unsigned milliseconds)
@@ -430,10 +421,6 @@ Thread::Handle Thread::getId()
430421
{
431422
}
432423

433-
Thread::Handle Thread::getIdFromHandle(Handle)
434-
{
435-
}
436-
437424
void Thread::sleep(unsigned milliseconds)
438425
{
439426
}

src/common/ThreadStart.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,12 +83,11 @@ class Thread
8383
static void kill(Handle& handle);
8484

8585
static ThreadId getId();
86-
static ThreadId getIdFromHandle(Handle threadHandle);
8786

8887
static void sleep(unsigned milliseconds);
8988
static void yield();
9089

91-
static bool isCurrent(InternalId iid);
90+
static bool isCurrent(Handle threadHandle);
9291
bool isCurrent();
9392

9493
Thread()

src/jrd/jrd.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7830,8 +7830,8 @@ void release_attachment(thread_db* tdbb, Jrd::Attachment* attachment, XThreadEns
78307830
XThreadEnsureUnlock* activeThreadGuard = dropGuard;
78317831
if (!activeThreadGuard)
78327832
{
7833-
if (dbb->dbb_crypto_manager
7834-
&& Thread::isCurrent(Thread::getIdFromHandle(dbb->dbb_crypto_manager->getCryptThreadHandle())))
7833+
if (dbb->dbb_crypto_manager &&
7834+
Thread::isCurrent(dbb->dbb_crypto_manager->getCryptThreadHandle()))
78357835
{
78367836
activeThreadGuard = &dummyGuard;
78377837
}

0 commit comments

Comments
 (0)