/* * Initialize a backend-local latch. */ void InitLatch(volatile Latch *latch) { /* Initialize the self-pipe if this is our first latch in the process */ if (selfpipe_readfd == -1) initSelfPipe(); latch->is_set = false; latch->owner_pid = MyProcPid; latch->is_shared = false; }
/* * Associate a shared latch with the current process, allowing it to * wait on it. * * Make sure that latch_sigusr1_handler() is called from the SIGUSR1 signal * handler, as shared latches use SIGUSR1 to for inter-process communication. */ void OwnLatch(volatile Latch *latch) { Assert(latch->is_shared); /* Initialize the self pipe if this is our first latch in the process */ if (selfpipe_readfd == -1) initSelfPipe(); /* sanity check */ if (latch->owner_pid != 0) elog(ERROR, "latch already owned"); latch->owner_pid = MyProcPid; }