Code comment on *mut Stream effect on thread safety

This commit is contained in:
Martin Algesten
2019-10-20 14:06:24 +02:00
parent 8871183df0
commit d9b8fef9a0
2 changed files with 6 additions and 1 deletions

View File

@@ -77,7 +77,10 @@ impl PoolKey {
pub(crate) struct PoolReturnRead<R: Read + Sized> { pub(crate) struct PoolReturnRead<R: Read + Sized> {
// unit that contains the agent where we want to return the reader. // unit that contains the agent where we want to return the reader.
unit: Option<Unit>, unit: Option<Unit>,
// pointer to underlying stream // pointer to underlying stream.
// this pointer forces the entire PoolReturnRead to be !Sync and !Send
// that's a good thing, because the pool return logic is certainly not
// thread safe.
stream: *mut Stream, stream: *mut Stream,
// wrapped reader around the same stream // wrapped reader around the same stream
reader: Option<R>, reader: Option<R>,

View File

@@ -557,6 +557,8 @@ fn read_next_line<R: Read>(reader: &mut R) -> IoResult<String> {
/// that api provides no way for us to get the underlying stream back. We need /// that api provides no way for us to get the underlying stream back. We need
/// to get the stream both for sending responses and for pooling. /// to get the stream both for sending responses and for pooling.
pub(crate) struct ReclaimingRead { pub(crate) struct ReclaimingRead {
// this pointer forces ReclaimingRead to be !Send and !Sync. That's a good
// thing, cause passing this reader around threads would not be safe.
stream: *mut Stream, stream: *mut Stream,
dealloc: bool, // whether we are to dealloc stream on drop dealloc: bool, // whether we are to dealloc stream on drop
} }