]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/wave/src/cpplexer/re2clex/aq.cpp
1 /*=============================================================================
2 Boost.Wave: A Standard compliant C++ preprocessor library
5 Copyright (c) 2001 Daniel C. Nuffer.
6 Copyright (c) 2001-2012 Hartmut Kaiser.
7 Distributed under the Boost Software License, Version 1.0. (See accompanying
8 file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
9 =============================================================================*/
11 #define BOOST_WAVE_SOURCE 1
13 // disable stupid compiler warnings
14 #include <boost/config/warning_disable.hpp>
19 #include <boost/wave/wave_config.hpp> // configuration data
20 #include <boost/wave/cpplexer/re2clex/aq.hpp>
22 #include <boost/assert.hpp>
24 // this must occur after all of the includes and before any code appears
25 #ifdef BOOST_HAS_ABI_HEADERS
26 #include BOOST_ABI_PREFIX
29 ///////////////////////////////////////////////////////////////////////////////
35 int aq_grow(aq_queue q
)
37 using namespace std
; // some systems have memcpy/realloc in std
38 std::size_t new_size
= q
->max_size
<< 1;
39 aq_stdelement
* new_queue
= (aq_stdelement
*)realloc(q
->queue
,
40 new_size
* sizeof(aq_stdelement
));
42 BOOST_ASSERT(NULL
!= q
);
43 BOOST_ASSERT(q
->max_size
< 100000);
44 BOOST_ASSERT(q
->size
<= q
->max_size
);
46 #define ASSERT_SIZE BOOST_ASSERT( \
47 ((q->tail + q->max_size + 1) - q->head) % q->max_size == \
48 q->size % q->max_size)
51 BOOST_ASSERT(q
->head
<= q
->max_size
);
52 BOOST_ASSERT(q
->tail
<= q
->max_size
);
61 if (q
->tail
<= q
->head
) /* tail has wrapped around */
63 /* move the tail from the beginning to the end */
64 memcpy(q
->queue
+ q
->max_size
, q
->queue
,
65 (q
->tail
+ 1) * sizeof(aq_stdelement
));
66 q
->tail
+= q
->max_size
;
68 q
->max_size
= new_size
;
70 BOOST_ASSERT(q
->size
<= q
->max_size
);
72 BOOST_ASSERT(q
->head
<= q
->max_size
);
73 BOOST_ASSERT(q
->tail
<= q
->max_size
);
78 int aq_enqueue(aq_queue q
, aq_stdelement e
)
80 BOOST_ASSERT(NULL
!= q
);
81 BOOST_ASSERT(q
->size
<= q
->max_size
);
83 BOOST_ASSERT(q
->head
<= q
->max_size
);
84 BOOST_ASSERT(q
->tail
<= q
->max_size
);
92 if (q
->tail
== q
->max_size
)
95 q
->queue
[q
->tail
] = e
;
98 BOOST_ASSERT(q
->size
<= q
->max_size
);
100 BOOST_ASSERT(q
->head
<= q
->max_size
);
101 BOOST_ASSERT(q
->tail
<= q
->max_size
);
106 int aq_enqueue_front(aq_queue q
, aq_stdelement e
)
108 BOOST_ASSERT(NULL
!= q
);
110 BOOST_ASSERT(q
->size
<= q
->max_size
);
112 BOOST_ASSERT(q
->head
<= q
->max_size
);
113 BOOST_ASSERT(q
->tail
<= q
->max_size
);
121 q
->head
= q
->max_size
- 1;
125 q
->queue
[q
->head
] = e
;
128 BOOST_ASSERT(q
->size
<= q
->max_size
);
130 BOOST_ASSERT(q
->head
<= q
->max_size
);
131 BOOST_ASSERT(q
->tail
<= q
->max_size
);
136 int aq_serve(aq_queue q
, aq_stdelement
*e
)
139 BOOST_ASSERT(NULL
!= q
);
140 BOOST_ASSERT(q
->size
<= q
->max_size
);
142 BOOST_ASSERT(q
->head
<= q
->max_size
);
143 BOOST_ASSERT(q
->tail
<= q
->max_size
);
149 *e
= q
->queue
[q
->head
];
153 int aq_pop(aq_queue q
)
156 BOOST_ASSERT(NULL
!= q
);
157 BOOST_ASSERT(q
->size
<= q
->max_size
);
159 BOOST_ASSERT(q
->head
<= q
->max_size
);
160 BOOST_ASSERT(q
->tail
<= q
->max_size
);
167 if (q
->head
== q
->max_size
)
171 BOOST_ASSERT(q
->size
<= q
->max_size
);
173 BOOST_ASSERT(q
->head
<= q
->max_size
);
174 BOOST_ASSERT(q
->tail
<= q
->max_size
);
179 aq_queue
aq_create(void)
183 using namespace std
; // some systems have malloc in std
184 q
= (aq_queue
)malloc(sizeof(aq_queuetype
));
190 q
->max_size
= 8; /* initial size */
191 q
->queue
= (aq_stdelement
*)malloc(
192 sizeof(aq_stdelement
) * q
->max_size
);
200 q
->tail
= q
->max_size
- 1;
204 BOOST_ASSERT(q
->size
<= q
->max_size
);
206 BOOST_ASSERT(q
->head
<= q
->max_size
);
207 BOOST_ASSERT(q
->tail
<= q
->max_size
);
212 void aq_terminate(aq_queue q
)
214 using namespace std
; // some systems have free in std
216 BOOST_ASSERT(NULL
!= q
);
217 BOOST_ASSERT(q
->size
<= q
->max_size
);
219 BOOST_ASSERT(q
->head
<= q
->max_size
);
220 BOOST_ASSERT(q
->tail
<= q
->max_size
);
226 ///////////////////////////////////////////////////////////////////////////////
227 } // namespace re2clex
228 } // namespace cpplexer
232 // the suffix header occurs after all of the code
233 #ifdef BOOST_HAS_ABI_HEADERS
234 #include BOOST_ABI_SUFFIX