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

VxWorks

开发平台:

C/C++

  1. /* qLib.h - multi-way queue library header */
  2. /* Copyright 1984-1992 Wind River Systems, Inc. */
  3. /*
  4. modification history
  5. --------------------
  6. 02d,15oct93,cd   added #ifndef _ASMLANGUAGE.
  7. 02c,22sep92,rrr  added support for c++
  8. 02b,19jul92,pme  made qRemove return STATUS.
  9. 02a,04jul92,jcf  cleaned up.
  10. 01i,26may92,rrr  the tree shuffle
  11. 01h,04oct91,rrr  passed through the ansification filter
  12.   -fixed #else and #endif
  13.   -changed copyright notice
  14. 01g,10jun91.del  added pragma for gnu960 alignment.
  15. 01f,05apr91,gae  added NOMANUAL to avoid fooling mangen.
  16. 01e,05oct90,shl  added copyright notice.
  17.                  made #endif ANSI style.
  18. 01d,02oct90,jcf  removed nested comments.
  19. 01c,05jul90,jcf  added Q_CALIBRATE.
  20. 01b,26jun90,jcf  added definition of all queue class ids/types.
  21.  remove includes of all queue classes.
  22.  defined Q_NODE/Q_HEAD as independent structure.
  23.  added Q_RESORT().
  24. 01a,21oct89,jcf  written.
  25. */
  26. #ifndef __INCqLibh
  27. #define __INCqLibh
  28. #ifdef __cplusplus
  29. extern "C" {
  30. #endif
  31. #include "vxWorks.h"
  32. #include "vwModNum.h"
  33. #include "qClass.h"
  34. /* status codes */
  35. #define S_qLib_Q_CLASS_ID_ERROR (M_qLib | 1)
  36. #ifndef _ASMLANGUAGE
  37. /* queue classes */
  38. IMPORT Q_CLASS_ID qFifoClassId;
  39. IMPORT Q_CLASS_ID qPriListClassId;
  40. IMPORT Q_CLASS_ID qPriListFromTailClassId;
  41. IMPORT Q_CLASS_ID qPriDeltaClassId;
  42. IMPORT Q_CLASS_ID qPriHeapClassId;
  43. IMPORT Q_CLASS_ID qPriBMapClassId;
  44. /* queue types */
  45. #define Q_FIFO qFifoClassId
  46. #define Q_PRI_LIST qPriListClassId
  47. #define Q_PRI_LIST_FROM_TAIL qPriListFromTailClassId
  48. #define Q_PRI_DELTA qPriDeltaClassId
  49. #define Q_PRI_HEAP qPriHeapClassId
  50. #define Q_PRI_BMAP qPriBMapClassId
  51. /* HIDDEN */
  52. /* All queue class nodes must not exceed the sizeof (Q_NODE).  If larger data
  53.  * structures must be used, use one of the private fields as pointer to provide
  54.  * a level on indirection so the size of Q_NODE is not exceeded.
  55.  */
  56. #if CPU_FAMILY==I960
  57. #pragma align 1 /* tell gcc960 not to optimize alignments */
  58. #endif /* CPU_FAMILY==I960 */
  59. typedef struct /* Q_NODE */
  60.     {
  61.     UINT     qPriv1; /* use is queue type dependent */
  62.     UINT     qPriv2; /* use is queue type dependent */
  63.     UINT     qPriv3; /* use is queue type dependent */
  64.     UINT     qPriv4; /* use is queue type dependent */
  65.     } Q_NODE;
  66. /* All queue classes must not exceed the sizeof (Q_HEAD).  If larger data
  67.  * structures must be used, use one of the private fields as pointer to provide
  68.  * a level on indirection so the size of Q_HEAD is not exceeded.
  69.  *
  70.  * The first field in the Q_HEAD must contain the highest priority Q_NODE.
  71.  * The routine qFirst () makes this assumption.  The scheduler does a qFirst
  72.  * on the ready queue as part of its scheduling.
  73.  */
  74. typedef struct /* Q_HEAD */
  75.     {
  76.     Q_NODE  *pFirstNode; /* first node in queue based on key */
  77.     UINT     qPriv1; /* use is queue type dependent */
  78.     UINT     qPriv2; /* use is queue type dependent */
  79.     Q_CLASS *pQClass; /* pointer to queue class */
  80.     } Q_HEAD;
  81. #if CPU_FAMILY==I960
  82. #pragma align 0 /* turn off alignment requirement */
  83. #endif /* CPU_FAMILY==I960 */
  84. /* END HIDDEN */
  85. /*******************************************************************************
  86. *
  87. * Q_FIRST - return first node in multi-way queue
  88. *
  89. * This routine returns a pointer to the first node in the specified multi-way
  90. * queue head.  If the queue is empty, NULL is returned.
  91. *
  92. * RETURNS
  93. *  Pointer to first queue node in queue head, or
  94. *  NULL if queue is empty.
  95. *
  96. * NOMANUAL
  97. */
  98. #define Q_FIRST(pQHead)
  99.     ((Q_NODE *)(((Q_HEAD *)(pQHead))->pFirstNode))
  100. /*******************************************************************************
  101. *
  102. * Q_PUT - insert a node into a multi-way queue
  103. *
  104. * This routine inserts a node into a multi-way queue.  The insertion is based
  105. * on the key and the underlying queue class.
  106. *
  107. * NOMANUAL
  108. */
  109. #define Q_PUT(pQHead,pQNode,key)
  110.     (*(((Q_HEAD *)(pQHead))->pQClass->putRtn))
  111.     (((Q_HEAD *)(pQHead)), ((Q_NODE *)(pQNode)), (key))
  112. /*******************************************************************************
  113. *
  114. * Q_GET - remove and return first node in multi-way queue
  115. *
  116. * This routine removes and returns the first node in a multi-way queue.  If
  117. * the queue is empty, NULL is returned.
  118. *
  119. * RETURNS
  120. *  Pointer to first queue node in queue head, or
  121. *  NULL if queue is empty.
  122. *
  123. * NOMANUAL
  124. */
  125. #define Q_GET(pQHead)
  126.     ((Q_NODE *)((*(((Q_HEAD *)(pQHead))->pQClass->getRtn))
  127.      ((Q_HEAD *)(pQHead))))
  128. /*******************************************************************************
  129. *
  130. * Q_REMOVE - remove a node from a multi-way queue
  131. *
  132. * This routine removes a node from the specified multi-way queue.
  133. *
  134. * NOMANUAL
  135. */
  136. #define Q_REMOVE(pQHead,pQNode)
  137.     (*(((Q_HEAD *)(pQHead))->pQClass->removeRtn))
  138.     (((Q_HEAD *)(pQHead)), ((Q_NODE *)(pQNode)))
  139. /*******************************************************************************
  140. *
  141. * Q_RESORT - resort a node to a new position based on a new key
  142. *
  143. * This routine resorts a node to a new position based on a new key.  It can
  144. * be used to change the priority of a queued element, for instance.
  145. *
  146. * NOMANUAL
  147. */
  148. #define Q_RESORT(pQHead,pQNode,newKey)
  149.     (*(((Q_HEAD *)(pQHead))->pQClass->resortRtn))
  150.     (((Q_HEAD *)(pQHead)), ((Q_NODE *)(pQNode)), ((ULONG)(newKey)))
  151. /*******************************************************************************
  152. *
  153. * Q_ADVANCE - advance a queues concept of time (timer queues only)
  154. *
  155. * Multi-way queues that keep nodes prioritized by time-to-fire utilize this
  156. * routine to advance time.  It is usually called from within a clock-tick
  157. * interrupt service routine.
  158. *
  159. * NOMANUAL
  160. */
  161. #define Q_ADVANCE(pQHead)
  162.     (*(((Q_HEAD *)(pQHead))->pQClass->advanceRtn))
  163.     (((Q_HEAD *)(pQHead)))
  164. /*******************************************************************************
  165. *
  166. * Q_GET_EXPIRED - return a time-to-fire expired node
  167. *
  168. * This routine returns a time-to-fire expired node in a multi-way timer queue.
  169. * Expired nodes result from a qAdvance(2) advancing a node beyond its delay.
  170. * As many nodes may expire on a single qAdvance(2), this routine should be
  171. * called inside a while loop until NULL is returned.  NULL is returned when
  172. * there are no expired nodes.
  173. *
  174. * RETURNS
  175. *  Pointer to first queue node in queue head, or
  176. *  NULL if queue is empty.
  177. *
  178. * NOMANUAL
  179. */
  180. #define Q_GET_EXPIRED(pQHead)
  181.     ((Q_NODE *)((*(((Q_HEAD *)(pQHead))->pQClass->getExpiredRtn))
  182.      ((Q_HEAD *)(pQHead))))
  183. /*******************************************************************************
  184. *
  185. * Q_KEY - return the key of a node
  186. *
  187. * This routine returns the key of a node currently in a multi-way queue.  The
  188. * keyType determines key style on certain queue classes.
  189. *
  190. * RETURNS
  191. *  Node's key.
  192. *
  193. * NOMANUAL
  194. */
  195. #define Q_KEY(pQHead,pQNode,keyType)
  196.     (*(((Q_HEAD *)(pQHead))->pQClass->keyRtn))
  197.     (((Q_NODE *)(pQNode)), ((int)(keyType)))
  198. /*******************************************************************************
  199. *
  200. * Q_CALIBRATE - offset every node in a queue by some delta
  201. *
  202. * This routine offsets every node in a multi-way queue by some delta.  The
  203. * offset may either by positive or negative.
  204. *
  205. * NOMANUAL
  206. */
  207. #define Q_CALIBRATE(pQHead,keyDelta)
  208.     (*(((Q_HEAD *)(pQHead))->pQClass->calibrateRtn))
  209.     (((Q_HEAD *)(pQHead)), ((int)(keyDelta)))
  210. /*******************************************************************************
  211. *
  212. * Q_INFO - gather information on a multi-way queue
  213. *
  214. * This routine fills up to maxNodes elements of a nodeArray with nodes
  215. * currently in a multi-way queue.  The actual number of nodes copied to the
  216. * array is returned.  If the nodeArray is NULL, then the number of nodes in
  217. * the multi-way queue is returned.
  218. *
  219. * RETURNS
  220. *  Number of node pointers copied into the nodeArray, or
  221. *  Number of nodes in multi-way queue if nodeArray is NULL
  222. *
  223. * NOMANUAL
  224. */
  225. #define Q_INFO(pQHead,nodeArray,maxNodes)
  226.     (*(((Q_HEAD *)(pQHead))->pQClass->infoRtn))
  227.     (((Q_HEAD *)(pQHead)),((int *)(nodeArray)),((int)(maxNodes)))
  228. /*******************************************************************************
  229. *
  230. * Q_EACH - call a routine for each node in a queue
  231. *
  232. * This routine calls a user-supplied routine once for each node in the
  233. * queue.  The routine should be declared as follows:
  234. * .CS
  235. *  BOOL routine (pQNode, arg)
  236. *      Q_NODE *pQNode; * pointer to a queue node          *
  237. *      int arg; * arbitrary user-supplied argument *
  238. * .CE
  239. * The user-supplied routine should return TRUE if qEach (2) is to continue
  240. * calling it for each entry, or FALSE if it is done and qEach can exit.
  241. *
  242. * RETURNS: NULL if traversed whole queue, or pointer to Q_NODE that
  243. *          qEach ended with.
  244. *
  245. * NOMANUAL
  246. */
  247. #define Q_EACH(pQHead,routine,routineArg)
  248.     ((Q_NODE *)((*(((Q_HEAD *)(pQHead))->pQClass->eachRtn))
  249.     (((Q_HEAD *)(pQHead)),((FUNCPTR)(routine)),((int)(routineArg)))))
  250. #if defined(__STDC__) || defined(__cplusplus)
  251. extern Q_HEAD * qCreate (Q_CLASS *pQClass, ...);
  252. extern Q_NODE * qEach (Q_HEAD *pQHead, FUNCPTR routine, int routineArg);
  253. extern Q_NODE * qFirst (Q_HEAD *pQHead);
  254. extern Q_NODE * qGet (Q_HEAD *pQHead);
  255. extern Q_NODE * qGetExpired (Q_HEAD *pQHead);
  256. extern STATUS  qDelete (Q_HEAD *pQHead);
  257. extern STATUS  qInit (Q_HEAD *pQHead, Q_CLASS *pQClass, ...);
  258. extern STATUS  qTerminate (Q_HEAD *pQHead);
  259. extern ULONG  qKey (Q_HEAD *pQHead, Q_NODE *pQNode, int keyType);
  260. extern int  qInfo (Q_HEAD *pQHead, Q_NODE *nodeArray [ ], int maxNodes);
  261. extern void  qAdvance (Q_HEAD *pQHead);
  262. extern void  qCalibrate (Q_HEAD *pQHead, ULONG keyDelta);
  263. extern void  qPut (Q_HEAD *pQHead, Q_NODE *pQNode, ULONG key);
  264. extern STATUS  qRemove (Q_HEAD *pQHead, Q_NODE *pQNode);
  265. extern void  qResort (Q_HEAD *pQHead, Q_NODE *pQNode, ULONG newKey);
  266. #else /* __STDC__ */
  267. extern Q_HEAD * qCreate ();
  268. extern Q_NODE * qEach ();
  269. extern Q_NODE * qFirst ();
  270. extern Q_NODE * qGet ();
  271. extern Q_NODE * qGetExpired ();
  272. extern STATUS  qDelete ();
  273. extern STATUS  qInit ();
  274. extern STATUS  qTerminate ();
  275. extern ULONG  qKey ();
  276. extern int  qInfo ();
  277. extern void  qAdvance ();
  278. extern void  qCalibrate ();
  279. extern void  qPut ();
  280. extern STATUS  qRemove ();
  281. extern void  qResort ();
  282. #endif /* __STDC__ */
  283. #endif /* _ASMLANGUAGE */
  284. #ifdef __cplusplus
  285. }
  286. #endif
  287. #endif /* __INCqLibh */