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

#ifndef HDRS
#define HDRS

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

#endif

#include "pr_FSSUB.h"
#include "pr_MISC.h"
#include "pr_debug.h"

/*
 ***	SoloOFT - Get Sole Use of an OFT
 *
 *	When we wish to delete an OFT it's not enough to lock it, since
 *	someone may block upon our releasing a lock and they'll be unhappy
 *	if the OFT is gone when they wake up.
 *
 *	SoloOFT blocks until this thread is the sole user of the OFT and
 *	no other threads are waiting.
 *
 *	ENTRY	poft (edi) = OFT address.
 *	EXIT	none
 *	USES	eax, flags
 */

void
SoloOFT (poft,pfrm)
POFT poft;
PFRAME pfrm;
{
    ASSERT_OFT (poft);

    while (TRUE) {
	if ((poft->bFlag & OTF_PLK) == 0 && poft->cusHolds == 0) {
	    if (poft->cWaits == 0) {
		return;
	    }
	    else {
		SetFlagsOFT(poft, OTF_PND | OTF_PSO);
		poft->cWaits++;
		BlockOnOFT( poft,pfrm );
		poft->cWaits--;
	    }
	}
	else {
	    SetFlagsOFT(poft, OTF_PND | OTF_PSO);
	    LockOFT (poft,pfrm);
	}
    }
}
