/*static char *SCCSID = "@(#)holddir.c	6.2 92/01/31";*/
#ifndef	 _BTXT
#define	 _BTXT _BTXT
#define	 _THISFILE "HOLDDIR.C"
#include _THISFILE.C
#undef	 _BTXT
#endif

#ifndef HDRS
#define HDRS

/***	holddir - block until holdable and hold a directory
 */

#include <os2def.h>

#include "const.h"
#include "chain.h"
#include "misc.h"
#include "buf.h"
#include "dir.h"
#include "storage.h"
#include "volume.h"
#include "tables.h"
#include "pb_ifs.h"
#include "pbmacros.h"
#include "lw.h"
#include "frame.h"
#include "fsdata.h"
#include "assert.h"
#include "log.h"

#endif

#include "pr_DIR.h"
#include "pr_MISC.h"
#include "pr_debug.h"


/*
 ***	HoldDir - Hold Directory
 *
 *	HoldDir is used when the caller wants to hold a directory but
 *	the directory is in some reserved state.
 *
 * L1	if (directory is holdable)
 *		hold it and return
 *	If the directory is locked:
 *		add ourselves to the wait list.  Wait.
 *		goto L1
 *
 *	If (directory has wait pending)
 *		add ourselves to the wait list.  Wait
 *		goto L1
 *
 *	ENTRY	psbd points to SBDIR
 *
 *	EXIT	directory held
 *		(eax) = SBDIR pointer
 *
 *	Updated to reflect 10/16 assy
 */

void
HoldDir (PSUBDIR psbd, PFRAME pfrm)
{
    ASSERT_SBD (psbd);

    while ((psbd->bFlags & (SDF_LCK | SDF_PLK)) != 0) {

	psbd->cusWaiters += 1;
	BlockOnSBD( psbd,pfrm );
	psbd->cusWaiters -= 1;
    }
    IncrHoldsSBD (psbd);
}
