home *** CD-ROM | disk | FTP | other *** search
/ ftp.sustworks.com 2018 / ftp.sustworks.com.zip / ftp.sustworks.com / USBAx8817x_101.dmg / src / Source / IOMbufQueue.h < prev    next >
C/C++ Source or Header  |  2005-10-08  |  4KB  |  194 lines

  1. /*
  2.  * Copyright (c) 1998-2000 Apple Computer, Inc. All rights reserved.
  3.  *
  4.  * @APPLE_LICENSE_HEADER_START@
  5.  * 
  6.  * The contents of this file constitute Original Code as defined in and
  7.  * are subject to the Apple Public Source License Version 1.1 (the
  8.  * "License").  You may not use this file except in compliance with the
  9.  * License.  Please obtain a copy of the License at
  10.  * http://www.apple.com/publicsource and read it before using this file.
  11.  * 
  12.  * This Original Code and all software distributed under the License are
  13.  * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
  14.  * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
  15.  * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
  16.  * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT.  Please see the
  17.  * License for the specific language governing rights and limitations
  18.  * under the License.
  19.  * 
  20.  * @APPLE_LICENSE_HEADER_END@
  21.  */
  22.  
  23. #ifndef _IOMBUFQUEUE_H
  24. #define _IOMBUFQUEUE_H
  25.  
  26. extern "C" {
  27. #include <sys/param.h>
  28. #if TIGER
  29.         #include <sys/kpi_mbuf.h>
  30. #else
  31.         //#include <sys/mbuf.h>
  32.         #include "mbufPanther.h"
  33. #endif
  34. }
  35.  
  36. struct IOMbufQueue {
  37.     mbuf_t  head;
  38.     mbuf_t  tail;
  39.     UInt32         size;
  40.     UInt32         capacity;
  41. };
  42.  
  43. static __inline__
  44. UInt32 IOMbufFree(mbuf_t m)
  45. {
  46. /*LD####
  47.     UInt32 count = 0;
  48.     mbuf_t mn;
  49.  
  50.     while (( mn = m ))
  51.     {
  52.         m = mbuf_nextpkt(mn);
  53.         mbuf_setnextpkt(mn, 0);
  54.         m_freem(mn);
  55.         count++;
  56.     }
  57.     return count;
  58. */
  59.     return mbuf_freem_list(m);
  60. }
  61.  
  62. static __inline__
  63. void IOMbufQueueInit(IOMbufQueue * q, UInt32 capacity)
  64. {
  65.     q->head = q->tail = 0;
  66.     q->size = 0;
  67.     q->capacity = capacity;
  68. }
  69.  
  70. static __inline__
  71. bool IOMbufQueueEnqueue(IOMbufQueue * q, mbuf_t m)
  72. {
  73.     if (q->size >= q->capacity) return false;
  74.  
  75.     if (q->size++ > 0)
  76.         mbuf_setnextpkt(q->tail, m);    //q->tail->m_nextpkt = m;
  77.     else
  78.         q->head = m;
  79.  
  80.     for (q->tail = m;
  81.          mbuf_nextpkt(q->tail);    //q->tail->m_nextpkt;
  82.          //q->tail = q->tail->m_nextpkt, q->size++)
  83.          q->tail = mbuf_nextpkt(q->tail), q->size++)
  84.         ;
  85.  
  86.     return true;
  87. }
  88.  
  89. static __inline__
  90. bool IOMbufQueueEnqueue(IOMbufQueue * q, IOMbufQueue * qe)
  91. {
  92.     if (qe->size)
  93.     {
  94.         if (q->size == 0)
  95.             q->head = qe->head;
  96.         else
  97.             //q->tail->m_nextpkt = qe->head;
  98.             mbuf_setnextpkt(q->tail, qe->head);
  99.         q->tail  = qe->tail;
  100.         q->size += qe->size;
  101.  
  102.         qe->head = qe->tail = 0;
  103.         qe->size = 0;
  104.     }
  105.     return true;
  106. }
  107.  
  108. static __inline__
  109. void IOMbufQueuePrepend(IOMbufQueue * q, mbuf_t m)
  110. {
  111.     mbuf_t tail;
  112.  
  113.     for (tail = m, q->size++;
  114.          //tail->m_nextpkt;
  115.          mbuf_nextpkt(tail);
  116.          //tail = tail->m_nextpkt, q->size++)
  117.          tail = mbuf_nextpkt(tail), q->size++)
  118.         ;
  119.  
  120.     //tail->m_nextpkt = q->head;
  121.     mbuf_setnextpkt(tail, q->head);
  122.     if (q->tail == 0)
  123.         q->tail = tail;
  124.     q->head = m;
  125. }
  126.  
  127. static __inline__
  128. void IOMbufQueuePrepend(IOMbufQueue * q, IOMbufQueue * qp)
  129. {
  130.     if (qp->size)
  131.     {
  132.         //qp->tail->m_nextpkt = q->head;
  133.         mbuf_setnextpkt(qp->tail, q->head);
  134.         if (q->tail == 0)
  135.             q->tail = qp->tail;
  136.         q->head  = qp->head;
  137.         q->size += qp->size;
  138.  
  139.         qp->head = qp->tail = 0;
  140.         qp->size = 0;
  141.     }
  142. }
  143.  
  144. static __inline__
  145. mbuf_t IOMbufQueueDequeue(IOMbufQueue * q)
  146. {   
  147.     mbuf_t m = q->head;
  148.     if (m)
  149.     {
  150.         //if ((q->head = m->m_nextpkt) == 0)
  151.         if ((q->head = mbuf_nextpkt(m)) == 0)
  152.             q->tail = 0;
  153.         //m->m_nextpkt = 0;
  154.         mbuf_setnextpkt(m, 0);
  155.         q->size--;
  156.     }
  157.     return m;
  158. }
  159.  
  160. static __inline__
  161. mbuf_t IOMbufQueueDequeueAll(IOMbufQueue * q)
  162. {
  163.     mbuf_t m = q->head;
  164.     q->head = q->tail = 0;
  165.     q->size = 0;
  166.     return m;
  167. }
  168.  
  169. static __inline__
  170. mbuf_t IOMbufQueuePeek(IOMbufQueue * q)
  171. {
  172.     return q->head;
  173. }
  174.  
  175. static __inline__
  176. UInt32 IOMbufQueueGetSize(IOMbufQueue * q)
  177. {
  178.     return q->size;
  179. }
  180.  
  181. static __inline__
  182. UInt32 IOMbufQueueGetCapacity(IOMbufQueue * q)
  183. {
  184.     return q->capacity;
  185. }
  186.  
  187. static __inline__
  188. void IOMbufQueueSetCapacity(IOMbufQueue * q, UInt32 capacity)
  189. {
  190.     q->capacity = capacity;
  191. }
  192.  
  193. #endif /* !_IOMBUFQUEUE_H */
  194.