Home | History | Annotate | Download | only in src
      1 /**************************************************************************
      2  *
      3  * Copyright 2006-2008 Tungsten Graphics, Inc., Cedar Park, TX., USA.
      4  * All Rights Reserved.
      5  * Copyright 2009 VMware, Inc., Palo Alto, CA., USA.
      6  * All Rights Reserved.
      7  *
      8  * Permission is hereby granted, free of charge, to any person obtaining a
      9  * copy of this software and associated documentation files (the
     10  * "Software"), to deal in the Software without restriction, including
     11  * without limitation the rights to use, copy, modify, merge, publish,
     12  * distribute, sub license, and/or sell copies of the Software, and to
     13  * permit persons to whom the Software is furnished to do so, subject to
     14  * the following conditions:
     15  *
     16  * The above copyright notice and this permission notice (including the
     17  * next paragraph) shall be included in all copies or substantial portions
     18  * of the Software.
     19  *
     20  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
     21  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
     22  * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
     23  * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
     24  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
     25  * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
     26  * USE OR OTHER DEALINGS IN THE SOFTWARE.
     27  *
     28  **************************************************************************/
     29 
     30 /*
     31  * Generic simple memory manager implementation. Intended to be used as a base
     32  * class implementation for more advanced memory managers.
     33  *
     34  * Note that the algorithm used is quite simple and there might be substantial
     35  * performance gains if a smarter free list is implemented. Currently it is just an
     36  * unordered stack of free regions. This could easily be improved if an RB-tree
     37  * is used instead. At least if we expect heavy fragmentation.
     38  *
     39  * Authors:
     40  * Thomas Hellstrom <thomas-at-tungstengraphics-dot-com>
     41  */
     42 
     43 #ifndef _WSBM_MM_H_
     44 #define _WSBM_MM_H_
     45 
     46 #include "wsbm_util.h"
     47 struct _WsbmMM
     48 {
     49     struct _WsbmListHead fl_entry;
     50     struct _WsbmListHead ml_entry;
     51 };
     52 
     53 struct _WsbmMMNode
     54 {
     55     struct _WsbmListHead fl_entry;
     56     struct _WsbmListHead ml_entry;
     57     int free;
     58     unsigned long start;
     59     unsigned long size;
     60     struct _WsbmMM *mm;
     61 };
     62 
     63 extern struct _WsbmMMNode *wsbmMMSearchFree(const struct _WsbmMM *mm,
     64 					    unsigned long size,
     65 					    unsigned alignment,
     66 					    int best_match);
     67 extern struct _WsbmMMNode *wsbmMMGetBlock(struct _WsbmMMNode *parent,
     68 					  unsigned long size,
     69 					  unsigned alignment);
     70 extern void wsbmMMPutBlock(struct _WsbmMMNode *cur);
     71 extern void wsbmMMtakedown(struct _WsbmMM *mm);
     72 extern int wsbmMMinit(struct _WsbmMM *mm, unsigned long start,
     73 		      unsigned long size);
     74 extern int wsbmMMclean(struct _WsbmMM *mm);
     75 #endif
     76