/*static char *SCCSID = "@(#)placeche.c	6.2 91/04/29";*/

#define SCCSID "@(#)placeche.c	6.2 91/04/29"
/********************************************************/
/*                                                      */
/*       IBM/Microsoft Confidential                     */
/*                                                      */
/*       Copyright (c) IBM Corporation 1987, 1989       */
/*       Copyright (c) Microsoft Corporation 1987, 1989 */
/*                                                      */
/*       All Rights Reserved                            */
/********************************************************/

#define FNO_NUM FNO_PLACECHE_C
#define INCL_TYPES                      // for basedef.h typedefs
#include <osconst.h>
#include <ostypes.h>
#include <basemac.h>
#include <basedef.h>
#include <mi.h>
#include <fnofs.h>
#include <osmac.h>
#include <vmexport.h>
#include <selxport.h>
#include <pgexport.h>
#include <tkexport.h>
#include <smexport.h>
#include <sft.h>
#include <cache.h>

/*
 ***    PlaceBuf - Place buffer into LRU chain
 *
 *      PlaceBuf will place a particular buffer into the correct place
 *      in the LRU chain.  Not all buffer accesses demand that the buffer
 *      be put into the most-recently-used position.
 *
 *      ENTRY   pcache = header address
 *              priCache = advisory priority:
 *                         PLCBUF_MRU or PLCBUF_LRU
 *
 *      EXIT    none
 *

 *      HISTORY
 */

void
PlaceBuf (pBuf,priBuf)
register PBUFHDR pBuf;      /*  address of buffer header to go into LRU chain  */
register ulong_t priBuf;
{
    /*  If it is on the LRU chain
     *      remove it
     */
    if (pBuf->BufLru.pbufFwd != pBuf) {
       DCREM (pBuf, BufLru);
    }
    else {
       if (GFB_Sem){
          TKWakeup ((void *)&GFB_Sem,0,NULL);
          GFB_Sem = FALSE;
       }
    }
    if (priBuf == PLCBUF_MRU) {
       /*  Put in MRU position
        */
       DCADDF (pBuf,BufLru,BufLRUHead);
    }
    else {
       /* Put in LRU position
        */
       DCADDB (pBuf,BufLru,BufLRUHead);
    }
}
