[vlc-devel] [PATCH 1/2] adaptive: chunk: C++ify mutex usage
Alexandre Janniaux
ajanni at videolabs.io
Thu Sep 17 08:44:46 CEST 2020
Hi,
On Thu, Sep 17, 2020 at 07:53:30AM +0200, Steve Lhomme wrote:
> On 2020-09-16 1:04, Alexandre Janniaux wrote:
> > void HTTPChunkBufferedSource::bufferize(size_t readsize)
> > {
> > - vlc_mutex_lock(&lock);
> > - if(!prepare())
> > {
>
> You might as well remove this block level since you change the whole block.
What do you mean by changing the whole block?
A mutex locker needs scope to define the boundaries of the
lock, and the block here needs both early return and value
return so was not easily movable to a function without a
loss in readability/complexity.
Thus, there are many lines modified but most of them are
just reindent at the new scope level whose existence is
actually needed.
>
> > - done = true;
> > - eof = true;
> > - vlc_cond_signal(&avail);
> > - vlc_mutex_unlock(&lock);
> > - return;
> > + mutex_locker locker {lock};
> > + if(!prepare())
> > + {
> > + done = true;
> > + eof = true;
> > + avail.signal();
> > + return;
> > + }
> > +
> > + if(readsize < HTTPChunkSource::CHUNK_SIZE)
> > + readsize = HTTPChunkSource::CHUNK_SIZE;
> > +
> > + if(contentLength && readsize > contentLength - buffered)
> > + readsize = contentLength - buffered;
> > }
> > - if(readsize < HTTPChunkSource::CHUNK_SIZE)
> > - readsize = HTTPChunkSource::CHUNK_SIZE;
> > -
> > - if(contentLength && readsize > contentLength - buffered)
> > - readsize = contentLength - buffered;
> > -
> > - vlc_mutex_unlock(&lock);
> > -
> > block_t *p_block = block_Alloc(readsize);
> > if(!p_block)
> > {
> _______________________________________________
> vlc-devel mailing list
> To unsubscribe or modify your subscription options:
> https://mailman.videolan.org/listinfo/vlc-devel
More information about the vlc-devel
mailing list