gonzui


Format: Advanced Search

tkernel_2/include/sys/queue.hbare sourcepermlink (0.01 seconds)

Search this content:

    1: /*
    2:  *----------------------------------------------------------------------
    3:  *    T-Kernel 2.0 Software Package
    4:  *
    5:  *    Copyright 2011 by Ken Sakamura.
    6:  *    This software is distributed under the latest version of T-License 2.x.
    7:  *----------------------------------------------------------------------
    8:  *
    9:  *    Released by T-Engine Forum(http://www.t-engine.org/) at 2011/05/17.
   10:  *    Modified by TRON Forum(http://www.tron.org/) at 2015/06/01.
   11:  *
   12:  *----------------------------------------------------------------------
   13:  */
   14: 
   15: /*
   16:  *      @(#)queue.h (sys)
   17:  *
   18:  *      Queuing operation
   19:  */
   20: 
   21: #ifndef __SYS_QUEUE_H__
   22: #define __SYS_QUEUE_H__
   23: 
   24: #include <basic.h>
   25: 
   26: #ifdef __cplusplus
   27: extern "C" {
   28: #endif
   29: 
   30: /*
   31:  * Double-link queue (ring)
   32:  */
   33: typedef struct queue {
   34:         struct queue   *next;
   35:         struct queue   *prev;
   36: } QUEUE;
   37: 
   38: /*
   39:  * Queue initialization
   40:  */
   41: Inline void QueInit( QUEUE *que )
   42: {
   43:         que->next = (struct queue *)que;
   44:         que->prev = (struct queue *)que;
   45: }
   46: 
   47: /*
   48:  * TRUE if the queue is empty
   49:  */
   50: Inline BOOL isQueEmpty( QUEUE *que )
   51: {
   52:         return ( que->next == que )? TRUE: FALSE;
   53: }
   54: 
   55: /*
   56:  * Insert in queue
   57:  *      Inserts entry directly prior to que
   58:  */
   59: Inline void QueInsert( QUEUE *entry, QUEUE *que )
   60: {
   61:         entry->prev = (struct queue*) que->prev;
   62:         entry->next = que;
   63:         que->prev->next = entry;
   64:         que->prev = entry;
   65: }
   66: 
   67: /*
   68:  * Delete from queue
   69:  *      Deletes entry from queue
   70:  *      No action is performed if entry is empty.
   71:  */
   72: Inline void QueRemove( QUEUE *entry )
   73: {
   74:         if ( entry->next != entry ) {
   75:                 entry->prev->next = (struct queue*) entry->next;
   76:                 entry->next->prev = (struct queue*) entry->prev;
   77:         }
   78: }
   79: 
   80: /*
   81:  * Remove top entry
   82:  *      Deletes the entry directly after que from the queue,
   83:  *      and returns the deleted entry.
   84:  *      Returns NULL if que is empty.
   85:  */
   86: Inline QUEUE* QueRemoveNext( QUEUE *que )
   87: {
   88:         QUEUE  *entry;
   89: 
   90:         if ( que->next == que ) {
   91:                 return NULL;
   92:         }
   93: 
   94:         entry = que->next;
   95:         que->next = (struct queue*)entry->next;
   96:         entry->next->prev = que;
   97: 
   98:         return entry;
   99: }
  100: 
  101: /*
  102:  * Queue search
  103:  *      Searches entries in the forward direction from start->next
  104:  *      to end->prev.
  105:  *      Compares the value at the offset position with val, and returns
  106:  *      matching entries.
  107:  *      Returns end if no suitable entries are found.
  108:  *      start and end are not included in the search.
  109:  *
  110:  *      QueSearch [conditions][data type](start, end, val, offset)
  111:  *
  112:  *      Conditions
  113:  *      None offset position value = val
  114:  *      NE   offset position value != val
  115:  *      GT   offset position value > val
  116:  *      GE   offset position value >= val
  117:  *      LT   offset position value < val
  118:  *
  119:  *      Data type
  120:  *      None W
  121:  *      U    UW
  122:  *      H    H
  123:  *      UB   UB
  124:  *
  125:  *      for ( que = start->next; que != end; que = que->next ) {
  126:  *              if ( *(data type*)((VB*)que + offset) conditions val ) {
  127:  *                      break;
  128:  *              }
  129:  *      }
  130:  *      return que;
  131:  */
  132: IMPORT QUEUE* QueSearch    ( QUEUE *start, QUEUE *end, W  val, W offset );
  133: IMPORT QUEUE* QueSearchH   ( QUEUE *start, QUEUE *end, H  val, W offset );
  134: IMPORT QUEUE* QueSearchNE  ( QUEUE *start, QUEUE *end, W  val, W offset );
  135: IMPORT QUEUE* QueSearchNEH ( QUEUE *start, QUEUE *end, H  val, W offset );
  136: IMPORT QUEUE* QueSearchGT  ( QUEUE *start, QUEUE *end, W  val, W offset );
  137: IMPORT QUEUE* QueSearchGTUB( QUEUE *start, QUEUE *end, UB val, W offset );
  138: IMPORT QUEUE* QueSearchGE  ( QUEUE *start, QUEUE *end, W  val, W offset );
  139: IMPORT QUEUE* QueSearchGEU ( QUEUE *start, QUEUE *end, UW val, W offset );
  140: 
  141: /*
  142:  * Queue search (reverse order)
  143:  *      Searches entries in the reverse direction from start->prev to
  144:  *      end->next.
  145:  *      Otherwise identical to QueSearch.
  146:  *      QueSearchRev[conditions][data type](start, end, val, offset)
  147:  *
  148:  *      for ( que = start->prev; que != end; que = que->prev ) {
  149:  *              if ( *(data type*)((VB*)que + offset) conditions val ) {
  150:  *                      break;
  151:  *              }
  152:  *      }
  153:  *      return que;
  154:  */
  155: IMPORT QUEUE* QueSearchRevLTU( QUEUE *start, QUEUE *end, UW val, W offset );
  156: 
  157: #ifdef __cplusplus
  158: }
  159: #endif
  160: #endif /* __SYS_QUEUE_H__ */