Skip to content

Commit

Permalink
ringbuffer: use atomic ops on ringbuffer chunk magic
Browse files Browse the repository at this point in the history
The ringbuffer protocol uses the chunk magic number to indicate to the
other side what state a chunk is in.  It's therefore important to use
strongly ordered memory writes to make sure that neither the compiler
nor the CPU change the apparent order of the writes, since that would
result in corrupted messages.

Signed-off-by: Angus Salkeld <asalkeld@redhat.com>
  • Loading branch information
jsgf authored and asalkeld committed Apr 24, 2013
1 parent 6d7da39 commit 9b3be0b
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/ringbuffer.c
Expand Up @@ -86,11 +86,11 @@ do { \
#define QB_RB_CHUNK_MAGIC_DEAD 0xD0D0D0D0
#define QB_RB_CHUNK_MAGIC_ALLOC 0xA110CED0
#define QB_RB_CHUNK_SIZE_GET(rb, pointer) \
rb->shared_data[pointer]
qb_atomic_int_get(&rb->shared_data[pointer])
#define QB_RB_CHUNK_MAGIC_GET(rb, pointer) \
rb->shared_data[(pointer + 1) % rb->shared_hdr->word_size]
qb_atomic_int_get(&rb->shared_data[(pointer + 1) % rb->shared_hdr->word_size])
#define QB_RB_CHUNK_MAGIC_SET(rb, pointer, new_val) \
rb->shared_data[(pointer + 1) % rb->shared_hdr->word_size] = new_val;
qb_atomic_int_set(&rb->shared_data[(pointer + 1) % rb->shared_hdr->word_size], new_val)
#define QB_RB_CHUNK_DATA_GET(rb, pointer) \
&rb->shared_data[(pointer + QB_RB_CHUNK_HEADER_WORDS) % rb->shared_hdr->word_size]

Expand Down

0 comments on commit 9b3be0b

Please sign in to comment.