We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
void AppendWriteBuf(const uint8_t *buf, uint32_t len) { muduo::MutexLockGuard lock(*sp_mutexlock_write_buf); if (!(sp_write_tmembuf_.unique())) { uint8_t *p_buf = 0; uint32_t u32_len = 0; sp_write_tmembuf_->getBuffer(&p_buf, &u32_len); sp_write_tmembuf_ = boost::make_shared<TMemoryBuffer>(p_buf, u32_len, TMemoryBuffer::COPY); } sp_write_tmembuf_->write(buf, len); }
sp_write_tmembuf_.unique
此处判断sp_write_tmembuf_是否,多个shared_ptr指向,如果被shared_ptr指向,则重新 boost::make_shared ,,why?
The text was updated successfully, but these errors were encountered:
void AppendWriteBuf(const uint8_t *buf, uint32_t len) { muduo::MutexLockGuard lock(*sp_mutexlock_write_buf); if (!(sp_write_tmembuf_.unique())) { uint8_t *p_buf = 0; uint32_t u32_len = 0; sp_write_tmembuf_->getBuffer(&p_buf, &u32_len); sp_write_tmembuf_ = boost::make_shared<TMemoryBuffer>(p_buf, u32_len, TMemoryBuffer::COPY); } sp_write_tmembuf_->write(buf, len); } sp_write_tmembuf_.unique 此处判断sp_write_tmembuf_是否,多个shared_ptr指向,如果被shared_ptr指向,则重新 boost::make_shared ,,why?
他的目的其实很简单,就是利用copy on write的机制减少锁的临界区,扩大并发。 具体原理: buffer会被多个线程访问,意味着需要加锁,但加锁临界区变大会导致并发度不高。 在这个buffer被某个线程访问的时候,判断下这个buffer的的智能指针否被唯一的指向,不是唯一被指向的话证明有多个线程访问,就开启写时复制,反之不然。 希望能有些帮助。
Sorry, something went wrong.
void AppendWriteBuf(const uint8_t *buf, uint32_t len) { muduo::MutexLockGuard lock(*sp_mutexlock_write_buf); if (!(sp_write_tmembuf_.unique())) { uint8_t *p_buf = 0; uint32_t u32_len = 0; sp_write_tmembuf_->getBuffer(&p_buf, &u32_len); sp_write_tmembuf_ = boost::make_shared<TMemoryBuffer>(p_buf, u32_len, TMemoryBuffer::COPY); } sp_write_tmembuf_->write(buf, len); } sp_write_tmembuf_.unique 此处判断sp_write_tmembuf_是否,多个shared_ptr指向,如果被shared_ptr指向,则重新 boost::make_shared ,,why? 他的目的其实很简单,就是利用copy on write的机制减少锁的临界区,扩大并发。 具体原理: buffer会被多个线程访问,意味着需要加锁,但加锁临界区变大会导致并发度不高。 在这个buffer被某个线程访问的时候,判断下这个buffer的的智能指针否被唯一的指向,不是唯一被指向的话证明有多个线程访问,就开启写时复制,反之不然。 希望能有些帮助。
sp_write_tmembuf_.unique 此处判断sp_write_tmembuf_是否,多个shared_ptr指向,如果被shared_ptr指向,则重新 boost::make_shared ,,why?
谢谢,反馈;
No branches or pull requests
sp_write_tmembuf_.unique
此处判断sp_write_tmembuf_是否,多个shared_ptr指向,如果被shared_ptr指向,则重新 boost::make_shared ,,why?
The text was updated successfully, but these errors were encountered: