diff options
author | jsdelfino <jsdelfino@13f79535-47bb-0310-9956-ffa450edef68> | 2011-09-04 06:02:25 +0000 |
---|---|---|
committer | jsdelfino <jsdelfino@13f79535-47bb-0310-9956-ffa450edef68> | 2011-09-04 06:02:25 +0000 |
commit | 763f84a6dace6af3d8637d12dd9cd2f6f69b46ab (patch) | |
tree | 75ac4ce391c59a62f23cbd02ffae54e3134376cc /sca-cpp/trunk/kernel/gc.hpp | |
parent | ad5eccea058713a2816ca95f7f4392fe0ab03fb0 (diff) |
Build with Clang/LLVM when available.
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1164964 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'sca-cpp/trunk/kernel/gc.hpp')
-rw-r--r-- | sca-cpp/trunk/kernel/gc.hpp | 37 |
1 files changed, 19 insertions, 18 deletions
diff --git a/sca-cpp/trunk/kernel/gc.hpp b/sca-cpp/trunk/kernel/gc.hpp index 30cc637388..28ca80edc9 100644 --- a/sca-cpp/trunk/kernel/gc.hpp +++ b/sca-cpp/trunk/kernel/gc.hpp @@ -47,7 +47,7 @@ namespace tuscany */ bool assertOrFail(const bool expr) { if (!expr) - *(char*)NULL = '\0'; + abort(); return true; } @@ -183,7 +183,8 @@ public: class gc_pool_stack_t { public: gc_pool_stack_t() { - pthread_key_create(&key, NULL); + int rc = pthread_key_create(&key, NULL); + assertOrFail(rc == 0); } operator apr_pool_t*() const { @@ -204,21 +205,6 @@ apr_pool_t* gc_pool_stack = NULL; #endif /** - * Return the current memory pool. - */ -apr_pool_t* gc_current_pool() { - apr_pool_t* apr_pool = gc_pool_stack; - if (apr_pool != NULL) - return apr_pool; - - // Create a parent pool for the current thread - apr_pool_create(&apr_pool, NULL); - assertOrFail(apr_pool != NULL); - gc_pool_stack = apr_pool; - return apr_pool; -} - -/** * Push a pool onto the stack. */ apr_pool_t* gc_push_pool(apr_pool_t* pool) { @@ -237,6 +223,21 @@ apr_pool_t* gc_pop_pool(apr_pool_t* pool) { } /** + * Return the current memory pool. + */ +apr_pool_t* gc_current_pool() { + apr_pool_t* p = gc_pool_stack; + if (p != NULL) + return p; + + // Create a parent pool for the current thread + apr_pool_create(&p, NULL); + assertOrFail(p != NULL); + gc_push_pool(p); + return p; +} + +/** * A memory pool scope, used to setup a scope in which a particular pool * will be used for all allocations. */ @@ -302,7 +303,7 @@ template<typename T> apr_status_t gc_pool_acleanup(void* v) { } template<typename T> T* gc_anew(apr_pool_t* p, size_t n) { - size_t* gc_anew_ptr = static_cast<size_t*>(apr_palloc(p, sizeof(size_t) + sizeof(T[n]))); + size_t* gc_anew_ptr = static_cast<size_t*>(apr_palloc(p, sizeof(size_t) + sizeof(T) * n)); assertOrFail(gc_anew_ptr != NULL); *gc_anew_ptr = n; apr_pool_cleanup_register(p, gc_anew_ptr, gc_pool_acleanup<T>, apr_pool_cleanup_null) ; |