0
0
mirror of https://github.com/yse/easy_profiler.git synced 2024-12-26 08:01:51 +08:00

#108 fix [Core] clang build for arbitrary values

This commit is contained in:
Victor Zarubkin 2018-05-15 23:56:59 +03:00
parent 1301dd05dc
commit 8623fa81bb
2 changed files with 17 additions and 6 deletions

View File

@ -54,7 +54,7 @@ namespace profiler
class ValueId EASY_FINAL
{
friend ::ThreadStorage;
vin_t m_id;
const void* m_id;
public:
@ -66,14 +66,14 @@ namespace profiler
inline EASY_CONSTEXPR_FCN ValueId(ValueId&&) = default;
#endif
explicit inline EASY_CONSTEXPR_FCN ValueId() : m_id(0) {}
explicit inline EASY_CONSTEXPR_FCN ValueId(const void* _member) : m_id(reinterpret_cast<vin_t>(_member)) {}
explicit inline EASY_CONSTEXPR_FCN ValueId() : m_id(nullptr) {}
explicit inline EASY_CONSTEXPR_FCN ValueId(const void* _member) : m_id(_member) {}
template <class T>
explicit inline EASY_CONSTEXPR_FCN ValueId(const T& _member) : m_id(reinterpret_cast<vin_t>(&_member)) {}
explicit inline EASY_CONSTEXPR_FCN ValueId(const T& _member) : m_id(&_member) {}
template <class T, size_t N>
explicit inline EASY_CONSTEXPR_FCN ValueId(const T (&_member)[N]) : m_id(reinterpret_cast<vin_t>((void*)_member)) {}
explicit inline EASY_CONSTEXPR_FCN ValueId(const T (&_member)[N]) : m_id(_member) {}
ValueId& operator = (const ValueId&) = delete;
ValueId& operator = (ValueId&&) = delete;

View File

@ -44,6 +44,17 @@ The Apache License, Version 2.0 (the "License");
#include "current_thread.h"
#include "current_time.h"
static profiler::vin_t ptr2vin(const void* ptr)
{
static_assert(sizeof(uintptr_t) == sizeof(void*),
"Can not cast void* to uintptr_t. Different sizes.");
static_assert(sizeof(profiler::vin_t) >= sizeof(uintptr_t),
"Can not cast uintptr_t to vin_t. Possible truncation.");
return static_cast<profiler::vin_t>(reinterpret_cast<uintptr_t>(ptr));
}
ThreadStorage::ThreadStorage()
: nonscopedBlocks(16)
, frameStartTime(0)
@ -62,7 +73,7 @@ void ThreadStorage::storeValue(profiler::timestamp_t _timestamp, profiler::block
const uint16_t serializedDataSize = _size + static_cast<uint16_t>(sizeof(profiler::ArbitraryValue));
void* data = blocks.closedList.allocate(serializedDataSize);
::new (data) profiler::ArbitraryValue(_timestamp, _vin.m_id, _id, _size, _type, _isArray);
::new (data) profiler::ArbitraryValue(_timestamp, ptr2vin(_vin.m_id), _id, _size, _type, _isArray);
char* cdata = reinterpret_cast<char*>(data);
memcpy(cdata + sizeof(profiler::ArbitraryValue), _data, _size);