Back to index

lightning-sunbird  0.9+nobinonly
morkPool.h
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-  */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is mozilla.org code.
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape Communications Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 1999
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *
00024  * Alternatively, the contents of this file may be used under the terms of
00025  * either of the GNU General Public License Version 2 or later (the "GPL"),
00026  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00027  * in which case the provisions of the GPL or the LGPL are applicable instead
00028  * of those above. If you wish to allow use of your version of this file only
00029  * under the terms of either the GPL or the LGPL, and not to allow others to
00030  * use your version of this file under the terms of the MPL, indicate your
00031  * decision by deleting the provisions above and replace them with the notice
00032  * and other provisions required by the GPL or the LGPL. If you do not delete
00033  * the provisions above, a recipient may use your version of this file under
00034  * the terms of any one of the MPL, the GPL or the LGPL.
00035  *
00036  * ***** END LICENSE BLOCK ***** */
00037 
00038 #ifndef _MORKPOOL_
00039 #define _MORKPOOL_ 1
00040 
00041 #ifndef _MORK_
00042 #include "mork.h"
00043 #endif
00044 
00045 #ifndef _MORKDEQUE_
00046 #include "morkDeque.h"
00047 #endif
00048 
00049 #ifndef _MORKNODE_
00050 #include "morkNode.h"
00051 #endif
00052 
00053 //3456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789
00054 
00055 class morkHandle;
00056 class morkHandleFrame;
00057 class morkHandleFace; // just an opaque cookie type
00058 class morkBigBookAtom;
00059 class morkFarBookAtom;
00060 
00061 #define morkDerived_kPool     /*i*/ 0x706C /* ascii 'pl' */
00062 
00063 /*| morkPool: a place to manage pools of non-node objects that are memory
00064 **| managed out of large chunks of space, so that per-object management
00065 **| space overhead has no signficant cost.
00066 |*/
00067 class morkPool : public morkNode {
00068   
00069 // public: // slots inherited from morkNode (meant to inform only)
00070   // nsIMdbHeap*       mNode_Heap;
00071 
00072   // mork_base      mNode_Base;     // must equal morkBase_kNode
00073   // mork_derived   mNode_Derived;  // depends on specific node subclass
00074   
00075   // mork_access    mNode_Access;   // kOpen, kClosing, kShut, or kDead
00076   // mork_usage     mNode_Usage;    // kHeap, kStack, kMember, kGlobal, kNone
00077   // mork_able      mNode_Mutable;  // can this node be modified?
00078   // mork_load      mNode_Load;     // is this node clean or dirty?
00079   
00080   // mork_uses      mNode_Uses;     // refcount for strong refs
00081   // mork_refs      mNode_Refs;     // refcount for strong refs + weak refs
00082 
00083 public: // state is public because the entire Mork system is private
00084   nsIMdbHeap*  mPool_Heap; // NON-refcounted heap instance
00085   
00086   morkDeque    mPool_Blocks;      // linked list of large blocks from heap
00087   
00088   // These two lists contain instances of morkHandleFrame:
00089   morkDeque    mPool_UsedHandleFrames; // handle frames currently being used
00090   morkDeque    mPool_FreeHandleFrames; // handle frames currently in free list
00091   
00092   mork_count   mPool_UsedFramesCount; // length of mPool_UsedHandleFrames
00093   mork_count   mPool_FreeFramesCount; // length of mPool_UsedHandleFrames
00094     
00095 // { ===== begin morkNode interface =====
00096 public: // morkNode virtual methods
00097   virtual void CloseMorkNode(morkEnv* ev); // ClosePool() only if open
00098   virtual ~morkPool(); // assert that ClosePool() executed earlier
00099   
00100 public: // morkPool construction & destruction
00101   morkPool(const morkUsage& inUsage, nsIMdbHeap* ioHeap,
00102     nsIMdbHeap* ioSlotHeap);
00103   morkPool(morkEnv* ev, const morkUsage& inUsage, nsIMdbHeap* ioHeap,
00104     nsIMdbHeap* ioSlotHeap);
00105   void ClosePool(morkEnv* ev); // called by CloseMorkNode();
00106 
00107 private: // copying is not allowed
00108   morkPool(const morkPool& other);
00109   morkPool& operator=(const morkPool& other);
00110 
00111 public: // dynamic type identification
00112   mork_bool IsPool() const
00113   { return IsNode() && mNode_Derived == morkDerived_kPool; }
00114 // } ===== end morkNode methods =====
00115 
00116 public: // typing
00117   void NonPoolTypeError(morkEnv* ev);
00118 
00119 public: // morkNode memory management operators
00120   void* operator new(size_t inSize, nsIMdbHeap& ioHeap, morkEnv* ev) CPP_THROW_NEW
00121   { return morkNode::MakeNew(inSize, ioHeap, ev); }
00122   
00123   void* operator new(size_t inSize) CPP_THROW_NEW
00124   { return ::operator new(inSize); }
00125   
00126 
00127 public: // other pool methods
00128 
00129   // alloc and free individual instances of handles (inside hand frames):
00130   morkHandleFace*  NewHandle(morkEnv* ev, mork_size inSize, morkZone* ioZone);
00131   void             ZapHandle(morkEnv* ev, morkHandleFace* ioHandle);
00132 
00133   // alloc and free individual instances of rows:
00134   morkRow*  NewRow(morkEnv* ev, morkZone* ioZone); // alloc new row instance
00135   void      ZapRow(morkEnv* ev, morkRow* ioRow, morkZone* ioZone); // free old row instance
00136 
00137   // alloc and free entire vectors of cells (not just one cell at a time)
00138   morkCell* NewCells(morkEnv* ev, mork_size inSize, morkZone* ioZone);
00139   void      ZapCells(morkEnv* ev, morkCell* ioVector, mork_size inSize, morkZone* ioZone);
00140   
00141   // resize (grow or trim) cell vectors inside a containing row instance
00142   mork_bool AddRowCells(morkEnv* ev, morkRow* ioRow, mork_size inNewSize, morkZone* ioZone);
00143   mork_bool CutRowCells(morkEnv* ev, morkRow* ioRow, mork_size inNewSize, morkZone* ioZone);
00144   
00145   // alloc & free individual instances of atoms (lots of atom subclasses):
00146   void ZapAtom(morkEnv* ev, morkAtom* ioAtom, morkZone* ioZone); // any subclass (by kind)
00147   
00148   morkOidAtom* NewRowOidAtom(morkEnv* ev, const mdbOid& inOid, morkZone* ioZone); 
00149   morkOidAtom* NewTableOidAtom(morkEnv* ev, const mdbOid& inOid, morkZone* ioZone);
00150   
00151   morkAtom* NewAnonAtom(morkEnv* ev, const morkBuf& inBuf,
00152     mork_cscode inForm, morkZone* ioZone);
00153     // if inForm is zero, and inBuf.mBuf_Fill is less than 256, then a 'wee'
00154     // anon atom will be created, and otherwise a 'big' anon atom.
00155     
00156   morkBookAtom* NewBookAtom(morkEnv* ev, const morkBuf& inBuf,
00157     mork_cscode inForm, morkAtomSpace* ioSpace, mork_aid inAid, morkZone* ioZone);
00158     // if inForm is zero, and inBuf.mBuf_Fill is less than 256, then a 'wee'
00159     // book atom will be created, and otherwise a 'big' book atom.
00160     
00161   morkBookAtom* NewBookAtomCopy(morkEnv* ev, const morkBigBookAtom& inAtom, morkZone* ioZone);
00162     // make the smallest kind of book atom that can hold content in inAtom.
00163     // The inAtom parameter is often expected to be a staged book atom in
00164     // the store, which was used to search an atom space for existing atoms.
00165     
00166   morkBookAtom* NewFarBookAtomCopy(morkEnv* ev, const morkFarBookAtom& inAtom, morkZone* ioZone);
00167     // make the smallest kind of book atom that can hold content in inAtom.
00168     // The inAtom parameter is often expected to be a staged book atom in
00169     // the store, which was used to search an atom space for existing atoms.
00170 
00171 public: // typesafe refcounting inlines calling inherited morkNode methods
00172   static void SlotWeakPool(morkPool* me,
00173     morkEnv* ev, morkPool** ioSlot)
00174   { morkNode::SlotWeakNode((morkNode*) me, ev, (morkNode**) ioSlot); }
00175   
00176   static void SlotStrongPool(morkPool* me,
00177     morkEnv* ev, morkPool** ioSlot)
00178   { morkNode::SlotStrongNode((morkNode*) me, ev, (morkNode**) ioSlot); }
00179 };
00180 
00181 //3456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789
00182 
00183 #endif /* _MORKPOOL_ */
00184