Lines Matching defs:mqhp

251 mq_init(mqhdr_t *mqhp, size_t msgsize, ssize_t maxmsg)
263 (void) mutex_init(&mqhp->mq_exclusive,
265 (void) sem_init(&mqhp->mq_rblocked, 1, 0);
266 (void) sem_init(&mqhp->mq_notempty, 1, 0);
267 (void) sem_init(&mqhp->mq_spawner, 1, 0);
268 (void) sem_init(&mqhp->mq_notfull, 1, (uint_t)maxmsg);
270 mqhp->mq_maxsz = msgsize;
271 mqhp->mq_maxmsg = maxmsg;
279 mqhp->mq_maxprio = _MQ_PRIO_MAX;
282 MQ_ASSERT(sizeof (mqhp->mq_mask) * 8 >= _MQ_PRIO_MAX);
290 mqhp->mq_headpp = sizeof (mqhdr_t);
291 mqhp->mq_tailpp = mqhp->mq_headpp +
292 mqhp->mq_maxprio * sizeof (uint64_t);
293 mqhp->mq_freep = mqhp->mq_tailpp +
294 mqhp->mq_maxprio * sizeof (uint64_t);
296 currentp = mqhp->mq_freep;
297 MQ_PTR(mqhp, currentp)->msg_next = 0;
299 temp = (mqhp->mq_maxsz + MQ_ALIGNSIZE - 1) & ~(MQ_ALIGNSIZE - 1);
300 for (i = 1; i < mqhp->mq_maxmsg; i++) {
302 MQ_PTR(mqhp, currentp)->msg_next = nextp;
303 MQ_PTR(mqhp, nextp)->msg_next = 0;
309 mq_getmsg(mqhdr_t *mqhp, char *msgp, uint_t *msg_prio)
316 MQ_ASSERT(MUTEX_HELD(&mqhp->mq_exclusive));
324 headpp = HEAD_PTR(mqhp, mqhp->mq_curmaxprio);
325 tailpp = TAIL_PTR(mqhp, mqhp->mq_curmaxprio);
328 *msg_prio = mqhp->mq_curmaxprio;
331 MQ_ASSERT_PTR(mqhp, currentp);
332 curbuf = MQ_PTR(mqhp, currentp);
340 uint_t prio = mqhp->mq_curmaxprio;
342 mqhp->mq_mask &= ~(1u << prio);
345 if (mqhp->mq_mask & (1u << prio))
347 mqhp->mq_curmaxprio = prio;
356 curbuf->msg_next = mqhp->mq_freep;
357 mqhp->mq_freep = currentp;
364 mq_putmsg(mqhdr_t *mqhp, const char *msgp, ssize_t len, uint_t prio)
371 MQ_ASSERT(MUTEX_HELD(&mqhp->mq_exclusive));
378 currentp = mqhp->mq_freep;
379 MQ_ASSERT_PTR(mqhp, currentp);
380 curbuf = MQ_PTR(mqhp, currentp);
385 mqhp->mq_freep = curbuf->msg_next;
390 headpp = HEAD_PTR(mqhp, prio);
391 tailpp = TAIL_PTR(mqhp, prio);
401 mqhp->mq_mask |= (1u << prio);
402 if (prio > mqhp->mq_curmaxprio)
403 mqhp->mq_curmaxprio = prio;
405 MQ_ASSERT_PTR(mqhp, *tailpp);
406 MQ_PTR(mqhp, *tailpp)->msg_next = currentp;
415 do_notify(mqhdr_t *mqhp)
417 (void) __signotify(SN_SEND, NULL, &mqhp->mq_sigid);
418 if (mqhp->mq_ntype == SIGEV_THREAD ||
419 mqhp->mq_ntype == SIGEV_PORT)
420 (void) sem_post(&mqhp->mq_spawner);
421 mqhp->mq_ntype = 0;
422 mqhp->mq_des = 0;
433 mqhdr_t *mqhp = mqdp->mqd_mq;
436 (void) sem_post(&mqhp->mq_notfull);
437 (void) sem_post(&mqhp->mq_notempty);
439 if (mqhp->mq_sigid.sn_pid != 0)
440 do_notify(mqhp);
441 (void) mutex_unlock(&mqhp->mq_exclusive);
462 mqhdr_t *mqhp;
564 mqhp = ptr;
604 mq_init(mqhp, msgsize, maxmsg);
605 mqhp->mq_totsize = total_size;
607 mqdp->mqd_mq = mqhp;
628 (void) munmap((caddr_t)mqhp, (size_t)total_size);
640 mqhdr_t *mqhp = mqdp->mqd_mq;
646 (void) mutex_unlock(&mqhp->mq_exclusive);
652 (void) munmap((caddr_t)mqhp, (size_t)mqhp->mq_totsize);
659 mqhdr_t *mqhp;
668 mqhp = mqdp->mqd_mq;
669 if ((error = mutex_lock(&mqhp->mq_exclusive)) != 0) {
672 (void) mutex_unlock(&mqhp->mq_exclusive);
676 if (mqhp->mq_des == (uintptr_t)mqdp &&
677 mqhp->mq_sigid.sn_pid == getpid()) {
679 (void) __signotify(SN_CANCEL, NULL, &mqhp->mq_sigid);
680 mqhp->mq_ntype = 0;
681 mqhp->mq_des = 0;
725 mqhdr_t *mqhp;
741 mqhp = mqdp->mqd_mq;
743 if (msg_prio >= mqhp->mq_maxprio) {
747 if (msg_len > mqhp->mq_maxsz) {
753 err = sem_trywait(&mqhp->mq_notfull);
759 err = sem_wait(&mqhp->mq_notfull);
761 err = sem_timedwait(&mqhp->mq_notfull, timeout);
763 err = sem_reltimedwait_np(&mqhp->mq_notfull, timeout);
777 if ((err = mutex_lock(&mqhp->mq_exclusive)) != 0) {
798 if (mqhp->mq_sigid.sn_pid != 0) {
801 (void) sem_getvalue(&mqhp->mq_notempty, &nmessages);
802 (void) sem_getvalue(&mqhp->mq_rblocked, &nblocked);
808 mq_putmsg(mqhp, msg_ptr, (ssize_t)msg_len, msg_prio);
809 (void) sem_post(&mqhp->mq_notempty);
813 do_notify(mqhp);
816 MQ_ASSERT_SEMVAL_LEQ(&mqhp->mq_notempty, ((int)mqhp->mq_maxmsg));
817 (void) mutex_unlock(&mqhp->mq_exclusive);
846 decrement_rblocked(mqhdr_t *mqhp)
851 while (sem_wait(&mqhp->mq_rblocked) == -1)
861 mqhdr_t *mqhp;
877 mqhp = mqdp->mqd_mq;
879 if (msg_len < mqhp->mq_maxsz) {
892 if (sem_trywait(&mqhp->mq_notempty) == -1) {
905 (void) sem_post(&mqhp->mq_rblocked);
907 pthread_cleanup_push(decrement_rblocked, mqhp);
909 err = sem_wait(&mqhp->mq_notempty);
911 err = sem_timedwait(&mqhp->mq_notempty, timeout);
913 err = sem_reltimedwait_np(&mqhp->mq_notempty, timeout);
925 if ((err = mutex_lock(&mqhp->mq_exclusive)) != 0) {
929 msg_size = mq_getmsg(mqhp, msg_ptr, msg_prio);
930 (void) sem_post(&mqhp->mq_notfull);
931 MQ_ASSERT_SEMVAL_LEQ(&mqhp->mq_notfull, ((int)mqhp->mq_maxmsg));
932 (void) mutex_unlock(&mqhp->mq_exclusive);
996 mqhdr_t *mqhp;
1013 mqhp = mqdp->mqd_mq;
1015 if ((error = mutex_lock(&mqhp->mq_exclusive)) != 0) {
1019 (void) mutex_unlock(&mqhp->mq_exclusive);
1024 if (mqhp->mq_des == (uintptr_t)mqdp &&
1025 mqhp->mq_sigid.sn_pid == getpid()) {
1027 (void) __signotify(SN_CANCEL, NULL, &mqhp->mq_sigid);
1039 mqhp->mq_ntype = 0;
1040 mqhp->mq_des = 0;
1091 tcdp->tcd_msg_avail = &mqhp->mq_spawner;
1107 if (__signotify(SN_PROC, &mq_siginfo, &mqhp->mq_sigid) < 0)
1109 mqhp->mq_ntype = ntype;
1110 mqhp->mq_des = (uintptr_t)mqdp;
1128 (void) mutex_unlock(&mqhp->mq_exclusive);
1140 mqhdr_t *mqhp;
1152 mqhp = mqdp->mqd_mq;
1154 omqstat->mq_maxmsg = (long)mqhp->mq_maxmsg;
1155 omqstat->mq_msgsize = (long)mqhp->mq_maxsz;
1156 (void) sem_getvalue(&mqhp->mq_notempty, &count);
1172 mqhdr_t *mqhp;
1180 mqhp = mqdp->mqd_mq;
1183 mqstat->mq_maxmsg = (long)mqhp->mq_maxmsg;
1184 mqstat->mq_msgsize = (long)mqhp->mq_maxsz;
1185 (void) sem_getvalue(&mqhp->mq_notempty, &count);