struct_manager.h File Reference


Data Structures

struct  Structure_Manager

Defines

#define PRIVATE_SM   1
#define SHARED_SM   0
#define SET_TRIE_ALLOCATION_TYPE_TIP(pTIF)
#define SET_TRIE_ALLOCATION_TYPE_SF(pSF)
#define SET_TRIE_ALLOCATION_TYPE_PSC(pPSC)
#define SM_CurBlock(SM)   ((SM).cur_block.pBlock)
#define SM_NextStruct(SM)   ((SM).cur_block.pNextStruct)
#define SM_LastStruct(SM)   ((SM).cur_block.pLastStruct)
#define SM_StructSize(SM)   ((SM).struct_desc.size)
#define SM_StructsPerBlock(SM)   ((SM).struct_desc.num)
#define SM_StructName(SM)   ((SM).struct_desc.name)
#define SM_AllocList(SM)   ((SM).struct_lists.alloc)
#define SM_FreeList(SM)   ((SM).struct_lists.dealloc)
#define SM_NewBlockSize(SM)
#define SM_CurBlockIsDepleted(SM)   ( IsNULL(SM_CurBlock(SM)) || (SM_NextStruct(SM) > SM_LastStruct(SM)) )
#define SM_NumStructsLeftInBlock(SM)
#define SM_AllocateFree(SM, pNewStruct)
#define SM_AllocateFromBlock(SM, pNewStruct)
#define SMFL_NextFreeStruct(pFreeStruct)   ( *(void **)(pFreeStruct) )
#define SMBlk_NextBlock(pBlock)   ( *(void **)(pBlock) )
#define SMBlk_FirstStruct(pBlock)   ( (char *)pBlock + sizeof(void *) )
#define SMBlk_LastStruct(pBlock, StructSize, StructsPerBlock)   ( SMBlk_FirstStruct(pBlock) + StructSize * (StructsPerBlock - 1) )
#define SMBlk_NextStruct(pStruct, StructSize)   ( (char *)pStruct + StructSize )
#define SM_InitDecl(StructType, StructsPerBlock, NameString)
#define SM_InitDeclDyna(StructPtr, StructType, StructsPerBlock, NameString)
#define SM_AllocateSharedStruct(SM, pStruct)
#define SM_AllocateStruct(SM, pStruct)
#define SM_DeallocateSharedStructList(SM, pHead, pTail)   SM_DeallocateStructList(SM,pHead,pTail)
#define SM_DeallocateStructList(SM, pHead, pTail)
#define SM_DeallocateSharedStruct(SM, pStruct)   SM_DeallocateSharedStructList(SM,pStruct,pStruct)
#define SM_DeallocateStruct(SM, pStruct)   SM_DeallocateStructList(SM,pStruct,pStruct)
#define SM_DeallocatePossSharedStruct(SM, pStruct)   SM_DeallocateStruct(SM,pStruct)
#define SM_CurrentCapacity(SM, NumBlocks, NumStructs)
#define SM_CountFreeStructs(SM, NumFreeStructs)
#define SM_RawUsage(SM, UsageInBytes)
#define SM_ReleaseResources(SM)   smFreeBlocks(&SM)
#define SM_AddToAllocList_SL(SM, pRecord, LinkFieldMacro)
#define SM_AddToAllocList_DL(SM, pRecord, PrevFieldMacro, NextFieldMacro)
#define SM_RemoveFromAllocList_SL(SM, pRecord, LinkFieldMacro, RecordType)
#define SM_RemoveFromAllocList_DL(SM, pRecord, PrevFieldMacro, NextFieldMacro)

Typedefs

typedef Structure_Manager Structure_Manager
typedef Structure_ManagerSMptr

Functions

void smPrint (Structure_Manager, char *)
void smAllocateBlock (Structure_Manager *)
void smFreeBlocks (Structure_Manager *)
xsbBool smIsValidStructRef (Structure_Manager, void *)
xsbBool smIsAllocatedStruct (Structure_Manager, void *)
xsbBool smIsAllocatedStructRef (Structure_Manager, void *)

Define Documentation

#define PRIVATE_SM   1
 

#define SET_TRIE_ALLOCATION_TYPE_PSC pPSC   ) 
 

#define SET_TRIE_ALLOCATION_TYPE_SF pSF   ) 
 

#define SET_TRIE_ALLOCATION_TYPE_TIP pTIF   ) 
 

#define SHARED_SM   0
 

#define SM_AddToAllocList_DL SM,
pRecord,
PrevFieldMacro,
NextFieldMacro   ) 
 

Value:

{ \
   PrevFieldMacro(pRecord) = NULL;                                       \
   NextFieldMacro(pRecord) = SM_AllocList(SM);                           \
   SM_AllocList(SM) = pRecord;                                           \
   if ( IsNonNULL(NextFieldMacro(pRecord)) )                             \
     PrevFieldMacro(NextFieldMacro(pRecord)) = pRecord;                  \
 }

#define SM_AddToAllocList_SL SM,
pRecord,
LinkFieldMacro   ) 
 

Value:

{       \
   LinkFieldMacro(pRecord) = SM_AllocList(SM);                  \
   SM_AllocList(SM) = pRecord;                                  \
 }

#define SM_AllocateFree SM,
pNewStruct   ) 
 

Value:

pNewStruct = SM_FreeList(SM);                           \
   SM_FreeList(SM) = SMFL_NextFreeStruct(SM_FreeList(SM))

#define SM_AllocateFromBlock SM,
pNewStruct   ) 
 

Value:

#define SM_AllocateSharedStruct SM,
pStruct   ) 
 

Value:

{               \
  SYS_MUTEX_LOCK( MUTEX_SM );                           \
  if ( IsNonNULL(SM_FreeList(SM)) ) {                   \
    SM_AllocateFree(SM,pStruct);                        \
  }                                                     \
  else {                                                \
    if ( SM_CurBlockIsDepleted(SM) ) {                  \
      smAllocateBlock(&SM);                             \
    }                                                   \
    SM_AllocateFromBlock(SM,pStruct);                   \
  }                                                     \
  SYS_MUTEX_UNLOCK( MUTEX_SM );                         \
 }

#define SM_AllocateStruct SM,
pStruct   ) 
 

Value:

{               \
                                                \
   if ( IsNonNULL(SM_FreeList(SM)) ) {          \
     SM_AllocateFree(SM,pStruct);               \
   }                                            \
   else {                                       \
     if ( SM_CurBlockIsDepleted(SM) )           \
       smAllocateBlock(&SM);                    \
     SM_AllocateFromBlock(SM,pStruct);          \
   }                                            \
 }

#define SM_AllocList SM   )     ((SM).struct_lists.alloc)
 

#define SM_CountFreeStructs SM,
NumFreeStructs   ) 
 

Value:

{               \
                                                                \
   void *pStruct;                                               \
                                                                \
   if ( IsNonNULL(SM_CurBlock(SM)) ) {                          \
     NumFreeStructs = SM_NumStructsLeftInBlock(SM);             \
     for ( pStruct = SM_FreeList(SM);  IsNonNULL(pStruct);      \
           pStruct = SMFL_NextFreeStruct(pStruct) )             \
       NumFreeStructs++;                                        \
   }                                                            \
   else                                                         \
     NumFreeStructs = 0;                                        \
 }

#define SM_CurBlock SM   )     ((SM).cur_block.pBlock)
 

#define SM_CurBlockIsDepleted SM   )     ( IsNULL(SM_CurBlock(SM)) || (SM_NextStruct(SM) > SM_LastStruct(SM)) )
 

#define SM_CurrentCapacity SM,
NumBlocks,
NumStructs   ) 
 

Value:

{       \
                                                        \
   void *pBlock;                                        \
                                                        \
   NumBlocks = 0;                                       \
   for ( pBlock = SM_CurBlock(SM);  IsNonNULL(pBlock);  \
         pBlock = SMBlk_NextBlock(pBlock) )             \
     NumBlocks++;                                       \
   NumStructs = NumBlocks * SM_StructsPerBlock(SM);     \
 }

#define SM_DeallocatePossSharedStruct SM,
pStruct   )     SM_DeallocateStruct(SM,pStruct)
 

#define SM_DeallocateSharedStruct SM,
pStruct   )     SM_DeallocateSharedStructList(SM,pStruct,pStruct)
 

#define SM_DeallocateSharedStructList SM,
pHead,
pTail   )     SM_DeallocateStructList(SM,pHead,pTail)
 

#define SM_DeallocateStruct SM,
pStruct   )     SM_DeallocateStructList(SM,pStruct,pStruct)
 

#define SM_DeallocateStructList SM,
pHead,
pTail   ) 
 

Value:

{       \
   void *pStruct = pHead;                               \
   while (pStruct != pTail) {                           \
     *(((int *)pStruct)+1) = FREE_TRIE_NODE_MARK;       \
     pStruct = *(void **)pStruct;                       \
   }                                                    \
   *(((int *)pStruct)+1) = FREE_TRIE_NODE_MARK;         \
   SMFL_NextFreeStruct(pTail) = SM_FreeList(SM);        \
   SM_FreeList(SM) = pHead;                             \
 }

#define SM_FreeList SM   )     ((SM).struct_lists.dealloc)
 

#define SM_InitDecl StructType,
StructsPerBlock,
NameString   ) 
 

Value:

{       \
   {NULL, NULL, NULL},                                          \
   {sizeof(StructType), StructsPerBlock, NameString},           \
   {NULL, NULL}                                                 \
 }

#define SM_InitDeclDyna StructPtr,
StructType,
StructsPerBlock,
NameString   ) 
 

Value:

(StructPtr->cur_block).pBlock = NULL;                           \
  (StructPtr->cur_block).pNextStruct = NULL;                            \
  (StructPtr->cur_block).pLastStruct = NULL;                            \
  (StructPtr->struct_desc).size = sizeof(StructType);                   \
  (StructPtr->struct_desc).num = StructsPerBlock;                       \
  (StructPtr->struct_desc).name = NameString;                           \
  (StructPtr->struct_lists).alloc = NULL;                               \
  (StructPtr->struct_lists).dealloc = NULL;

#define SM_LastStruct SM   )     ((SM).cur_block.pLastStruct)
 

#define SM_NewBlockSize SM   ) 
 

Value:

/* in bytes */                  \
   ( sizeof(void *) + SM_StructSize(SM) * SM_StructsPerBlock(SM) )

#define SM_NextStruct SM   )     ((SM).cur_block.pNextStruct)
 

#define SM_NumStructsLeftInBlock SM   ) 
 

Value:

( ! SM_CurBlockIsDepleted(SM)                                    \
     ? ( ((char *)SM_LastStruct(SM) - (char *)SM_NextStruct(SM))         \
         / SM_StructSize(SM) + 1 )                                       \
     : 0 )

#define SM_RawUsage SM,
UsageInBytes   ) 
 

Value:

{                       \
                                                        \
   void *pBlock;                                        \
                                                        \
   UsageInBytes = 0;                                    \
   for ( pBlock = SM_CurBlock(SM);  IsNonNULL(pBlock);  \
         pBlock = SMBlk_NextBlock(pBlock) )             \
     UsageInBytes = UsageInBytes + SM_NewBlockSize(SM); \
 }

#define SM_ReleaseResources SM   )     smFreeBlocks(&SM)
 

#define SM_RemoveFromAllocList_DL SM,
pRecord,
PrevFieldMacro,
NextFieldMacro   ) 
 

Value:

{ \
   if ( IsNonNULL(PrevFieldMacro(pRecord)) )                                  \
     NextFieldMacro(PrevFieldMacro(pRecord)) = NextFieldMacro(pRecord);       \
   else {                                                                     \
     if ( SM_AllocList(SM) == pRecord )                                       \
       SM_AllocList(SM) = NextFieldMacro(pRecord);                            \
     else {                                                             \
       xsb_abort("Record not present in given Structure Manager: %s",         \
                 SM_StructName(SM));                                          \
     }                                                                  \
   }                                                                          \
   if ( IsNonNULL(NextFieldMacro(pRecord)) )                                  \
     PrevFieldMacro(NextFieldMacro(pRecord)) = PrevFieldMacro(pRecord);       \
   NextFieldMacro(pRecord) = PrevFieldMacro(pRecord) = NULL;                  \
 }

#define SM_RemoveFromAllocList_SL SM,
pRecord,
LinkFieldMacro,
RecordType   ) 
 

Value:

{ \
                                                                          \
   RecordType pCur, pPrev;                                                \
                                                                          \
   for ( pPrev = NULL, pCur = SM_AllocList(SM);                           \
         IsNonNULL(pCur);                                                 \
         pPrev = pCur, pCur = LinkFieldMacro(pCur) )                      \
     if ( pCur == pRecord )                                               \
       break;                                                             \
   if ( IsNonNULL(pCur) ) {                                               \
     if ( IsNonNULL(pPrev) )                                              \
       LinkFieldMacro(pPrev) = LinkFieldMacro(pCur);                      \
     else                                                                 \
       SM_AllocList(SM) = LinkFieldMacro(pCur);                           \
     LinkFieldMacro(pCur) = NULL;                                         \
   }                                                                      \
   else                                                                   \
     xsb_warn("Record not present in given Structure Manager: %s",        \
              SM_StructName(SM));                                         \
 }

#define SM_StructName SM   )     ((SM).struct_desc.name)
 

#define SM_StructSize SM   )     ((SM).struct_desc.size)
 

#define SM_StructsPerBlock SM   )     ((SM).struct_desc.num)
 

#define SMBlk_FirstStruct pBlock   )     ( (char *)pBlock + sizeof(void *) )
 

#define SMBlk_LastStruct pBlock,
StructSize,
StructsPerBlock   )     ( SMBlk_FirstStruct(pBlock) + StructSize * (StructsPerBlock - 1) )
 

#define SMBlk_NextBlock pBlock   )     ( *(void **)(pBlock) )
 

#define SMBlk_NextStruct pStruct,
StructSize   )     ( (char *)pStruct + StructSize )
 

#define SMFL_NextFreeStruct pFreeStruct   )     ( *(void **)(pFreeStruct) )
 


Typedef Documentation

typedef struct Structure_Manager* SMptr
 

typedef struct Structure_Manager Structure_Manager
 


Function Documentation

void smAllocateBlock Structure_Manager  ) 
 

void smFreeBlocks Structure_Manager  ) 
 

xsbBool smIsAllocatedStruct Structure_Manager  ,
void * 
 

xsbBool smIsAllocatedStructRef Structure_Manager  ,
void * 
 

xsbBool smIsValidStructRef Structure_Manager  ,
void * 
 

void smPrint Structure_Manager  ,
char * 
 


Generated on Wed Jul 26 13:26:54 2006 for XSB by  doxygen 1.4.5