/*static char *SCCSID = "@(#)unlckio.c  6.3 92/01/31";*/

#include <os2def.h>
#include <strat2.h>

#include "const.h"
#include "misc.h"
#include "buf.h"
#include "chain.h"
#include "dir.h"
#include "volume.h"
#include "frame.h"
#include "asyncio.h"
#include "lprintf.h"
#include "heap.h"
#include "lw.h"
#include "fsdata.h"
#include "pbmacros.h"
#include "storage.h"
#include "tables.h"

#include "pr_misc.h"
//@76193   #ifdef DEBUG
    #include "assert.h"
    #include "pr_debug.h"
// @76193  #endif

#include "pr_heap.h"

/*
 * VOID UnlockIOHPages( PIOH pioh );
 *
 * Called to release the pages locked down by QDiskOp
 *
 * Parameter:
 *     pioh        Pointer to I/O Handle usually obtained from GetIOHand()
 *
 * UnlockIOHPages is called after I/O for a given Execution-list has
 * completed and before ResetIOH is called to unlock any pages that
 * were locked down by QDiskOp.  QDiskOp swaps in and locks down
 * the buffers that are passed in as pbData to allow the disk controller
 * to access them.
 *
 *  HISTORY:
 * @76193   23-Nov-93 by D. Azzarito  - modify logging support for debug
 */
VOID UnlockIOHPages( PIOH pioh, PFRAME pfrm ) {
    PLCKHAND plh;
    PLCKHAND plhOld;

//@76193 - don't print when logging
#if defined (DEBUG) || defined (LOG_PRINT)
    lprintf( LMOD_PROC, __FILE__":entered, pioh=%p", pioh );
#endif

#ifdef ASSERT_IOH
    ASSERT_IOH(pioh);
#endif

  if( (pioh->usFlags & GIH_PHYSADDR) == 0 ) {

    /* step through the list, unlocking the pages it points to as we go */
    for( plh = pioh->plhChain; plh != NULL; ) {

        REACHABLE( plh );

        MAYBLOCK (VMUnlock( plh->abLockHand))

        plhOld = plh;

        plh = plh->plhNext;

#if defined (DEBUG) || defined (LOG_PRINT)
        lprintf( LMOD_PROC, __FILE__":retheaping lock handle %p", plhOld );
#endif

        RetHeap( plhOld );
    }

#ifdef DEBUG
    /* set to null for debug check in resetioh.c */
    pioh->plhChain = NULL;
#endif

  }
}
