Date: Sat, 17 Apr 2010 15:15:48 +0300 From: Andriy Gapon <avg@icyb.net.ua> To: freebsd-hackers@freebsd.org Subject: towards fixing intermingled dmesg Message-ID: <4BC9A674.2050705@icyb.net.ua>
next in thread | raw e-mail | index | archive | help
Here is a simple extension of msgbuf_addchar that is supposed to allow to put N characters consecutively into msgbuf. The idea is very simple: atomically forward msg_wseq by N and then copy characters into the reserved space. Could you please check if this is implemented correctly and if it would actually work the way I expect? There is still a harder issue of actually plugging this routine into subr_prf.c :-) --- a/sys/kern/subr_msgbuf.c +++ b/sys/kern/subr_msgbuf.c @@ -131,6 +131,26 @@ msgbuf_addchar(struct msgbuf *mbp, int c) mbp->msg_ptr[pos] = c; } +void +msgbuf_addchars(struct msgbuf *mbp, const char *s, const int n) +{ + u_int new_seq, pos, seq; + int c, i; + + do { + seq = mbp->msg_wseq; + new_seq = MSGBUF_SEQNORM(mbp, seq + n); + } while (atomic_cmpset_rel_int(&mbp->msg_wseq, seq, new_seq) == 0); + + for (i = 0; i < n; i++) { + pos = MSGBUF_SEQ_TO_POS(mbp, seq + i); + c = s[i]; + atomic_add_int(&mbp->msg_cksum, (u_int)(u_char)c - + (u_int)(u_char)mbp->msg_ptr[pos]); + mbp->msg_ptr[pos] = c; + } +} + /* * Read and mark as read a character from a message buffer. * Returns the character, or -1 if no characters are available. -- Andriy Gapon
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?4BC9A674.2050705>