summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorJosh Blum2013-05-02 23:37:51 -0700
committerJosh Blum2013-05-02 23:37:51 -0700
commit540a314a00b747c293f81d7931c22252a861fcdd (patch)
treef15a7b34c626c7fd9499729bb6399a443446b956 /include
parentfd4d5a2ccfd383f374d70f82aee66f3201395810 (diff)
downloadsandhi-540a314a00b747c293f81d7931c22252a861fcdd.tar.gz
sandhi-540a314a00b747c293f81d7931c22252a861fcdd.tar.bz2
sandhi-540a314a00b747c293f81d7931c22252a861fcdd.zip
gras: inline the sbuffer deref code
Diffstat (limited to 'include')
-rw-r--r--include/gras/detail/sbuffer.hpp24
1 files changed, 19 insertions, 5 deletions
diff --git a/include/gras/detail/sbuffer.hpp b/include/gras/detail/sbuffer.hpp
index 0d68ebc..720c8db 100644
--- a/include/gras/detail/sbuffer.hpp
+++ b/include/gras/detail/sbuffer.hpp
@@ -21,9 +21,6 @@ struct SBufferImpl
SBufferConfig config;
};
-
-extern GRAS_API void sbuffer_handle_deref(SBufferImpl *impl);
-
GRAS_FORCE_INLINE void intrusive_ptr_add_ref(SBufferImpl *impl)
{
++impl->count;
@@ -31,9 +28,26 @@ GRAS_FORCE_INLINE void intrusive_ptr_add_ref(SBufferImpl *impl)
GRAS_FORCE_INLINE void intrusive_ptr_release(SBufferImpl *impl)
{
- if (--impl->count == 0)
+ if GRAS_LIKELY(--impl->count) return;
+
+ //call the deleter if possible
+ boost::shared_ptr<SBufferDeleter> token_deleter = impl->config.token.lock();
+ if GRAS_LIKELY(token_deleter)
+ {
+ SBuffer buff;
+ buff.reset(impl);
+ (*token_deleter)(buff);
+ }
+ else if (impl->config.deleter)
+ {
+ SBuffer buff;
+ buff.reset(impl);
+ impl->config.deleter(buff);
+ impl->config.deleter = SBufferDeleter(); //reset deleter, so we dont double delete
+ }
+ else
{
- sbuffer_handle_deref(impl);
+ delete impl; //its really dead now
}
}