FreeBSD/sys/kern/subr_msgbuf.c
/*
 * Read and mark as read a character from a message buffer.
 * Returns the character, or -1 if no characters are available.
 */
Read and mark as read a character from a message buffer.
Returns the character, or -1 if no characters are available.
Read and mark as read a character from a message buffer . Returns the character or - 1 if no characters are available .
int
msgbuf_getchar(struct msgbuf *mbp)
{
	u_int len, wseq;
	int c;
	mtx_lock_spin(&mbp->msg_lock);
	wseq = mbp->msg_wseq;
	len = MSGBUF_SEQSUB(mbp, wseq, mbp->msg_rseq);
	if (len == 0) {
		mtx_unlock_spin(&mbp->msg_lock);
		return (-1);
	}
	if (len > mbp->msg_size)
		mbp->msg_rseq = MSGBUF_SEQNORM(mbp, wseq - mbp->msg_size);
	c = (u_char)mbp->msg_ptr[MSGBUF_SEQ_TO_POS(mbp, mbp->msg_rseq)];
	mbp->msg_rseq = MSGBUF_SEQNORM(mbp, mbp->msg_rseq + 1);
	mtx_unlock_spin(&mbp->msg_lock);
	return (c);
}
int msgbuf_getchar ( struct msgbuf * mbp ) { u_int len , wseq ; int c ; mtx_lock_spin ( & mbp -> msg_lock ) ; wseq = mbp -> msg_wseq ; len = MSGBUF_SEQSUB ( mbp , wseq , mbp -> msg_rseq ) ; if ( len == 0 ) { mtx_unlock_spin ( & mbp -> msg_lock ) ; return ( -1 ) ; } if ( len > mbp -> msg_size ) mbp -> msg_rseq = MSGBUF_SEQNORM ( mbp , wseq - mbp -> msg_size ) ; c = ( u_char ) mbp -> msg_ptr [ MSGBUF_SEQ_TO_POS ( mbp , mbp -> msg_rseq ) ] ; mbp -> msg_rseq = MSGBUF_SEQNORM ( mbp , mbp -> msg_rseq + 1 ) ; mtx_unlock_spin ( & mbp -> msg_lock ) ; return ( c ) ; }
Read and mark as read a character from a message buffer.
Read and mark as read a character from a message buffer .