Lines Matching refs:mqhp
180 mq_init(mqhdr_t *mqhp, size_t msgsize, ssize_t maxmsg)
192 (void) mutex_init(&mqhp->mq_exclusive,
194 (void) sem_init(&mqhp->mq_rblocked, 1, 0);
195 (void) sem_init(&mqhp->mq_notempty, 1, 0);
196 (void) sem_init(&mqhp->mq_spawner, 1, 0);
197 (void) sem_init(&mqhp->mq_notfull, 1, (uint_t)maxmsg);
199 mqhp->mq_maxsz = msgsize;
200 mqhp->mq_maxmsg = maxmsg;
208 mqhp->mq_maxprio = _MQ_PRIO_MAX;
211 MQ_ASSERT(sizeof (mqhp->mq_mask) * 8 >= _MQ_PRIO_MAX);
219 mqhp->mq_headpp = sizeof (mqhdr_t);
220 mqhp->mq_tailpp = mqhp->mq_headpp +
221 mqhp->mq_maxprio * sizeof (uint64_t);
222 mqhp->mq_freep = mqhp->mq_tailpp +
223 mqhp->mq_maxprio * sizeof (uint64_t);
225 currentp = mqhp->mq_freep;
226 MQ_PTR(mqhp, currentp)->msg_next = 0;
228 temp = (mqhp->mq_maxsz + MQ_ALIGNSIZE - 1) & ~(MQ_ALIGNSIZE - 1);
229 for (i = 1; i < mqhp->mq_maxmsg; i++) {
231 MQ_PTR(mqhp, currentp)->msg_next = nextp;
232 MQ_PTR(mqhp, nextp)->msg_next = 0;
238 mq_getmsg(mqhdr_t *mqhp, char *msgp, uint_t *msg_prio)
245 MQ_ASSERT(MUTEX_HELD(&mqhp->mq_exclusive));
253 headpp = HEAD_PTR(mqhp, mqhp->mq_curmaxprio);
254 tailpp = TAIL_PTR(mqhp, mqhp->mq_curmaxprio);
257 *msg_prio = mqhp->mq_curmaxprio;
260 MQ_ASSERT_PTR(mqhp, currentp);
261 curbuf = MQ_PTR(mqhp, currentp);
269 uint_t prio = mqhp->mq_curmaxprio;
271 mqhp->mq_mask &= ~(1u << prio);
274 if (mqhp->mq_mask & (1u << prio))
276 mqhp->mq_curmaxprio = prio;
285 curbuf->msg_next = mqhp->mq_freep;
286 mqhp->mq_freep = currentp;
293 mq_putmsg(mqhdr_t *mqhp, const char *msgp, ssize_t len, uint_t prio)
300 MQ_ASSERT(MUTEX_HELD(&mqhp->mq_exclusive));
307 currentp = mqhp->mq_freep;
308 MQ_ASSERT_PTR(mqhp, currentp);
309 curbuf = MQ_PTR(mqhp, currentp);
314 mqhp->mq_freep = curbuf->msg_next;
319 headpp = HEAD_PTR(mqhp, prio);
320 tailpp = TAIL_PTR(mqhp, prio);
330 mqhp->mq_mask |= (1u << prio);
331 if (prio > mqhp->mq_curmaxprio)
332 mqhp->mq_curmaxprio = prio;
334 MQ_ASSERT_PTR(mqhp, *tailpp);
335 MQ_PTR(mqhp, *tailpp)->msg_next = currentp;
344 do_notify(mqhdr_t *mqhp)
346 (void) __signotify(SN_SEND, NULL, &mqhp->mq_sigid);
347 if (mqhp->mq_ntype == SIGEV_THREAD ||
348 mqhp->mq_ntype == SIGEV_PORT)
349 (void) sem_post(&mqhp->mq_spawner);
350 mqhp->mq_ntype = 0;
351 mqhp->mq_des = 0;
362 mqhdr_t *mqhp = mqdp->mqd_mq;
365 (void) sem_post(&mqhp->mq_notfull);
366 (void) sem_post(&mqhp->mq_notempty);
368 if (mqhp->mq_sigid.sn_pid != 0)
369 do_notify(mqhp);
370 (void) mutex_unlock(&mqhp->mq_exclusive);
391 mqhdr_t *mqhp;
493 mqhp = ptr;
531 mq_init(mqhp, msgsize, maxmsg);
532 mqhp->mq_totsize = total_size;
534 mqdp->mqd_mq = mqhp;
562 (void) munmap((caddr_t)mqhp, (size_t)total_size);
574 mqhdr_t *mqhp = mqdp->mqd_mq;
580 (void) mutex_unlock(&mqhp->mq_exclusive);
593 (void) munmap((caddr_t)mqhp, (size_t)mqhp->mq_totsize);
600 mqhdr_t *mqhp;
609 mqhp = mqdp->mqd_mq;
610 if ((error = mutex_lock(&mqhp->mq_exclusive)) != 0) {
613 (void) mutex_unlock(&mqhp->mq_exclusive);
617 if (mqhp->mq_des == (uintptr_t)mqdp &&
618 mqhp->mq_sigid.sn_pid == getpid()) {
620 (void) __signotify(SN_CANCEL, NULL, &mqhp->mq_sigid);
621 mqhp->mq_ntype = 0;
622 mqhp->mq_des = 0;
666 mqhdr_t *mqhp;
682 mqhp = mqdp->mqd_mq;
684 if (msg_prio >= mqhp->mq_maxprio) {
688 if (msg_len > mqhp->mq_maxsz) {
694 err = sem_trywait(&mqhp->mq_notfull);
700 err = sem_wait(&mqhp->mq_notfull);
702 err = sem_timedwait(&mqhp->mq_notfull, timeout);
704 err = sem_reltimedwait_np(&mqhp->mq_notfull, timeout);
718 if ((err = mutex_lock(&mqhp->mq_exclusive)) != 0) {
739 if (mqhp->mq_sigid.sn_pid != 0) {
742 (void) sem_getvalue(&mqhp->mq_notempty, &nmessages);
743 (void) sem_getvalue(&mqhp->mq_rblocked, &nblocked);
749 mq_putmsg(mqhp, msg_ptr, (ssize_t)msg_len, msg_prio);
750 (void) sem_post(&mqhp->mq_notempty);
754 do_notify(mqhp);
757 MQ_ASSERT_SEMVAL_LEQ(&mqhp->mq_notempty, ((int)mqhp->mq_maxmsg));
758 (void) mutex_unlock(&mqhp->mq_exclusive);
787 decrement_rblocked(mqhdr_t *mqhp)
792 while (sem_wait(&mqhp->mq_rblocked) == -1)
802 mqhdr_t *mqhp;
818 mqhp = mqdp->mqd_mq;
820 if (msg_len < mqhp->mq_maxsz) {
833 if (sem_trywait(&mqhp->mq_notempty) == -1) {
846 (void) sem_post(&mqhp->mq_rblocked);
848 pthread_cleanup_push(decrement_rblocked, mqhp);
850 err = sem_wait(&mqhp->mq_notempty);
852 err = sem_timedwait(&mqhp->mq_notempty, timeout);
854 err = sem_reltimedwait_np(&mqhp->mq_notempty, timeout);
866 if ((err = mutex_lock(&mqhp->mq_exclusive)) != 0) {
870 msg_size = mq_getmsg(mqhp, msg_ptr, msg_prio);
871 (void) sem_post(&mqhp->mq_notfull);
872 MQ_ASSERT_SEMVAL_LEQ(&mqhp->mq_notfull, ((int)mqhp->mq_maxmsg));
873 (void) mutex_unlock(&mqhp->mq_exclusive);
937 mqhdr_t *mqhp;
954 mqhp = mqdp->mqd_mq;
956 if ((error = mutex_lock(&mqhp->mq_exclusive)) != 0) {
960 (void) mutex_unlock(&mqhp->mq_exclusive);
965 if (mqhp->mq_des == (uintptr_t)mqdp &&
966 mqhp->mq_sigid.sn_pid == getpid()) {
968 (void) __signotify(SN_CANCEL, NULL, &mqhp->mq_sigid);
980 mqhp->mq_ntype = 0;
981 mqhp->mq_des = 0;
1032 tcdp->tcd_msg_avail = &mqhp->mq_spawner;
1048 if (__signotify(SN_PROC, &mq_siginfo, &mqhp->mq_sigid) < 0)
1050 mqhp->mq_ntype = ntype;
1051 mqhp->mq_des = (uintptr_t)mqdp;
1069 (void) mutex_unlock(&mqhp->mq_exclusive);
1081 mqhdr_t *mqhp;
1093 mqhp = mqdp->mqd_mq;
1095 omqstat->mq_maxmsg = (long)mqhp->mq_maxmsg;
1096 omqstat->mq_msgsize = (long)mqhp->mq_maxsz;
1097 (void) sem_getvalue(&mqhp->mq_notempty, &count);
1113 mqhdr_t *mqhp;
1121 mqhp = mqdp->mqd_mq;
1124 mqstat->mq_maxmsg = (long)mqhp->mq_maxmsg;
1125 mqstat->mq_msgsize = (long)mqhp->mq_maxsz;
1126 (void) sem_getvalue(&mqhp->mq_notempty, &count);