OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
dequeue.c
Go to the documentation of this file.
1 #include "FP_failed_pkt_queue.h"
2 #include "L1A_prototype.h"
3 
4 
5 char *dequeue ( FP_QUEUE_t Q )
6 
7 /*
8 !C************************************************************************
9 
10 !Description: Removes the first item from the front of the queue and
11  returns it. If the queue is empty, NULL is returned.
12 
13 !Input Parameters:
14  None
15 
16 !Output Parameters:
17  None
18 
19 !Input/Output Parameters:
20  FP_QUEUE_t Q ** The FIFO queue from which to
21  dequeue an item **
22 
23 Return Values:
24  NULL
25  item ** the item that is first in
26  line (or NULL if Q is empty) **
27 
28 Externally Defined:
29  FP_QUEUE_t (FP_failed_pkt_queue.h)
30 
31 Called By:
32  write_failed_packets
33 
34 Routines Called:
35  None
36 
37 !Revision History:
38  Revision 2.0 2001/01/04
39  John Seaton (seaton@ltpmail.gsfc.nasa.gov)
40  Simplified code. Removed call to is_empty
41 
42  Revision 1.0 1997/07/14 15:58 EDT
43  David Catozzi/SAIC/GSC (cato@ltpmail.gsfc.nasa.gov)
44  Originated code development.
45 
46 !Team-unique Header:
47  This software is developed by the MODIS Science
48  Data Support Team (SDST) for the National Aeronautics
49  and Space Administration (NASA), Goddard Space Flight
50  Center (GSFC), under contract NAS5-32373.
51 
52 !References and Credits:
53  None
54 
55 !Design Notes:
56  None
57 
58 !END************************************************************************
59 */
60 
61 {
62  /***************************************************************************/
63  /* Declare and Initialize Local Variables */
64  /***************************************************************************/
65 
66  node_ptr first_cell;
67  char *item=NULL;
68 
69 
70  /***************************************************************************/
71  /* */
72  /* IF (NOT((Q == NULL) OR (Q->head == NULL)) */
73  /* THEN */
74  /* CALL is_empty to ascertain whether or not there are any items on the */
75  /* queue. */
76  /* INPUTS: Q */
77  /* OUTPUTS: None */
78  /* RETURNS: queue_is_empty */
79  /* */
80  /* IF ( queue_is_empty equals True ) */
81  /* THEN */
82  /* set item to NULL */
83  /* ELSE */
84  /* */
85  /* set first_cell to Q.head.next */
86  /* set item to first_cell.element */
87  /* set Q.head.next to Q.head.next.next */
88  /* */
89  /* free the dynamically allocated memory (first_cell) */
90  /* */
91  /* set Q.head.next.prev to Q.head */
92  /* ENDIF */
93  /* ENDIF */
94  /* */
95  /***************************************************************************/
96 
97  if (!(Q == NULL) || (Q->head == NULL)) {
98 
99  if( Q->head->next == Q->tail ) /* check for empty queue */
100  item = NULL;
101  else {
102  first_cell = Q->head->next;
103  item = first_cell->element;
104  Q->head->next = Q->head->next->next;
105 
106  free( first_cell );
107 
108  Q->head->next->prev = Q->head;
109  }
110  }
111 
112 
113  /***************************************************************************/
114  /* */
115  /* RETURN item */
116  /* */
117  /***************************************************************************/
118 
119  return (item);
120 
121 }
#define NULL
Definition: decode_rs.h:63
char * dequeue(FP_QUEUE_t Q)
Definition: dequeue.c:5