summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorJosh Blum2013-09-05 00:53:21 -0700
committerJosh Blum2013-09-05 00:53:21 -0700
commita7ae7925eb8c393cdec972ed59a1ca0cb48253bd (patch)
tree35fb700245824046e842483c34ddde24edcdcf0f /lib
parenteeb4d1e7e38e98f372ee21936c220ac6a5cb4efb (diff)
downloadsandhi-a7ae7925eb8c393cdec972ed59a1ca0cb48253bd.tar.gz
sandhi-a7ae7925eb8c393cdec972ed59a1ca0cb48253bd.tar.bz2
sandhi-a7ae7925eb8c393cdec972ed59a1ca0cb48253bd.zip
gras: move sbuffer inlines into lib
This avoids inline ASM to be LLVM JIT friendly. This commit includes a unit test for jit factory + sbuffer.
Diffstat (limited to 'lib')
-rw-r--r--lib/sbuffer.cpp55
1 files changed, 55 insertions, 0 deletions
diff --git a/lib/sbuffer.cpp b/lib/sbuffer.cpp
index bdf8a6f..04b3092 100644
--- a/lib/sbuffer.cpp
+++ b/lib/sbuffer.cpp
@@ -6,6 +6,43 @@
using namespace gras;
+void gras::intrusive_ptr_add_ref(SBufferImpl *impl)
+{
+ ++impl->count;
+}
+
+void gras::intrusive_ptr_release(SBufferImpl *impl)
+{
+ 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
+ {
+ delete impl; //its really dead now
+ }
+}
+
+SBufferImpl::SBufferImpl(const SBufferConfig &config):
+ count(0),
+ config(config)
+{
+ //NOP
+}
+
SBufferConfig::SBufferConfig(void)
{
memory = NULL;
@@ -14,6 +51,11 @@ SBufferConfig::SBufferConfig(void)
user_index = ~0;
}
+SBufferConfig::~SBufferConfig(void)
+{
+ //NOP
+}
+
static void numa_mem_deleter(SBuffer &buff)
{
Theron::Detail::Utils::FreeOnNode(buff.get_actual_memory(), buff.get_actual_length());
@@ -47,6 +89,14 @@ static void default_allocator(SBufferConfig &config)
}
}
+SBuffer::SBuffer(void):
+ offset(0),
+ length(0),
+ last(NULL)
+{
+ //NOP
+}
+
SBuffer::SBuffer(const SBufferConfig &config):
offset(0),
length(0)
@@ -58,3 +108,8 @@ SBuffer::SBuffer(const SBufferConfig &config):
}
this->length = this->get_actual_length();
}
+
+SBuffer::~SBuffer(void)
+{
+ //NOP
+}