Files
cpp-project-template/third_party/tracy/server/TracyShortPtr.hpp
tqcq 68b2e7f763
Some checks failed
sm-rpc / build (Debug, arm-linux-gnueabihf) (push) Successful in 1m34s
sm-rpc / build (Debug, aarch64-linux-gnu) (push) Successful in 2m46s
sm-rpc / build (Debug, host.gcc) (push) Failing after 1m28s
sm-rpc / build (Release, aarch64-linux-gnu) (push) Successful in 2m14s
sm-rpc / build (Release, arm-linux-gnueabihf) (push) Successful in 2m8s
sm-rpc / build (Debug, mipsel-linux-gnu) (push) Successful in 5m35s
sm-rpc / build (Release, host.gcc) (push) Failing after 1m55s
sm-rpc / build (Release, mipsel-linux-gnu) (push) Successful in 7m21s
fix: breakpad use miniz
2025-08-25 15:24:22 +08:00

83 lines
2.2 KiB
C++

#ifndef __TRACYSHORTPTR_HPP__
#define __TRACYSHORTPTR_HPP__
#include <assert.h>
#include <stdint.h>
#include <string.h>
#include "../public/common/TracyForceInline.hpp"
namespace tracy
{
#if UINTPTR_MAX == 0xFFFFFFFFFFFFFFFF
template<typename T>
class short_ptr
{
public:
tracy_force_inline short_ptr() {}
tracy_force_inline short_ptr( const T* ptr ) { set( ptr ); }
tracy_force_inline operator T*() { return get(); }
tracy_force_inline operator const T*() const { return get(); }
tracy_force_inline T& operator*() { return *get(); }
tracy_force_inline const T& operator*() const { return *get(); }
tracy_force_inline T* operator->() { return get(); }
tracy_force_inline const T* operator->() const { return get(); }
tracy_force_inline void set( const T* ptr )
{
assert( ( uint64_t( ptr ) & 0xFFFF000000000000 ) == 0 );
memcpy( m_ptr, &ptr, 4 );
memcpy( m_ptr+4, ((char*)&ptr)+4, 2 );
}
tracy_force_inline T* get()
{
uint32_t lo;
uint16_t hi;
memcpy( &lo, m_ptr, 4 );
memcpy( &hi, m_ptr+4, 2 );
return (T*)( uint64_t( lo ) | ( ( uint64_t( hi ) << 32 ) ) );
}
tracy_force_inline const T* get() const
{
uint32_t lo;
uint16_t hi;
memcpy( &lo, m_ptr, 4 );
memcpy( &hi, m_ptr+4, 2 );
return (T*)( uint64_t( lo ) | ( ( uint64_t( hi ) << 32 ) ) );
}
private:
uint8_t m_ptr[6];
};
#else
template<typename T>
class short_ptr
{
public:
tracy_force_inline short_ptr() {}
tracy_force_inline short_ptr( const T* ptr ) { memcpy( &m_ptr, &ptr, sizeof( T* ) ); }
tracy_force_inline operator T*() { return m_ptr; }
tracy_force_inline operator const T*() const { return m_ptr; }
tracy_force_inline T& operator*() { return *m_ptr; }
tracy_force_inline const T& operator*() const { return *m_ptr; }
tracy_force_inline T* operator->() { return m_ptr; }
tracy_force_inline const T* operator->() const { return m_ptr; }
tracy_force_inline void set( const T* ptr ) { m_ptr = ptr; }
tracy_force_inline T* get() { return m_ptr; }
tracy_force_inline const T* get() const { return m_ptr; }
private:
T* m_ptr;
};
#endif
}
#endif