Skip to content
Merged
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
2 changes: 1 addition & 1 deletion builds/posix/make.shared.variables
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ Engine_Objects:= $(call dirObjects,jrd) $(call dirObjects,dsql) $(call dirObject
$(call dirObjects,jrd/sys-packages) $(call dirObjects,jrd/trace) \
$(call makeObjects,lock,lock.cpp)

Engine_Test_Objects:= $(call dirObjects,jrd/tests)
Engine_Test_Objects:= $(call dirObjects,jrd/tests) $(call dirObjects,lock/tests)

AllObjects += $(Engine_Objects) $(Engine_Test_Objects)

Expand Down
3 changes: 3 additions & 0 deletions builds/win32/msvc15/engine_test.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,9 @@
<ItemGroup>
<ClCompile Include="..\..\..\src\jrd\tests\RecordNumberTest.cpp" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\..\..\src\lock\tests\LockManagerTest.cpp" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="alice.vcxproj">
<Project>{0d616380-1a5a-4230-a80b-021360e4e669}</Project>
Expand Down
3 changes: 3 additions & 0 deletions builds/win32/msvc15/engine_test.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,8 @@
<ClCompile Include="..\..\..\src\jrd\tests\RecordNumberTest.cpp">
<Filter>source</Filter>
</ClCompile>
<ClCompile Include="..\..\..\src\lock\tests\LockManagerTest.cpp">
<Filter>source</Filter>
</ClCompile>
</ItemGroup>
</Project>
41 changes: 30 additions & 11 deletions src/jrd/lck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,24 @@ namespace
}
#endif


ISC_STATUS LockManagerEngineCallbacks::getCancelState() const
{
return tdbb->getCancelState();
}

ULONG LockManagerEngineCallbacks::adjustWait(ULONG wait) const
{
return tdbb->adjustWait(wait);
}

void LockManagerEngineCallbacks::checkoutRun(std::function<void()> func) const
{
EngineCheckout cout(tdbb, FB_FUNCTION, EngineCheckout::UNNECESSARY);
func();
}


// globals and macros

inline LOCK_OWNER_T LCK_OWNER_ID_DBB(thread_db* tdbb)
Expand Down Expand Up @@ -155,8 +173,8 @@ inline bool CONVERT(thread_db* tdbb, CheckStatusWrapper* statusVector, Lock* loc

return lock->lck_compatible ?
internal_enqueue(tdbb, statusVector, lock, level, wait, true) :
dbb->lockManager()->convert(tdbb, statusVector, lock->lck_id, level, wait, lock->lck_ast,
lock->lck_object);
dbb->lockManager()->convert(LockManagerEngineCallbacks(tdbb), statusVector, lock->lck_id, level,
wait, lock->lck_ast, lock->lck_object);
}

inline void DEQUEUE(thread_db* tdbb, Lock* lock)
Expand All @@ -177,7 +195,7 @@ inline USHORT DOWNGRADE(thread_db* tdbb, Lock* lock)

USHORT ret = lock->lck_compatible ?
internal_downgrade(tdbb, &statusVector, lock) :
dbb->lockManager()->downgrade(tdbb, &statusVector, lock->lck_id);
dbb->lockManager()->downgrade(LockManagerEngineCallbacks(tdbb), &statusVector, lock->lck_id);

fb_assert(statusVector.isEmpty());

Expand Down Expand Up @@ -499,7 +517,7 @@ void LCK_fini(thread_db* tdbb, enum lck_owner_t owner_type)
}

if (*owner_handle_ptr)
dbb->lockManager()->shutdownOwner(tdbb, owner_handle_ptr);
dbb->lockManager()->shutdownOwner(LockManagerEngineCallbacks(tdbb), owner_handle_ptr);
}


Expand Down Expand Up @@ -841,7 +859,8 @@ void LCK_re_post(thread_db* tdbb, Lock* lock)
return;
}

dbb->lockManager()->repost(tdbb, lock->lck_ast, lock->lck_object, lock->lck_owner_handle);
dbb->lockManager()->repost(LockManagerEngineCallbacks(tdbb),
lock->lck_ast, lock->lck_object, lock->lck_owner_handle);

fb_assert(LCK_CHECK_LOCK(lock));
}
Expand Down Expand Up @@ -945,7 +964,7 @@ static void enqueue(thread_db* tdbb, CheckStatusWrapper* statusVector, Lock* loc

fb_assert(LCK_CHECK_LOCK(lock));

lock->lck_id = dbb->lockManager()->enqueue(tdbb, statusVector, lock->lck_id,
lock->lck_id = dbb->lockManager()->enqueue(LockManagerEngineCallbacks(tdbb), statusVector, lock->lck_id,
lock->lck_type, lock->getKeyPtr(), lock->lck_length,
level, lock->lck_ast, lock->lck_object, lock->lck_data, wait,
lock->lck_owner_handle);
Expand Down Expand Up @@ -1335,8 +1354,8 @@ static USHORT internal_downgrade(thread_db* tdbb, CheckStatusWrapper* statusVect

if (level < first->lck_physical)
{
if (dbb->lockManager()->convert(tdbb, statusVector, first->lck_id, level, LCK_NO_WAIT,
external_ast, first))
if (dbb->lockManager()->convert(LockManagerEngineCallbacks(tdbb), statusVector,
first->lck_id, level, LCK_NO_WAIT, external_ast, first))
{
for (Lock* lock = first; lock; lock = lock->lck_identical)
{
Expand Down Expand Up @@ -1402,8 +1421,8 @@ static bool internal_enqueue(thread_db* tdbb, CheckStatusWrapper* statusVector,

if (level > match->lck_physical)
{
if (!dbb->lockManager()->convert(tdbb, statusVector, match->lck_id, level, wait,
external_ast, lock))
if (!dbb->lockManager()->convert(LockManagerEngineCallbacks(tdbb), statusVector,
match->lck_id, level, wait, external_ast, lock))
{
return false;
}
Expand Down Expand Up @@ -1431,7 +1450,7 @@ static bool internal_enqueue(thread_db* tdbb, CheckStatusWrapper* statusVector,
// enqueue the lock, but swap out the ast and the ast argument
// with the local ast handler, passing it the lock block itself

lock->lck_id = dbb->lockManager()->enqueue(tdbb, statusVector, lock->lck_id,
lock->lck_id = dbb->lockManager()->enqueue(LockManagerEngineCallbacks(tdbb), statusVector, lock->lck_id,
lock->lck_type, lock->getKeyPtr(), lock->lck_length,
level, external_ast, lock, lock->lck_data, wait, lock->lck_owner_handle);

Expand Down
16 changes: 16 additions & 0 deletions src/jrd/lck.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,22 @@ enum lck_owner_t {
LCK_OWNER_attachment // An attachment is the owner of the lock
};

class LockManagerEngineCallbacks final : public LockManager::Callbacks
{
public:
LockManagerEngineCallbacks(thread_db* aTdbb)
: tdbb(aTdbb)
{
}

ISC_STATUS getCancelState() const override;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the class is marked final, perhaps it would be better to mark the methods final as well?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That can be inferred by the compiler.

ULONG adjustWait(ULONG wait) const override;
void checkoutRun(std::function<void()> func) const override;

private:
thread_db* const tdbb;
};

class Lock : public pool_alloc_rpt<UCHAR, type_lck>
{
public:
Expand Down
Loading
Loading