Skip to content

Commit e6c7509

Browse files
knizhnikkelvich
authored andcommitted
Correctly handle lock failure in MtmLock
1 parent 00bdad3 commit e6c7509

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

multimaster.c

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -317,19 +317,22 @@ void MtmLock(LWLockMode mode)
317317
atexit(MtmReleaseLocks);
318318
MtmAtExitHookRegistered = true;
319319
}
320-
if (mode == LW_EXCLUSIVE || MtmLockCount != 0) {
321-
if (MtmLockCount++ != 0) {
322-
Assert(Mtm->lastLockHolder == MyProcPid);
323-
return;
324-
}
320+
if (MtmLockCount != 0) {
321+
Assert(Mtm->lastLockHolder == MyProcPid);
322+
MtmLockCount += 1;
323+
return;
325324
}
326325
start = MtmGetSystemTime();
327326
LWLockAcquire((LWLockId)&Mtm->locks[MTM_STATE_LOCK_ID], mode);
328327
stop = MtmGetSystemTime();
329328
if (stop > start + MSEC_TO_USEC(MtmHeartbeatSendTimeout)) {
330329
MTM_LOG1("%d: obtaining %s lock takes %lld microseconds", MyProcPid, (mode == LW_EXCLUSIVE ? "exclusive" : "shared"), stop - start);
331330
}
332-
Mtm->lastLockHolder = MyProcPid;
331+
if (mode == LW_EXCLUSIVE) {
332+
Assert(MtmLockCount == 0);
333+
Mtm->lastLockHolder = MyProcPid;
334+
MtmLockCount = 1;
335+
}
333336
}
334337

335338
void MtmUnlock(void)

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy