smMemLibP.h
上传用户:luoyougen
上传日期:2008-05-12
资源大小:23136k
文件大小:5k
源码类别:

VxWorks

开发平台:

C/C++

  1. /* smMemLibP.h - private shared memory management library header file */
  2. /* Copyright 1984-2002 Wind River Systems, Inc. */
  3. /*
  4. modification history
  5. --------------------
  6. 01h,05may02,mas  added volatile pointers (SPR 68334)
  7. 01g,29jan93,pme  added little endian support
  8.  changed SM_BLOCK_HDR structure to avoid bit field use.
  9. 01f,29sep92,pme  added smMemPartShow prototype 
  10. 01e,22sep92,rrr  added support for c++
  11. 01d,14sep92,smb  removed the prototype for smMemPartShow()
  12. 01c,28jul92,pme  added align pragma for I960.
  13. 01b,21jul92,pme  removed MEM_ROUND_UP and  MEM_IS_ROUND.
  14. 01a,19jul92,pme  extracted from smMemLib v1b.
  15. */
  16. #ifndef __INCsmMemLibPh
  17. #define __INCsmMemLibPh
  18. #ifdef __cplusplus
  19. extern "C" {
  20. #endif
  21. #include "vwModNum.h"
  22. #include "smMemLib.h"
  23. #include "smDllLib.h"
  24. #include "private/semSmLibP.h"
  25. /* defines */
  26. #define MEM_PART_TYPE_SM_STD 20 /* standard shared memory partition */
  27. #if (defined (CPU_FAMILY) && (CPU_FAMILY==I960) && (defined __GNUC__))
  28. #pragma align 1                 /* tell gcc960 not to optimize alignments */
  29. #endif  /* CPU_FAMILY==I960 */
  30. /* typedefs */
  31. typedef struct sm_obj_partition
  32.     {
  33.     UINT32       verify;               /* partition is initialized */
  34.     UINT32       objType;               /* partition type */
  35.     SM_DL_LIST   freeList;              /* list of free blocks */
  36.     SM_SEMAPHORE sem;                   /* partition semaphore */
  37.     unsigned     totalWords;            /* total number of words in pool */
  38.     unsigned     minBlockWords;         /* min blk size in words includes hdr */
  39.     unsigned     options;               /* options */
  40.     /* allocation statistics */
  41.     unsigned curBlocksAllocated;        /* current # of blocks allocated */
  42.     unsigned curWordsAllocated;         /* current # of words allocated */
  43.     unsigned cumBlocksAllocated;        /* cumulative # of blocks allocated */
  44.     unsigned cumWordsAllocated;         /* cumulative # of words allocated */
  45.     } SM_PARTITION;
  46. typedef struct sm_block_hdr     /* SM_BLOCK_HDR */
  47.     {
  48.     struct sm_block_hdr * pPrevHdr;  /* pointer to previous block hdr */
  49.     unsigned              nWords; /* size in words of this block */
  50.     unsigned              free; /* TRUE = this block is free */
  51.     UINT32   pad; /* 4 byte pad for round up */
  52.     } SM_BLOCK_HDR;
  53. /* SM_FREE_BLOCK is the structure for a free block.  It includes the freelist
  54.  * node in addition to the usual header. */
  55. typedef struct sm_free_block    /* SM_FREE_BLOCK */
  56.     {
  57.     SM_BLOCK_HDR  hdr; /* normal block header */
  58.     SM_DL_NODE  node; /* freelist links */
  59.     UINT32              pad; /* 4 byte pad for round up */
  60.     } SM_FREE_BLOCK;
  61. /* defines */
  62. /* macros for getting to next and previous blocks */
  63. #define SM_NEXT_HDR(pHdr) 
  64.     ((SM_BLOCK_HDR *) ((char *) (pHdr) + (2 * ntohl ((int) ((pHdr)->nWords)))))
  65. #define SM_PREV_HDR(pHdr) 
  66.     ((SM_BLOCK_HDR *) (GLOB_TO_LOC_ADRS (ntohl ((int) ((pHdr)->pPrevHdr)))))
  67. /* macros for converting between the "block" that caller knows
  68.  * (actual available data area) and the block header in front of it */
  69. #define SM_HDR_TO_BLOCK(pHdr)   ((char *) ((int) pHdr + sizeof (SM_BLOCK_HDR)))
  70. #define SM_BLOCK_TO_HDR(pBlock) ((SM_BLOCK_HDR *) ((int) pBlock - 
  71.                                                 sizeof(SM_BLOCK_HDR)))
  72. /* macros for converting between the "node" that is strung on the freelist
  73.  * and the block header in front of it */
  74. #define SM_HDR_TO_NODE(pHdr)    (& ((SM_FREE_BLOCK *) pHdr)->node)
  75. #define SM_NODE_TO_HDR(pNode)   ((SM_BLOCK_HDR *) ((int) pNode - 
  76.                                                 OFFSET (SM_FREE_BLOCK, node)))
  77. #if defined(__STDC__) || defined(__cplusplus)
  78. extern void   smMemPartLibInit (void);
  79. extern void   smMemPartInit (SM_PART_ID partId, char * pPool,
  80.                              unsigned poolSize);
  81. extern STATUS smMemPartAddToPool (SM_PART_ID partId, char * pPool,
  82.                                   unsigned poolSize);
  83. extern STATUS smMemPartFree (SM_PART_ID partId, char * pBlock);
  84. extern STATUS smMemPartOptionsSet (SM_PART_ID partId, unsigned options);
  85. extern int    smMemPartFindMax (SM_PART_ID partId);
  86. extern void * smMemPartAlloc (SM_PART_ID partId, unsigned nBytes);
  87. extern void * smMemPartRealloc (SM_PART_ID partId, char * pBlock,
  88.                                 unsigned nBytes);
  89. extern STATUS smMemPartAccessGet (SM_PART_ID partId);
  90. extern STATUS smMemPartAccessRelease (SM_PART_ID partId);
  91. extern BOOL   smMemPartBlockIsValid (SM_PART_ID volatile partId,
  92.                                      SM_BLOCK_HDR volatile * pHdr,
  93.                                      BOOL isFree);
  94. extern STATUS smMemPartShow (SM_PART_ID gPartId, int type);
  95. #else   /* __STDC__ */
  96. extern void   smMemPartLibInit ();
  97. extern STATUS smMemPartAddToPool ();
  98. extern STATUS smMemPartFree ();
  99. extern STATUS smMemPartOptionsSet ();
  100. extern int    smMemPartFindMax ();
  101. extern void * smMemPartAlloc ();
  102. extern void * smMemPartRealloc ();
  103. extern STATUS smMemPartAccessGet ();
  104. extern STATUS smMemPartAccessRelease ();
  105. extern BOOL   smMemPartBlockIsValid ();
  106. extern STATUS smMemPartShow ();
  107. #endif  /* __STDC__ */
  108. #if (defined (CPU_FAMILY) && (CPU_FAMILY==I960) && (defined __GNUC__))
  109. #pragma align 0                 /* turn off alignment requirement */
  110. #endif  /* CPU_FAMILY==I960 */
  111. #ifdef __cplusplus
  112. }
  113. #endif
  114. #endif /* __INCsmMemLibPh */