Skip to content

Commit 1a90b9a

Browse files
committed
Do accquire a spinlock when not necessary
1 parent dd4adb7 commit 1a90b9a

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

pg_show_plans.c

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -459,20 +459,22 @@ pgsp_ExecutorRun(QueryDesc *queryDesc, ScanDirection direction,
459459
standard_ExecutorRun(queryDesc, direction, count, execute_once);
460460

461461
nest_level--;
462-
/* Wait for reading to complete, the delete. */
463-
SpinLockAcquire(&pgsp_cache->mutex);
464-
if (nest_level < 1) /* Mark hash entry as empty. */
462+
/* Wait for reading to complete, then delete. */
463+
if (nest_level < 1) { /* Mark hash entry as empty. */
464+
SpinLockAcquire(&pgsp_cache->mutex);
465465
pgsp_cache->n_plans = 0;
466-
SpinLockRelease(&pgsp_cache->mutex);
466+
SpinLockRelease(&pgsp_cache->mutex);
467+
}
467468
}
468469
PG_CATCH(); /* Since 13 PG_FINALLY() is available. */
469470
{
470471
nest_level--;
471-
/* Wait for reading to complete, the delete. */
472-
SpinLockAcquire(&pgsp_cache->mutex);
473-
if (nest_level < 1) /* Mark hash entry as empty. */
472+
/* Wait for reading to complete, then delete. */
473+
if (nest_level < 1) { /* Mark hash entry as empty. */
474+
SpinLockAcquire(&pgsp_cache->mutex);
474475
pgsp_cache->n_plans = 0;
475-
SpinLockRelease(&pgsp_cache->mutex);
476+
SpinLockRelease(&pgsp_cache->mutex);
477+
}
476478

477479
PG_RE_THROW();
478480
}

0 commit comments

Comments
 (0)