|
31 | 31 | * Pre-processor Definitions
|
32 | 32 | ****************************************************************************/
|
33 | 33 |
|
| 34 | +#ifdef CONFIG_LIBC_INLINE_QUEUE |
| 35 | +# ifndef STATIC_INLINE |
| 36 | +# define STATIC_INLINE static inline_function |
| 37 | +# endif |
| 38 | +#else |
| 39 | +# define STATIC_INLINE |
| 40 | +#endif |
| 41 | + |
34 | 42 | #define sq_init(q) \
|
35 | 43 | do \
|
36 | 44 | { \
|
@@ -343,24 +351,241 @@ extern "C"
|
343 | 351 |
|
344 | 352 | /* Add nodes to queues */
|
345 | 353 |
|
| 354 | +#ifndef CONFIG_LIBC_INLINE_QUEUE |
346 | 355 | void sq_addafter(FAR sq_entry_t *prev, FAR sq_entry_t *node,
|
347 | 356 | FAR sq_queue_t *queue);
|
| 357 | +#else |
| 358 | +STATIC_INLINE void sq_addafter(FAR sq_entry_t *prev, FAR sq_entry_t *node, |
| 359 | + FAR sq_queue_t *queue) |
| 360 | +{ |
| 361 | + if (!queue->head || prev == queue->tail) |
| 362 | + { |
| 363 | + sq_addlast(node, queue); |
| 364 | + } |
| 365 | + else |
| 366 | + { |
| 367 | + node->flink = prev->flink; |
| 368 | + prev->flink = node; |
| 369 | + } |
| 370 | +} |
| 371 | +#endif |
| 372 | + |
| 373 | +#ifndef CONFIG_LIBC_INLINE_QUEUE |
348 | 374 | void dq_addafter(FAR dq_entry_t *prev, FAR dq_entry_t *node,
|
349 | 375 | FAR dq_queue_t *queue);
|
| 376 | +#else |
| 377 | +STATIC_INLINE void dq_addafter(FAR dq_entry_t *prev, FAR dq_entry_t *node, |
| 378 | + FAR dq_queue_t *queue) |
| 379 | +{ |
| 380 | + if (!queue->head || prev == queue->tail) |
| 381 | + { |
| 382 | + dq_addlast(node, queue); |
| 383 | + } |
| 384 | + else |
| 385 | + { |
| 386 | + FAR dq_entry_t *next = prev->flink; |
| 387 | + node->blink = prev; |
| 388 | + node->flink = next; |
| 389 | + next->blink = node; |
| 390 | + prev->flink = node; |
| 391 | + } |
| 392 | +} |
| 393 | +#endif |
350 | 394 |
|
351 | 395 | /* Remove nodes from queues */
|
352 | 396 |
|
| 397 | +#ifndef CONFIG_LIBC_INLINE_QUEUE |
353 | 398 | FAR sq_entry_t *sq_remafter(FAR sq_entry_t *node, FAR sq_queue_t *queue);
|
| 399 | +#else |
| 400 | +STATIC_INLINE FAR sq_entry_t *sq_remafter(FAR sq_entry_t *node, |
| 401 | + FAR sq_queue_t *queue) |
| 402 | +{ |
| 403 | + FAR sq_entry_t *ret = node->flink; |
| 404 | + |
| 405 | + if (queue->head && ret) |
| 406 | + { |
| 407 | + if (queue->tail == ret) |
| 408 | + { |
| 409 | + queue->tail = node; |
| 410 | + node->flink = NULL; |
| 411 | + } |
| 412 | + else |
| 413 | + { |
| 414 | + node->flink = ret->flink; |
| 415 | + } |
| 416 | + |
| 417 | + ret->flink = NULL; |
| 418 | + } |
| 419 | + |
| 420 | + return ret; |
| 421 | +} |
| 422 | +#endif |
| 423 | + |
| 424 | +#ifndef CONFIG_LIBC_INLINE_QUEUE |
354 | 425 | FAR dq_entry_t *dq_remafter(FAR dq_entry_t *node, FAR dq_queue_t *queue);
|
| 426 | +#else |
| 427 | +STATIC_INLINE FAR dq_entry_t *dq_remafter(FAR dq_entry_t *node, |
| 428 | + FAR dq_queue_t *queue) |
| 429 | +{ |
| 430 | + FAR dq_entry_t *ret = node->flink; |
| 431 | + |
| 432 | + if (queue->head != NULL && ret != NULL) |
| 433 | + { |
| 434 | + dq_rem(ret, queue); |
| 435 | + } |
| 436 | + |
| 437 | + return ret; |
| 438 | +} |
| 439 | +#endif |
| 440 | + |
| 441 | +#ifndef CONFIG_LIBC_INLINE_QUEUE |
355 | 442 | FAR sq_entry_t *sq_remlast(FAR sq_queue_t *queue);
|
| 443 | +#else |
| 444 | +STATIC_INLINE FAR sq_entry_t *sq_remlast(FAR sq_queue_t *queue) |
| 445 | +{ |
| 446 | + FAR sq_entry_t *ret = queue->tail; |
| 447 | + |
| 448 | + if (ret) |
| 449 | + { |
| 450 | + if (queue->head == queue->tail) |
| 451 | + { |
| 452 | + queue->head = NULL; |
| 453 | + queue->tail = NULL; |
| 454 | + } |
| 455 | + else |
| 456 | + { |
| 457 | + FAR sq_entry_t *prev; |
| 458 | + for (prev = queue->head; |
| 459 | + prev && prev->flink != ret; |
| 460 | + prev = prev->flink); |
| 461 | + |
| 462 | + if (prev) |
| 463 | + { |
| 464 | + prev->flink = NULL; |
| 465 | + queue->tail = prev; |
| 466 | + } |
| 467 | + } |
| 468 | + |
| 469 | + ret->flink = NULL; |
| 470 | + } |
| 471 | + |
| 472 | + return ret; |
| 473 | +} |
| 474 | +#endif |
| 475 | + |
| 476 | +#ifndef CONFIG_LIBC_INLINE_QUEUE |
356 | 477 | FAR dq_entry_t *dq_remlast(FAR dq_queue_t *queue);
|
| 478 | +#else |
| 479 | +STATIC_INLINE FAR dq_entry_t *dq_remlast(FAR dq_queue_t *queue) |
| 480 | +{ |
| 481 | + FAR dq_entry_t *ret = queue->tail; |
| 482 | + |
| 483 | + if (ret) |
| 484 | + { |
| 485 | + FAR dq_entry_t *prev = ret->blink; |
| 486 | + if (!prev) |
| 487 | + { |
| 488 | + queue->head = NULL; |
| 489 | + queue->tail = NULL; |
| 490 | + } |
| 491 | + else |
| 492 | + { |
| 493 | + queue->tail = prev; |
| 494 | + prev->flink = NULL; |
| 495 | + } |
| 496 | + |
| 497 | + ret->flink = NULL; |
| 498 | + ret->blink = NULL; |
| 499 | + } |
| 500 | + |
| 501 | + return ret; |
| 502 | +} |
| 503 | +#endif |
| 504 | + |
| 505 | +#ifndef CONFIG_LIBC_INLINE_QUEUE |
357 | 506 | FAR sq_entry_t *sq_remfirst(FAR sq_queue_t *queue);
|
| 507 | +#else |
| 508 | +STATIC_INLINE FAR sq_entry_t *sq_remfirst(FAR sq_queue_t *queue) |
| 509 | +{ |
| 510 | + FAR sq_entry_t *ret = queue->head; |
| 511 | + |
| 512 | + if (ret) |
| 513 | + { |
| 514 | + queue->head = ret->flink; |
| 515 | + if (!queue->head) |
| 516 | + { |
| 517 | + queue->tail = NULL; |
| 518 | + } |
| 519 | + |
| 520 | + ret->flink = NULL; |
| 521 | + } |
| 522 | + |
| 523 | + return ret; |
| 524 | +} |
| 525 | +#endif |
| 526 | + |
| 527 | +#ifndef CONFIG_LIBC_INLINE_QUEUE |
358 | 528 | FAR dq_entry_t *dq_remfirst(FAR dq_queue_t *queue);
|
| 529 | +#else |
| 530 | +STATIC_INLINE FAR dq_entry_t *dq_remfirst(FAR dq_queue_t *queue) |
| 531 | +{ |
| 532 | + FAR dq_entry_t *ret = queue->head; |
| 533 | + |
| 534 | + if (ret) |
| 535 | + { |
| 536 | + FAR dq_entry_t *next = ret->flink; |
| 537 | + if (!next) |
| 538 | + { |
| 539 | + queue->head = NULL; |
| 540 | + queue->tail = NULL; |
| 541 | + } |
| 542 | + else |
| 543 | + { |
| 544 | + queue->head = next; |
| 545 | + next->blink = NULL; |
| 546 | + } |
| 547 | + |
| 548 | + ret->flink = NULL; |
| 549 | + ret->blink = NULL; |
| 550 | + } |
| 551 | + |
| 552 | + return ret; |
| 553 | +} |
| 554 | +#endif |
359 | 555 |
|
360 | 556 | /* Count nodes in queues */
|
361 | 557 |
|
| 558 | +#ifndef CONFIG_LIBC_INLINE_QUEUE |
362 | 559 | size_t sq_count(FAR sq_queue_t *queue);
|
| 560 | +#else |
| 561 | +STATIC_INLINE size_t sq_count(FAR sq_queue_t *queue) |
| 562 | +{ |
| 563 | + FAR sq_entry_t *node; |
| 564 | + size_t count; |
| 565 | + |
| 566 | + for (node = queue->head, count = 0; |
| 567 | + node != NULL; |
| 568 | + node = node->flink, count++); |
| 569 | + |
| 570 | + return count; |
| 571 | +} |
| 572 | +#endif |
| 573 | + |
| 574 | +#ifndef CONFIG_LIBC_INLINE_QUEUE |
363 | 575 | size_t dq_count(FAR dq_queue_t *queue);
|
| 576 | +#else |
| 577 | +STATIC_INLINE size_t dq_count(FAR dq_queue_t *queue) |
| 578 | +{ |
| 579 | + FAR dq_entry_t *node; |
| 580 | + size_t count; |
| 581 | + |
| 582 | + for (node = queue->head, count = 0; |
| 583 | + node != NULL; |
| 584 | + node = node->flink, count++); |
| 585 | + |
| 586 | + return count; |
| 587 | +} |
| 588 | +#endif |
364 | 589 |
|
365 | 590 | #undef EXTERN
|
366 | 591 | #ifdef __cplusplus
|
|
0 commit comments