diff options
author | Matt A. Tobin <email@mattatobin.com> | 2019-11-03 00:17:46 -0400 |
---|---|---|
committer | Matt A. Tobin <email@mattatobin.com> | 2019-11-03 00:17:46 -0400 |
commit | 302bf1b523012e11b60425d6eee1221ebc2724eb (patch) | |
tree | b191a895f8716efcbe42f454f37597a545a6f421 /db/mork/src/morkPool.h | |
parent | 21b3f6247403c06f85e1f45d219f87549862198f (diff) | |
download | uxp-302bf1b523012e11b60425d6eee1221ebc2724eb.tar.gz |
Issue #1258 - Part 1: Import mailnews, ldap, and mork from comm-esr52.9.1
Diffstat (limited to 'db/mork/src/morkPool.h')
-rw-r--r-- | db/mork/src/morkPool.h | 152 |
1 files changed, 152 insertions, 0 deletions
diff --git a/db/mork/src/morkPool.h b/db/mork/src/morkPool.h new file mode 100644 index 0000000000..4cf9a4e045 --- /dev/null +++ b/db/mork/src/morkPool.h @@ -0,0 +1,152 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef _MORKPOOL_ +#define _MORKPOOL_ 1 + +#ifndef _MORK_ +#include "mork.h" +#endif + +#ifndef _MORKDEQUE_ +#include "morkDeque.h" +#endif + +#ifndef _MORKNODE_ +#include "morkNode.h" +#endif + +//3456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789 + +class morkHandle; +class morkHandleFrame; +class morkHandleFace; // just an opaque cookie type +class morkBigBookAtom; +class morkFarBookAtom; + +#define morkDerived_kPool /*i*/ 0x706C /* ascii 'pl' */ + +/*| morkPool: a place to manage pools of non-node objects that are memory +**| managed out of large chunks of space, so that per-object management +**| space overhead has no signficant cost. +|*/ +class morkPool : public morkNode { + +// public: // slots inherited from morkNode (meant to inform only) + // nsIMdbHeap* mNode_Heap; + + // mork_base mNode_Base; // must equal morkBase_kNode + // mork_derived mNode_Derived; // depends on specific node subclass + + // mork_access mNode_Access; // kOpen, kClosing, kShut, or kDead + // mork_usage mNode_Usage; // kHeap, kStack, kMember, kGlobal, kNone + // mork_able mNode_Mutable; // can this node be modified? + // mork_load mNode_Load; // is this node clean or dirty? + + // mork_uses mNode_Uses; // refcount for strong refs + // mork_refs mNode_Refs; // refcount for strong refs + weak refs + +public: // state is public because the entire Mork system is private + nsIMdbHeap* mPool_Heap; // NON-refcounted heap instance + + morkDeque mPool_Blocks; // linked list of large blocks from heap + + // These two lists contain instances of morkHandleFrame: + morkDeque mPool_UsedHandleFrames; // handle frames currently being used + morkDeque mPool_FreeHandleFrames; // handle frames currently in free list + + mork_count mPool_UsedFramesCount; // length of mPool_UsedHandleFrames + mork_count mPool_FreeFramesCount; // length of mPool_UsedHandleFrames + +// { ===== begin morkNode interface ===== +public: // morkNode virtual methods + virtual void CloseMorkNode(morkEnv* ev); // ClosePool() only if open + virtual ~morkPool(); // assert that ClosePool() executed earlier + +public: // morkPool construction & destruction + morkPool(const morkUsage& inUsage, nsIMdbHeap* ioHeap, + nsIMdbHeap* ioSlotHeap); + morkPool(morkEnv* ev, const morkUsage& inUsage, nsIMdbHeap* ioHeap, + nsIMdbHeap* ioSlotHeap); + void ClosePool(morkEnv* ev); // called by CloseMorkNode(); + +private: // copying is not allowed + morkPool(const morkPool& other); + morkPool& operator=(const morkPool& other); + +public: // dynamic type identification + mork_bool IsPool() const + { return IsNode() && mNode_Derived == morkDerived_kPool; } +// } ===== end morkNode methods ===== + +public: // typing + void NonPoolTypeError(morkEnv* ev); + +public: // morkNode memory management operators + void* operator new(size_t inSize, nsIMdbHeap& ioHeap, morkEnv* ev) CPP_THROW_NEW + { return morkNode::MakeNew(inSize, ioHeap, ev); } + + void* operator new(size_t inSize) CPP_THROW_NEW + { return ::operator new(inSize); } + + +public: // other pool methods + + // alloc and free individual instances of handles (inside hand frames): + morkHandleFace* NewHandle(morkEnv* ev, mork_size inSize, morkZone* ioZone); + void ZapHandle(morkEnv* ev, morkHandleFace* ioHandle); + + // alloc and free individual instances of rows: + morkRow* NewRow(morkEnv* ev, morkZone* ioZone); // alloc new row instance + void ZapRow(morkEnv* ev, morkRow* ioRow, morkZone* ioZone); // free old row instance + + // alloc and free entire vectors of cells (not just one cell at a time) + morkCell* NewCells(morkEnv* ev, mork_size inSize, morkZone* ioZone); + void ZapCells(morkEnv* ev, morkCell* ioVector, mork_size inSize, morkZone* ioZone); + + // resize (grow or trim) cell vectors inside a containing row instance + mork_bool AddRowCells(morkEnv* ev, morkRow* ioRow, mork_size inNewSize, morkZone* ioZone); + mork_bool CutRowCells(morkEnv* ev, morkRow* ioRow, mork_size inNewSize, morkZone* ioZone); + + // alloc & free individual instances of atoms (lots of atom subclasses): + void ZapAtom(morkEnv* ev, morkAtom* ioAtom, morkZone* ioZone); // any subclass (by kind) + + morkOidAtom* NewRowOidAtom(morkEnv* ev, const mdbOid& inOid, morkZone* ioZone); + morkOidAtom* NewTableOidAtom(morkEnv* ev, const mdbOid& inOid, morkZone* ioZone); + + morkAtom* NewAnonAtom(morkEnv* ev, const morkBuf& inBuf, + mork_cscode inForm, morkZone* ioZone); + // if inForm is zero, and inBuf.mBuf_Fill is less than 256, then a 'wee' + // anon atom will be created, and otherwise a 'big' anon atom. + + morkBookAtom* NewBookAtom(morkEnv* ev, const morkBuf& inBuf, + mork_cscode inForm, morkAtomSpace* ioSpace, mork_aid inAid, morkZone* ioZone); + // if inForm is zero, and inBuf.mBuf_Fill is less than 256, then a 'wee' + // book atom will be created, and otherwise a 'big' book atom. + + morkBookAtom* NewBookAtomCopy(morkEnv* ev, const morkBigBookAtom& inAtom, morkZone* ioZone); + // make the smallest kind of book atom that can hold content in inAtom. + // The inAtom parameter is often expected to be a staged book atom in + // the store, which was used to search an atom space for existing atoms. + + morkBookAtom* NewFarBookAtomCopy(morkEnv* ev, const morkFarBookAtom& inAtom, morkZone* ioZone); + // make the smallest kind of book atom that can hold content in inAtom. + // The inAtom parameter is often expected to be a staged book atom in + // the store, which was used to search an atom space for existing atoms. + +public: // typesafe refcounting inlines calling inherited morkNode methods + static void SlotWeakPool(morkPool* me, + morkEnv* ev, morkPool** ioSlot) + { morkNode::SlotWeakNode((morkNode*) me, ev, (morkNode**) ioSlot); } + + static void SlotStrongPool(morkPool* me, + morkEnv* ev, morkPool** ioSlot) + { morkNode::SlotStrongNode((morkNode*) me, ev, (morkNode**) ioSlot); } +}; + +//3456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789 + +#endif /* _MORKPOOL_ */ + |