summaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
authorAndres Freund2015-01-14 17:45:22 +0000
committerAndres Freund2015-01-14 17:45:22 +0000
commit59f71a0d0b56b2df48db4bf1738aece5551f7a47 (patch)
tree6023eb572eade66adb21ee0ae84fd6aa33e30ac9 /src/test
parent85a2a8903f7e9151793308d0638621003aded5ae (diff)
Add a default local latch for use in signal handlers.
To do so, move InitializeLatchSupport() into the new common process initialization functions, and add a new global variable MyLatch. MyLatch is usable as soon InitPostmasterChild() has been called (i.e. very early during startup). Initially it points to a process local latch that exists in all processes. InitProcess/InitAuxiliaryProcess then replaces that local latch with PGPROC->procLatch. During shutdown the reverse happens. This is primarily advantageous for two reasons: For one it simplifies dealing with the shared process latch, especially in signal handlers, because instead of having to check for MyProc, MyLatch can be used unconditionally. For another, a later patch that makes FEs/BE communication use latches, now can rely on the existence of a latch, even before having gone through InitProcess. Discussion: 20140927191243.GD5423@alap3.anarazel.de
Diffstat (limited to 'src/test')
-rw-r--r--src/test/modules/test_shm_mq/setup.c4
-rw-r--r--src/test/modules/test_shm_mq/test.c4
-rw-r--r--src/test/modules/test_shm_mq/worker.c3
-rw-r--r--src/test/modules/worker_spi/worker_spi.c10
4 files changed, 9 insertions, 12 deletions
diff --git a/src/test/modules/test_shm_mq/setup.c b/src/test/modules/test_shm_mq/setup.c
index b049cff2d05..195099095de 100644
--- a/src/test/modules/test_shm_mq/setup.c
+++ b/src/test/modules/test_shm_mq/setup.c
@@ -285,13 +285,13 @@ wait_for_workers_to_become_ready(worker_state *wstate,
}
/* Wait to be signalled. */
- WaitLatch(&MyProc->procLatch, WL_LATCH_SET, 0);
+ WaitLatch(MyLatch, WL_LATCH_SET, 0);
/* An interrupt may have occurred while we were waiting. */
CHECK_FOR_INTERRUPTS();
/* Reset the latch so we don't spin. */
- ResetLatch(&MyProc->procLatch);
+ ResetLatch(MyLatch);
}
}
PG_CATCH();
diff --git a/src/test/modules/test_shm_mq/test.c b/src/test/modules/test_shm_mq/test.c
index 6428fcf51c4..732376daff2 100644
--- a/src/test/modules/test_shm_mq/test.c
+++ b/src/test/modules/test_shm_mq/test.c
@@ -230,9 +230,9 @@ test_shm_mq_pipelined(PG_FUNCTION_ARGS)
* have read or written data and therefore there may now be work
* for us to do.
*/
- WaitLatch(&MyProc->procLatch, WL_LATCH_SET, 0);
+ WaitLatch(MyLatch, WL_LATCH_SET, 0);
CHECK_FOR_INTERRUPTS();
- ResetLatch(&MyProc->procLatch);
+ ResetLatch(MyLatch);
}
}
diff --git a/src/test/modules/test_shm_mq/worker.c b/src/test/modules/test_shm_mq/worker.c
index dec058b55ea..a9d9e0e2552 100644
--- a/src/test/modules/test_shm_mq/worker.c
+++ b/src/test/modules/test_shm_mq/worker.c
@@ -211,8 +211,7 @@ handle_sigterm(SIGNAL_ARGS)
{
int save_errno = errno;
- if (MyProc)
- SetLatch(&MyProc->procLatch);
+ SetLatch(MyLatch);
if (!proc_exit_inprogress)
{
diff --git a/src/test/modules/worker_spi/worker_spi.c b/src/test/modules/worker_spi/worker_spi.c
index ac0f59c9886..94d3857364f 100644
--- a/src/test/modules/worker_spi/worker_spi.c
+++ b/src/test/modules/worker_spi/worker_spi.c
@@ -74,8 +74,7 @@ worker_spi_sigterm(SIGNAL_ARGS)
int save_errno = errno;
got_sigterm = true;
- if (MyProc)
- SetLatch(&MyProc->procLatch);
+ SetLatch(MyLatch);
errno = save_errno;
}
@@ -91,8 +90,7 @@ worker_spi_sighup(SIGNAL_ARGS)
int save_errno = errno;
got_sighup = true;
- if (MyProc)
- SetLatch(&MyProc->procLatch);
+ SetLatch(MyLatch);
errno = save_errno;
}
@@ -227,10 +225,10 @@ worker_spi_main(Datum main_arg)
* necessary, but is awakened if postmaster dies. That way the
* background process goes away immediately in an emergency.
*/
- rc = WaitLatch(&MyProc->procLatch,
+ rc = WaitLatch(MyLatch,
WL_LATCH_SET | WL_TIMEOUT | WL_POSTMASTER_DEATH,
worker_spi_naptime * 1000L);
- ResetLatch(&MyProc->procLatch);
+ ResetLatch(MyLatch);
/* emergency bailout if postmaster has died */
if (rc & WL_POSTMASTER_DEATH)