Skip to content

Commit 14610d6

Browse files
committed
Decouple LockManager from engine
1 parent 382cf0f commit 14610d6

File tree

4 files changed

+117
-71
lines changed

4 files changed

+117
-71
lines changed

src/jrd/lck.cpp

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,24 @@ namespace
9595
}
9696
#endif
9797

98+
99+
ISC_STATUS LockManagerEngineCallbacks::getCancelState() const
100+
{
101+
return tdbb->getCancelState();
102+
}
103+
104+
ULONG LockManagerEngineCallbacks::adjustWait(ULONG wait) const
105+
{
106+
return tdbb->adjustWait(wait);
107+
}
108+
109+
void LockManagerEngineCallbacks::checkoutRun(std::function<void()> func) const
110+
{
111+
EngineCheckout cout(tdbb, FB_FUNCTION, EngineCheckout::UNNECESSARY);
112+
func();
113+
}
114+
115+
98116
// globals and macros
99117

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

156174
return lock->lck_compatible ?
157175
internal_enqueue(tdbb, statusVector, lock, level, wait, true) :
158-
dbb->lockManager()->convert(tdbb, statusVector, lock->lck_id, level, wait, lock->lck_ast,
159-
lock->lck_object);
176+
dbb->lockManager()->convert(LockManagerEngineCallbacks(tdbb), statusVector, lock->lck_id, level,
177+
wait, lock->lck_ast, lock->lck_object);
160178
}
161179

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

178196
USHORT ret = lock->lck_compatible ?
179197
internal_downgrade(tdbb, &statusVector, lock) :
180-
dbb->lockManager()->downgrade(tdbb, &statusVector, lock->lck_id);
198+
dbb->lockManager()->downgrade(LockManagerEngineCallbacks(tdbb), &statusVector, lock->lck_id);
181199

182200
fb_assert(statusVector.isEmpty());
183201

@@ -499,7 +517,7 @@ void LCK_fini(thread_db* tdbb, enum lck_owner_t owner_type)
499517
}
500518

501519
if (*owner_handle_ptr)
502-
dbb->lockManager()->shutdownOwner(tdbb, owner_handle_ptr);
520+
dbb->lockManager()->shutdownOwner(LockManagerEngineCallbacks(tdbb), owner_handle_ptr);
503521
}
504522

505523

@@ -841,7 +859,8 @@ void LCK_re_post(thread_db* tdbb, Lock* lock)
841859
return;
842860
}
843861

844-
dbb->lockManager()->repost(tdbb, lock->lck_ast, lock->lck_object, lock->lck_owner_handle);
862+
dbb->lockManager()->repost(LockManagerEngineCallbacks(tdbb),
863+
lock->lck_ast, lock->lck_object, lock->lck_owner_handle);
845864

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

946965
fb_assert(LCK_CHECK_LOCK(lock));
947966

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

13361355
if (level < first->lck_physical)
13371356
{
1338-
if (dbb->lockManager()->convert(tdbb, statusVector, first->lck_id, level, LCK_NO_WAIT,
1339-
external_ast, first))
1357+
if (dbb->lockManager()->convert(LockManagerEngineCallbacks(tdbb), statusVector,
1358+
first->lck_id, level, LCK_NO_WAIT, external_ast, first))
13401359
{
13411360
for (Lock* lock = first; lock; lock = lock->lck_identical)
13421361
{
@@ -1402,8 +1421,8 @@ static bool internal_enqueue(thread_db* tdbb, CheckStatusWrapper* statusVector,
14021421

14031422
if (level > match->lck_physical)
14041423
{
1405-
if (!dbb->lockManager()->convert(tdbb, statusVector, match->lck_id, level, wait,
1406-
external_ast, lock))
1424+
if (!dbb->lockManager()->convert(LockManagerEngineCallbacks(tdbb), statusVector,
1425+
match->lck_id, level, wait, external_ast, lock))
14071426
{
14081427
return false;
14091428
}
@@ -1431,7 +1450,7 @@ static bool internal_enqueue(thread_db* tdbb, CheckStatusWrapper* statusVector,
14311450
// enqueue the lock, but swap out the ast and the ast argument
14321451
// with the local ast handler, passing it the lock block itself
14331452

1434-
lock->lck_id = dbb->lockManager()->enqueue(tdbb, statusVector, lock->lck_id,
1453+
lock->lck_id = dbb->lockManager()->enqueue(LockManagerEngineCallbacks(tdbb), statusVector, lock->lck_id,
14351454
lock->lck_type, lock->getKeyPtr(), lock->lck_length,
14361455
level, external_ast, lock, lock->lck_data, wait, lock->lck_owner_handle);
14371456

src/jrd/lck.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,22 @@ enum lck_owner_t {
8686
LCK_OWNER_attachment // An attachment is the owner of the lock
8787
};
8888

89+
class LockManagerEngineCallbacks : public LockManager::Callbacks
90+
{
91+
public:
92+
LockManagerEngineCallbacks(thread_db* aTdbb)
93+
: tdbb(aTdbb)
94+
{
95+
}
96+
97+
ISC_STATUS getCancelState() const override;
98+
ULONG adjustWait(ULONG wait) const override;
99+
void checkoutRun(std::function<void()> func) const override;
100+
101+
private:
102+
thread_db* const tdbb;
103+
};
104+
89105
class Lock : public pool_alloc_rpt<UCHAR, type_lck>
90106
{
91107
public:

0 commit comments

Comments
 (0)