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

#ifndef HDRS
#define HDRS

#define INCL_DOSERRORS
#include <os2def.h>
#include <bse.h>
#include <fsh.h>
#include "const.h"
#include "misc.h"
#include "chain.h"
#include "buf.h"
#include "dir.h"
#include "storage.h"
#include "volume.h"
#include "tables.h"
#include "lw.h"
#include "pbmacros.h"
#include "pb_ifs.h"
#include "frame.h"
#include "fsdata.h"

#endif

#include "pr_MISC.h"
#include "pr_DEBUG.h"


/*
 ***	Block - Block on an Event
 *
 *	Block suspends execution for this thread until the specified
 *	event is woken (via Wakeup).  We chain the TDB onto the end
 *	of the suspend list.
 *
 *	Block is frequently called with interrupts disabled in order to
 *	prevent race conditions with wakers that run at interrupt time.
 *	Even if the event that our current caller is blocking on can
 *	only wakeup at task time, Block has to CLI internally so that
 *	an interrupt time wakeup on some other event won't cause
 *	critical section conflicts with the dispatch tables.
 *
 *	Block returns when the event chain has been woken.
 *
 *	ENTRY	pBlockChain = Address of head of suspend list
 *
 *	HISTORY
 *	    15-Aug-1989 by JR (John Rogers, JohnRo@Microsoft)
 *		- Added BlockFar() for use from FS_SEG.
 */

void
Block (pBlockChain, pfrm)
PVOID pBlockChain;
PFRAME pfrm;
{
#ifdef DEBUG
    /* We should never block if we aren't allowing multithreading. */
    if (!fMTFlag) {
	INTERR ("Block: shouldn't have got here\n");
    }
#endif

    /* the following increment & block must happen without interrupts, in
     * order for the wake up code to work correctly.
     */
    _disable ();

	(*MAKETYPE (pBlockChain, PULONG))++;
	MAYBLOCK (ProcBlock (pBlockChain));

    _enable ();
}
