ringbuf: add thread-safe, thread-specific reset functions
This will allow both the reader and writer threads to reset the ringbuffer in a thread-safe fashion. git-svn-id: https://svn.musicpd.org/mpd/trunk@7390 09075e82-0dd4-0310-85a5-a0d7c8717e4f
This commit is contained in:
parent
9873e07c5a
commit
c593152967
@ -62,6 +62,18 @@ void ringbuf_reset(struct ringbuf * rb)
|
|||||||
rb->write_ptr = 0;
|
rb->write_ptr = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Reset the read and write pointers, thread-safe iff called only by writer */
|
||||||
|
void ringbuf_writer_reset(struct ringbuf * rb)
|
||||||
|
{
|
||||||
|
rb->write_ptr = rb->read_ptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Reset the read and write pointers, thread-safe iff called only by reader */
|
||||||
|
void ringbuf_reader_reset(struct ringbuf * rb)
|
||||||
|
{
|
||||||
|
rb->read_ptr = rb->write_ptr;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Return the number of bytes available for reading. This is the
|
* Return the number of bytes available for reading. This is the
|
||||||
* number of bytes in front of the read pointer and behind the write
|
* number of bytes in front of the read pointer and behind the write
|
||||||
|
@ -172,6 +172,24 @@ size_t ringbuf_read_space(const struct ringbuf * rb);
|
|||||||
*/
|
*/
|
||||||
void ringbuf_reset(struct ringbuf * rb);
|
void ringbuf_reset(struct ringbuf * rb);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reset the write pointer to the read pointer, making an empty buffer.
|
||||||
|
*
|
||||||
|
* This should only be called by the writer
|
||||||
|
*
|
||||||
|
* @param rb a pointer to the ringbuffer structure.
|
||||||
|
*/
|
||||||
|
void ringbuf_writer_reset(struct ringbuf * rb);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reset the read pointer to the write pointer, making an empty buffer.
|
||||||
|
*
|
||||||
|
* This should only be called by the reader
|
||||||
|
*
|
||||||
|
* @param rb a pointer to the ringbuffer structure.
|
||||||
|
*/
|
||||||
|
void ringbuf_reader_reset(struct ringbuf * rb);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Write data into the ringbuffer.
|
* Write data into the ringbuffer.
|
||||||
*
|
*
|
||||||
|
Loading…
Reference in New Issue
Block a user