summaryrefslogtreecommitdiffstats
path: root/sys/sys/msgbuf.h
diff options
context:
space:
mode:
authoriedowse <iedowse@FreeBSD.org>2003-06-22 02:18:31 +0000
committeriedowse <iedowse@FreeBSD.org>2003-06-22 02:18:31 +0000
commit6bb0e5cb462431a2a86e4263d027ba8ad04eddc4 (patch)
tree9a1905dfa8c0a75f641cb540d2ad545b73865369 /sys/sys/msgbuf.h
parente6efd8ec4391d9b20c677c9b0a816b41e4036b17 (diff)
downloadFreeBSD-src-6bb0e5cb462431a2a86e4263d027ba8ad04eddc4.zip
FreeBSD-src-6bb0e5cb462431a2a86e4263d027ba8ad04eddc4.tar.gz
Replace the code for reading and writing the kernel message buffer
with a new implementation that has a mostly reentrant "addchar" routine, supports multiple message buffers in the kernel, and hides the implementation details from callers. The new code uses a kind of sequence number to represend the current read and write positions in the buffer. This approach (suggested mainly by bde) permits the read and write pointers to be maintained separately, which reduces the number of atomic operations that are required. The "mostly reentrant" above refers to the way that while it is now always safe to have any number of concurrent writers, readers could see the message buffer after a writer has advanced the pointers but before it has witten the new character. Discussed on: freebsd-arch
Diffstat (limited to 'sys/sys/msgbuf.h')
-rw-r--r--sys/sys/msgbuf.h26
1 files changed, 22 insertions, 4 deletions
diff --git a/sys/sys/msgbuf.h b/sys/sys/msgbuf.h
index 22bd161..b92ccc8 100644
--- a/sys/sys/msgbuf.h
+++ b/sys/sys/msgbuf.h
@@ -38,19 +38,37 @@
#define _SYS_MSGBUF_H_
struct msgbuf {
+ char *msg_ptr; /* pointer to buffer */
#define MSG_MAGIC 0x063062
u_int msg_magic;
- int msg_size; /* size of buffer area */
- int msg_bufx; /* write pointer */
- int msg_bufr; /* read pointer */
- char *msg_ptr; /* pointer to buffer */
+ u_int msg_size; /* size of buffer area */
+ u_int msg_wseq; /* write sequence number */
+ u_int msg_rseq; /* read sequence number */
u_int msg_cksum; /* checksum of contents */
+ u_int msg_seqmod; /* range for sequence numbers */
};
+/* Normalise a sequence number or a difference between sequence numbers */
+#define MSGBUF_SEQNORM(mbp, seq) (((seq) + (mbp)->msg_seqmod) % \
+ (mbp)->msg_seqmod)
+#define MSGBUF_SEQ_TO_POS(mbp, seq) ((seq) % (mbp)->msg_size)
+/* Subtract sequence numbers, but note that only positive values result. */
+#define MSGBUF_SEQSUB(mbp, seq1, seq2) (MSGBUF_SEQNORM((mbp), (seq1) - (seq2)))
+
#ifdef _KERNEL
extern int msgbuftrigger;
extern struct msgbuf *msgbufp;
void msgbufinit(void *ptr, int size);
+void msgbuf_addchar(struct msgbuf *mbp, int c);
+void msgbuf_clear(struct msgbuf *mbp);
+void msgbuf_copy(struct msgbuf *src, struct msgbuf *dst);
+int msgbuf_getbytes(struct msgbuf *mbp, char *buf, int buflen);
+int msgbuf_getchar(struct msgbuf *mbp);
+int msgbuf_getcount(struct msgbuf *mbp);
+void msgbuf_init(struct msgbuf *mbp, void *ptr, int size);
+void msgbuf_reinit(struct msgbuf *mbp, void *ptr, int size);
+int msgbuf_peekbytes(struct msgbuf *mbp, char *buf, int buflen,
+ u_int *seqp);
#if !defined(MSGBUF_SIZE)
#define MSGBUF_SIZE 32768
OpenPOWER on IntegriCloud