* Allocate a message queue */
| 1594 | * Allocate a message queue |
| 1595 | */ |
| 1596 | static struct mqueue * |
| 1597 | mqueue_alloc(const struct mq_attr *attr) |
| 1598 | { |
| 1599 | struct mqueue *mq; |
| 1600 | |
| 1601 | if (curmq >= maxmq) |
| 1602 | return (NULL); |
| 1603 | mq = uma_zalloc(mqueue_zone, M_WAITOK | M_ZERO); |
| 1604 | TAILQ_INIT(&mq->mq_msgq); |
| 1605 | if (attr != NULL) { |
| 1606 | mq->mq_maxmsg = attr->mq_maxmsg; |
| 1607 | mq->mq_msgsize = attr->mq_msgsize; |
| 1608 | } else { |
| 1609 | mq->mq_maxmsg = default_maxmsg; |
| 1610 | mq->mq_msgsize = default_msgsize; |
| 1611 | } |
| 1612 | mtx_init(&mq->mq_mutex, "mqueue lock", NULL, MTX_DEF); |
| 1613 | knlist_init_mtx(&mq->mq_rsel.si_note, &mq->mq_mutex); |
| 1614 | knlist_init_mtx(&mq->mq_wsel.si_note, &mq->mq_mutex); |
| 1615 | atomic_add_int(&curmq, 1); |
| 1616 | return (mq); |
| 1617 | } |
| 1618 | |
| 1619 | /* |
| 1620 | * Destroy a message queue |
no test coverage detected