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

Function msgbuf_getchar

freebsd/kern/subr_msgbuf.c:290–312  ·  view source on GitHub ↗

* Read and mark as read a character from a message buffer. * Returns the character, or -1 if no characters are available. */

Source from the content-addressed store, hash-verified

288 * Returns the character, or -1 if no characters are available.
289 */
290int
291msgbuf_getchar(struct msgbuf *mbp)
292{
293 u_int len, wseq;
294 int c;
295
296 mtx_lock_spin(&mbp->msg_lock);
297
298 wseq = mbp->msg_wseq;
299 len = MSGBUF_SEQSUB(mbp, wseq, mbp->msg_rseq);
300 if (len == 0) {
301 mtx_unlock_spin(&mbp->msg_lock);
302 return (-1);
303 }
304 if (len > mbp->msg_size)
305 mbp->msg_rseq = MSGBUF_SEQNORM(mbp, wseq - mbp->msg_size);
306 c = (u_char)mbp->msg_ptr[MSGBUF_SEQ_TO_POS(mbp, mbp->msg_rseq)];
307 mbp->msg_rseq = MSGBUF_SEQNORM(mbp, mbp->msg_rseq + 1);
308
309 mtx_unlock_spin(&mbp->msg_lock);
310
311 return (c);
312}
313
314/*
315 * Read and mark as read a number of characters from a message buffer.

Callers 3

msgbuf_copyFunction · 0.85
constty_clearFunction · 0.85
constty_timeoutFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected