IOBuf: add a method to signal the underlying buffer as externally shared
authorHuapeng Zhou <hzhou@fb.com>
Fri, 24 Jun 2016 17:45:37 +0000 (10:45 -0700)
committerFacebook Github Bot 3 <facebook-github-bot-3-bot@fb.com>
Fri, 24 Jun 2016 17:53:38 +0000 (10:53 -0700)
commit523ca0edb14fd73137660cc7f460cac59170b941
tree9a9ad4db76ba025fdd486b3844a547022ffa96ee
parent996d59be509226b2a5ecbb7fe3205ace7cd734a3
IOBuf: add a method to signal the underlying buffer as externally shared

Summary:
There are use cases where 1). the underlying buffer is externally managed (e.g. by a slab allocator) and 2). we need to do bookkeeping when the wrapped IOBuf gets destroyed (e.g. reference counting). This diff adds a another method to mark the underlying buffer as shared with the external memory management mechanism.

The `takeOwnership` doesn't meet the criteria since it assumes the ownership of the buffer, while in this case we need to signal it as externally managed so that hopefully callers won't try to modify the underlying buffer.

Reviewed By: simpkins

Differential Revision: D2662954

fbshipit-source-id: e908c3ebeeefe9a5d332c75070f377fb1dad5acb
folly/io/IOBuf.cpp
folly/io/IOBuf.h
folly/io/test/IOBufTest.cpp