MCPcopy Create free account
hub / github.com/F-Stack/f-stack / _mqueue_send

Function _mqueue_send

freebsd/kern/uipc_mqueue.c:1762–1812  ·  view source on GitHub ↗

* Common routine to send a message */

Source from the content-addressed store, hash-verified

1760 * Common routine to send a message
1761 */
1762static int
1763_mqueue_send(struct mqueue *mq, struct mqueue_msg *msg, int timo)
1764{
1765 struct mqueue_msg *msg2;
1766 int error = 0;
1767
1768 mtx_lock(&mq->mq_mutex);
1769 while (mq->mq_curmsgs >= mq->mq_maxmsg && error == 0) {
1770 if (timo < 0) {
1771 mtx_unlock(&mq->mq_mutex);
1772 return (EAGAIN);
1773 }
1774 mq->mq_senders++;
1775 error = msleep(&mq->mq_senders, &mq->mq_mutex,
1776 PCATCH, "mqsend", timo);
1777 mq->mq_senders--;
1778 if (error == EAGAIN)
1779 error = ETIMEDOUT;
1780 }
1781 if (mq->mq_curmsgs >= mq->mq_maxmsg) {
1782 mtx_unlock(&mq->mq_mutex);
1783 return (error);
1784 }
1785 error = 0;
1786 if (TAILQ_EMPTY(&mq->mq_msgq)) {
1787 TAILQ_INSERT_HEAD(&mq->mq_msgq, msg, msg_link);
1788 } else {
1789 if (msg->msg_prio <= TAILQ_LAST(&mq->mq_msgq, msgq)->msg_prio) {
1790 TAILQ_INSERT_TAIL(&mq->mq_msgq, msg, msg_link);
1791 } else {
1792 TAILQ_FOREACH(msg2, &mq->mq_msgq, msg_link) {
1793 if (msg2->msg_prio < msg->msg_prio)
1794 break;
1795 }
1796 TAILQ_INSERT_BEFORE(msg2, msg, msg_link);
1797 }
1798 }
1799 mq->mq_curmsgs++;
1800 mq->mq_totalbytes += msg->msg_size;
1801 if (mq->mq_receivers)
1802 wakeup_one(&mq->mq_receivers);
1803 else if (mq->mq_notifier != NULL)
1804 mqueue_send_notification(mq);
1805 if (mq->mq_flags & MQ_RSEL) {
1806 mq->mq_flags &= ~MQ_RSEL;
1807 selwakeup(&mq->mq_rsel);
1808 }
1809 KNOTE_LOCKED(&mq->mq_rsel.si_note, 0);
1810 mtx_unlock(&mq->mq_mutex);
1811 return (0);
1812}
1813
1814/*
1815 * Send realtime a signal to process which registered itself

Callers 1

mqueue_sendFunction · 0.85

Calls 5

mqueue_send_notificationFunction · 0.85
selwakeupFunction · 0.85
mtx_lockFunction · 0.70
mtx_unlockFunction · 0.70
wakeup_oneFunction · 0.70

Tested by

no test coverage detected