Ignore:
Timestamp:
Sep 2, 2000, 11:08:23 PM (25 years ago)
Author:
bird
Message:

Merged in the Grace branch. New Win32k!

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/win32k/misc/rmalloc_avl.c

    r2511 r4164  
    1 /* $Id: rmalloc_avl.c,v 1.5 2000-01-24 18:19:00 bird Exp $
     1/* $Id: rmalloc_avl.c,v 1.6 2000-09-02 21:08:14 bird Exp $
    22 *
    33 * Resident Heap - AVL.
     
    4747******************************************************************************/
    4848#include <os2.h>
     49#include "devSegDf.h"                   /* Win32k segment definitions. */
    4950#ifdef RING0
    5051    #include "dev32hlp.h"
     
    120121static PHEAPANCHOR  phaFirst;           /* Pointer to the first anchor block.*/
    121122static PHEAPANCHOR  phaLast;            /* Pointer to the last anchor block.*/
    122 static unsigned     cbResHeapMax;       /* Maximum amount of memory used by the heap. */
     123unsigned            cbResHeapMax;       /* Maximum amount of memory used by the heap. */
    123124
    124125#ifndef RING0
     
    898899
    899900/**
     901 * Get amount of used memory (in bytes)
     902 * @returns  Amount of used memory (in bytes).
     903 */
     904unsigned    _res_memused(void)
     905{
     906    PHEAPANCHOR pha = phaFirst;
     907    unsigned    cb;
     908
     909    #ifdef ALLWAYS_HEAPCHECK
     910    if (!_res_heap_check())
     911        kprintf(("_res_memused: _res_heap_check failed!\n"));
     912    #endif
     913
     914    for (cb = 0; pha != NULL; pha = pha->pNext)
     915        cb += pha->cbUsed;
     916
     917    return cb;
     918}
     919
     920
     921/**
     922 * Collects the heap state.
     923 * @returns     0 on success.
     924 *              -1 on error.
     925 * @param       pState  Pointer to a RES_HEAPSTATE structure which is
     926 *                      filled upon successful return.
     927 */
     928int         _res_state(PHEAPSTATE pState)
     929{
     930    PHEAPANCHOR pha;
     931
     932    #ifdef ALLWAYS_HEAPCHECK
     933    if (!_res_heap_check())
     934    {
     935        kprintf(("_res_state: _res_heap_check failed!\n"));
     936        return -1;
     937    }
     938    #endif
     939
     940    if (pState == NULL)
     941        return -1;
     942
     943    /*
     944     * Loop thru all the anchor blocks and all memory blocks
     945     * building the stats.
     946     */
     947    memset(pState, 0, sizeof(HEAPSTATE));
     948    for (pha = phaFirst; pha != NULL; pha = pha->pNext)
     949    {
     950        AVLENUMDATA     EnumData;
     951        PAVLENUMDATA    pEnumData = SSToDS(&EnumData);
     952        PMEMBLOCK       pmb;
     953
     954        /* count of free blocks */
     955        pmb = (PMEMBLOCK)AVLBeginEnumTree((PPAVLNODECORE)&pha->pmbFree, pEnumData, TRUE);
     956        while (pmb)
     957        {
     958            pState->cBlocksFree++;
     959            pmb = (PMEMBLOCK)AVLGetNextNode(pEnumData);
     960        }
     961
     962        /* count of used blocks */
     963        pmb = (PMEMBLOCK)AVLBeginEnumTree((PPAVLNODECORE)&pha->pmbUsed, pEnumData, TRUE);
     964        while (pmb)
     965        {
     966            pState->cBlocksUsed++;
     967            pmb = (PMEMBLOCK)AVLGetNextNode(pEnumData);
     968        }
     969
     970        /* sizes */
     971        pState->cbHeapSize  += pha->cbSize;
     972        pState->cbHeapFree  += pha->cbFree;
     973        pState->cbHeapUsed  += pha->cbUsed;
     974    }
     975
     976    return 0;
     977}
     978
     979
     980/**
    900981 * Checks heap integrety.
    901982 * @returns  TRUE  when ok.
Note: See TracChangeset for help on using the changeset viewer.