Alien-libpanda

 view release on metacpan or  search on metacpan

src/panda/cast.h  view on Meta::CPAN

#include <stddef.h>
#include <type_traits>

namespace panda {

namespace detail { namespace cast {
    typedef std::map<intptr_t, ptrdiff_t> DynCastCacheMap;

    template <class DERIVED, class BASE>
    DynCastCacheMap& get_map () {
        thread_local DynCastCacheMap* map;
        if (!map) {
            thread_local DynCastCacheMap _map;
            map = &_map;
        }
        return *map;
    }

    constexpr const ptrdiff_t INCORRECT_PTRDIFF = PTRDIFF_MAX;
}}

template <class DERIVED_PTR, class BASE>
DERIVED_PTR dyn_cast (BASE* obj) {

src/panda/error.cc  view on Meta::CPAN

#include "error.h"

namespace panda { namespace error {

const NestedCategory& get_nested_categoty(const std::error_category& self, const NestedCategory* next) {
    static thread_local std::map<std::pair<const std::error_category*, const NestedCategory*>, NestedCategory> cache;
    auto iter = cache.find({&self, next});
    if (iter != cache.end()) {
        return iter->second;
    } else {
        return cache.emplace(std::piecewise_construct,
                             std::forward_as_tuple(&self, next),
                             std::forward_as_tuple(self, next)).first->second;
    }
}

src/panda/log.cc  view on Meta::CPAN

#include <math.h>
#include <memory>
#include <iomanip>
#include <sstream>

namespace panda { namespace log {

namespace details {
    std::unique_ptr<ILogger> ilogger;

    static thread_local std::ostringstream os;

    std::ostream& _get_os () { return os; }

    bool _do_log (std::ostream& _stream, const CodePoint& cp, Level level) {
        std::ostringstream& stream = static_cast<std::ostringstream&>(_stream);
        if (!ilogger) return false;
        stream.flush();
        std::string s(stream.str());
        stream.str({});
        ilogger->log(level, cp, s);

src/panda/memory.cc  view on Meta::CPAN

#include "string.h"
#include <map>
#include <mutex>
#include <string.h>

namespace panda {

static std::map<string, void*> global_ptrs;
static std::mutex              global_ptrs_mutex;

static thread_local std::map<string, void*> global_tls_ptrs;

static const int START_SIZE = 16;

DynamicMemoryPool* DynamicMemoryPool::_global_instance = new DynamicMemoryPool();

void* detail::__get_global_ptr (const std::type_info& ti, const char* name, void* val) {
    string key(ti.name());
    if (name) key += name;

    std::lock_guard<std::mutex> guard(global_ptrs_mutex);

src/panda/memory.h  view on Meta::CPAN

        static TYPE* ptr;                                           \
        if (!ptr) {                                                 \
            static TYPE val = defval;                               \
            ptr = panda::get_global_ptr<CLASS>(&val, #accessor);    \
        }                                                           \
        return ptr;                                                 \
    }

#define PANDA_TLS_MEMBER_PTR(CLASS, TYPE, accessor, defval)                         \
    static TYPE accessor () {                                                       \
        static thread_local TYPE _ptr;                                              \
        TYPE ptr = _ptr;                                                            \
        if (!ptr) ptr = _ptr = panda::get_global_tls_ptr<CLASS>(defval, #accessor); \
        return ptr;                                                                 \
    }

#define PANDA_TLS_MEMBER(CLASS, TYPE, accessor, defval)                     \
    static TYPE& accessor () {                                              \
        static thread_local TYPE* _ptr;                                     \
        TYPE* ptr = _ptr;                                                   \
        if (!ptr) {                                                         \
            static thread_local TYPE val = defval;                          \
            ptr = _ptr = panda::get_global_tls_ptr<CLASS>(&val, #accessor); \
        }                                                                   \
        return *ptr;                                                        \
    }

#define PANDA_TLS_MEMBER_AS_PTR(CLASS, TYPE, accessor, defval)              \
    static TYPE* accessor () {                                              \
        static thread_local TYPE* _ptr;                                     \
        TYPE* ptr = _ptr;                                                   \
        if (!ptr) {                                                         \
            static thread_local TYPE val = defval;                          \
            ptr = _ptr = panda::get_global_tls_ptr<CLASS>(&val, #accessor); \
        }                                                                   \
        return ptr;                                                         \
    }

struct MemoryPool {
    MemoryPool (size_t blocksize) : first_free(NULL) {
        this->blocksize = round_up(blocksize);
    }



( run in 0.564 second using v1.01-cache-2.11-cpan-3cd7ad12f66 )