#include <arpbase.h>
#include <arp_proto.h>
#include "Launch.h"
#include "LaunchPriv.h"


/*
 *	NAME
 *		AllocParentSignal -- Allocate a signal for child notification.
 *
 *	SYNOPSIS
 *		bit = AllocParentSignal ()
 *
 *		LONG AllocParentSignal (void);
 *
 *	DESCRIPTION
 *		Check if we already launched a process and try to use the same
 *		bit for all processes.  If we can't find a process pair, we
 *		allocate a new bit.
 *
 *	INPUT
 *		None.
 *
 *	OUTPUT
 *		bit - the allocated bit number.
 *
 *	HISTORY
 *		1992/09/07	Pierre Baillargeon		Creation
 */

LONG AllocParentSignal (void)
{
	struct ProcPair *Parent;

	if (NULL != (Parent = IsParent ((struct Process *)FindTask (NULL))))
	{
		return Parent->pp_ParentBit;
	}
	else
	{
		return (LONG)AllocSignal (-1L);
	}
}


/*
 *	NAME
 *		FreeParentSignal -- free the signal if it's not used by other.
 *
 *	SYNOPSIS
 *		FreeParentSignal (bit)
 *
 *		void FreeParentSignal (LONG);
 *
 *	DESCRIPTION
 *		Check if the signal bit number is valid and if it is not used
 *		by another process pair.  If not, free it.
 *
 *	INPUT
 *		bit - the bit number.
 *
 *	OUTPUT
 *		None.
 *
 *	HISTORY
 *		1992/09/07	Pierre Baillargeon		Creation
 */

void FreeParentSignal (LONG Bit)
{
	if (-1L != Bit && NULL == IsParent ((struct Process *)FindTask (NULL)))
	{
		FreeSignal (Bit);
	}
}
