Rev 4582 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 4582 | Rev 4731 | ||
---|---|---|---|
Line 181... | Line 181... | ||
181 | } |
181 | } |
182 | gpm_destroy( & pm_globals.packet_map ); |
182 | gpm_destroy( & pm_globals.packet_map ); |
183 | // leave locked |
183 | // leave locked |
184 | } |
184 | } |
185 | 185 | ||
186 | packet_t pq_add( packet_t first, packet_t packet, int order, size_t metric ){ |
186 | packet_t pq_add( packet_t first, packet_t packet, size_t order, size_t metric ){ |
187 | packet_t item; |
187 | packet_t item; |
188 | 188 | ||
189 | if( ! packet_is_valid( packet )) return NULL; |
189 | if( ! packet_is_valid( packet )) return NULL; |
190 | pq_set( packet, order, metric ); |
190 | pq_set_order( packet, order, metric ); |
191 | if( packet_is_valid( first )){ |
191 | if( packet_is_valid( first )){ |
192 | item = first; |
192 | item = first; |
193 | do{ |
193 | do{ |
194 | if( item->order < order ){ |
194 | if( item->order < order ){ |
195 | if( item->next ){ |
195 | if( item->next ){ |
Line 203... | Line 203... | ||
203 | packet->previous = item->previous; |
203 | packet->previous = item->previous; |
204 | packet->next = item->packet_id; |
204 | packet->next = item->packet_id; |
205 | item->previous = packet->packet_id; |
205 | item->previous = packet->packet_id; |
206 | item = pm_find( packet->previous ); |
206 | item = pm_find( packet->previous ); |
207 | if( item ) item->next = packet->packet_id; |
207 | if( item ) item->next = packet->packet_id; |
208 | return item; |
208 | return item ? first : packet; |
209 | } |
209 | } |
210 | }while( packet_is_valid( item )); |
210 | }while( packet_is_valid( item )); |
211 | } |
211 | } |
212 | return packet; |
212 | return packet; |
213 | } |
213 | } |
214 | 214 | ||
- | 215 | packet_t pq_find( packet_t packet, size_t order ){ |
|
- | 216 | packet_t item; |
|
- | 217 | ||
- | 218 | if( ! packet_is_valid( packet )) return NULL; |
|
- | 219 | if( packet->order == order ) return packet; |
|
- | 220 | item = pm_find( packet->next ); |
|
- | 221 | while( item && ( item != packet )){ |
|
- | 222 | item = pm_find( item->next ); |
|
- | 223 | if( item->order == order ){ |
|
- | 224 | return item; |
|
- | 225 | } |
|
- | 226 | } |
|
- | 227 | return NULL; |
|
- | 228 | } |
|
- | 229 | ||
215 | int pq_insert_after( packet_t packet, packet_t new_packet ){ |
230 | int pq_insert_after( packet_t packet, packet_t new_packet ){ |
216 | packet_t item; |
231 | packet_t item; |
217 | 232 | ||
218 | if( !( packet_is_valid( packet ) && packet_is_valid( new_packet ))) return EINVAL; |
233 | if( !( packet_is_valid( packet ) && packet_is_valid( new_packet ))) return EINVAL; |
219 | new_packet->previous = packet->packet_id; |
234 | new_packet->previous = packet->packet_id; |
Line 240... | Line 255... | ||
240 | packet->previous = 0; |
255 | packet->previous = 0; |
241 | packet->next = 0; |
256 | packet->next = 0; |
242 | return next; |
257 | return next; |
243 | } |
258 | } |
244 | 259 | ||
245 | int pq_set( packet_t packet, int order, size_t metric ){ |
260 | int pq_set_order( packet_t packet, size_t order, size_t metric ){ |
246 | if( ! packet_is_valid( packet )) return EINVAL; |
261 | if( ! packet_is_valid( packet )) return EINVAL; |
247 | packet->order = order; |
262 | packet->order = order; |
248 | packet->metric = metric; |
263 | packet->metric = metric; |
249 | return EOK; |
264 | return EOK; |
250 | } |
265 | } |
251 | 266 | ||
- | 267 | int pq_get_order( packet_t packet, size_t * order, size_t * metric ){ |
|
- | 268 | if( ! packet_is_valid( packet )) return EINVAL; |
|
- | 269 | if( order ) * order = packet->order; |
|
- | 270 | if( metric ) * metric = packet->metric; |
|
- | 271 | return EOK; |
|
- | 272 | } |
|
- | 273 | ||
252 | void pq_destroy( packet_t first, void ( * packet_release )( packet_t packet )){ |
274 | void pq_destroy( packet_t first, void ( * packet_release )( packet_t packet )){ |
253 | packet_t actual; |
275 | packet_t actual; |
254 | packet_t next; |
276 | packet_t next; |
255 | 277 | ||
256 | actual = first; |
278 | actual = first; |