| 824 | } |
| 825 | |
| 826 | void |
| 827 | alq_post_flags(struct alq *alq, struct ale *ale, int flags) |
| 828 | { |
| 829 | int activate; |
| 830 | void *waitchan; |
| 831 | |
| 832 | activate = 0; |
| 833 | |
| 834 | if (ale->ae_bytesused > 0) { |
| 835 | if (!(alq->aq_flags & AQ_ACTIVE) && |
| 836 | !(flags & ALQ_NOACTIVATE)) { |
| 837 | alq->aq_flags |= AQ_ACTIVE; |
| 838 | activate = 1; |
| 839 | } |
| 840 | |
| 841 | alq->aq_writehead += ale->ae_bytesused; |
| 842 | alq->aq_freebytes -= ale->ae_bytesused; |
| 843 | |
| 844 | /* Wrap aq_writehead if we filled to the end of the buffer. */ |
| 845 | if (alq->aq_writehead == alq->aq_buflen) |
| 846 | alq->aq_writehead = 0; |
| 847 | |
| 848 | KASSERT((alq->aq_writehead >= 0 && |
| 849 | alq->aq_writehead < alq->aq_buflen), |
| 850 | ("%s: aq_writehead < 0 || aq_writehead >= aq_buflen", |
| 851 | __func__)); |
| 852 | |
| 853 | KASSERT((HAS_PENDING_DATA(alq)), ("%s: queue empty!", __func__)); |
| 854 | } |
| 855 | |
| 856 | /* |
| 857 | * If there are waiters, we need to signal the waiting threads after we |
| 858 | * complete our work. The alq ptr is used as a wait channel for threads |
| 859 | * requiring resources to be freed up. In the AQ_ORDERED case, threads |
| 860 | * are not allowed to concurrently compete for resources in the |
| 861 | * alq_getn() while loop, so we use a different wait channel in this case. |
| 862 | */ |
| 863 | if (alq->aq_waiters > 0) { |
| 864 | if (alq->aq_flags & AQ_ORDERED) |
| 865 | waitchan = &alq->aq_waiters; |
| 866 | else |
| 867 | waitchan = alq; |
| 868 | } else |
| 869 | waitchan = NULL; |
| 870 | |
| 871 | ALQ_UNLOCK(alq); |
| 872 | |
| 873 | if (activate) { |
| 874 | ALD_LOCK(); |
| 875 | ald_activate(alq); |
| 876 | ALD_UNLOCK(); |
| 877 | } |
| 878 | |
| 879 | /* NB: We rely on wakeup_one waking threads in a FIFO manner. */ |
| 880 | if (waitchan != NULL) |
| 881 | wakeup_one(waitchan); |
| 882 | } |
| 883 |
no test coverage detected