checkpmdeath.c
text/x-c
Filename: checkpmdeath.c
Type: text/x-c
Part: 0
/*
create function wait_on_process_latch() returns void
strict volatile language c as '.../whatever.so';
select wait_on_process_latch();
*/
#include "postgres.h"
#include "fmgr.h"
#include "miscadmin.h"
#include "storage/latch.h"
#include "pgstat.h"
PG_MODULE_MAGIC;
/*
* wait_on_process_latch() returns void
*/
PG_FUNCTION_INFO_V1(wait_on_process_latch);
Datum
wait_on_process_latch(PG_FUNCTION_ARGS)
{
int count = 10;
while (count-- > 0)
{
int rc;
CHECK_FOR_INTERRUPTS();
elog(INFO, "waiting on latch");
rc = WaitLatch(MyLatch,
WL_LATCH_SET | WL_POSTMASTER_DEATH, 0,
WAIT_EVENT_BGWORKER_SHUTDOWN);
if (rc & WL_POSTMASTER_DEATH)
{
elog(INFO, "got WL_POSTMASTER_DEATH report");
}
ResetLatch(MyLatch);
}
PG_RETURN_VOID();
}