Merged in tillrathmann/tracy_for_multi_dll_projects (pull request #20)

Master
This commit is contained in:
Till Rathmann 2018-08-01 17:24:16 +00:00 committed by Bartosz Taudul
commit 2fe073e195
11 changed files with 68 additions and 30 deletions

View File

@ -11,10 +11,6 @@
// Define TRACY_ENABLE to enable profiler. // Define TRACY_ENABLE to enable profiler.
#if ( defined _MSC_VER || defined __CYGWIN__ ) && !defined WIN32_LEAN_AND_MEAN
# define WIN32_LEAN_AND_MEAN
#endif
#include "common/TracySystem.cpp" #include "common/TracySystem.cpp"
#ifdef TRACY_ENABLE #ifdef TRACY_ENABLE

View File

@ -5,7 +5,10 @@
#if TRACY_HAS_CALLSTACK == 1 #if TRACY_HAS_CALLSTACK == 1
# include <windows.h> # include <windows.h>
# pragma warning( push )
# pragma warning( disable : 4091 )
# include <dbghelp.h> # include <dbghelp.h>
# pragma warning( pop )
#elif TRACY_HAS_CALLSTACK >= 2 #elif TRACY_HAS_CALLSTACK >= 2
# include <dlfcn.h> # include <dlfcn.h>
# include <cxxabi.h> # include <cxxabi.h>

View File

@ -85,7 +85,7 @@ static int SetupHwTimerFailed()
return sigsetjmp( SigIllEnv, 1 ); return sigsetjmp( SigIllEnv, 1 );
} }
static void SetupHwTimerSigIllHandler( int signum ) static void SetupHwTimerSigIllHandler( int /*signum*/ )
{ {
siglongjmp( SigIllEnv, 1 ); siglongjmp( SigIllEnv, 1 );
} }
@ -124,6 +124,7 @@ static int64_t SetupHwTimer()
static const char* GetProcessName() static const char* GetProcessName()
{ {
const char* processName = "unknown";
#if defined _MSC_VER #if defined _MSC_VER
static char buf[_MAX_PATH]; static char buf[_MAX_PATH];
GetModuleFileNameA( nullptr, buf, _MAX_PATH ); GetModuleFileNameA( nullptr, buf, _MAX_PATH );
@ -131,16 +132,16 @@ static const char* GetProcessName()
while( *ptr != '\0' ) ptr++; while( *ptr != '\0' ) ptr++;
while( ptr > buf && *ptr != '\\' && *ptr != '/' ) ptr--; while( ptr > buf && *ptr != '\\' && *ptr != '/' ) ptr--;
if( ptr > buf ) ptr++; if( ptr > buf ) ptr++;
return ptr; processName = ptr;
#elif defined __ANDROID__ #elif defined __ANDROID__
# if __ANDROID_API__ >= 21 # if __ANDROID_API__ >= 21
auto buf = getprogname(); auto buf = getprogname();
if( buf ) return buf; if( buf ) processName = buf;
# endif # endif
#elif defined _GNU_SOURCE || defined __CYGWIN__ #elif defined _GNU_SOURCE || defined __CYGWIN__
return program_invocation_short_name; processName = program_invocation_short_name;
#endif #endif
return "unknown"; return processName;
} }
enum { QueuePrealloc = 256 * 1024 }; enum { QueuePrealloc = 256 * 1024 };
@ -728,7 +729,7 @@ void Profiler::SendCallstackPayload( uint64_t _ptr )
AppendDataUnsafe( &item, QueueDataSize[(int)QueueType::CallstackPayload] ); AppendDataUnsafe( &item, QueueDataSize[(int)QueueType::CallstackPayload] );
AppendDataUnsafe( &l16, sizeof( l16 ) ); AppendDataUnsafe( &l16, sizeof( l16 ) );
if( sizeof( uintptr_t ) == sizeof( uint64_t ) ) if( compile_time_condition<sizeof( uintptr_t ) == sizeof( uint64_t )>::value )
{ {
AppendDataUnsafe( ptr, sizeof( uint64_t ) * sz ); AppendDataUnsafe( ptr, sizeof( uint64_t ) * sz );
} }

View File

@ -373,7 +373,7 @@ private:
MemWrite( &item->memAlloc.time, GetTime() ); MemWrite( &item->memAlloc.time, GetTime() );
MemWrite( &item->memAlloc.thread, thread ); MemWrite( &item->memAlloc.thread, thread );
MemWrite( &item->memAlloc.ptr, (uint64_t)ptr ); MemWrite( &item->memAlloc.ptr, (uint64_t)ptr );
if( sizeof( size ) == 4 ) if( compile_time_condition<sizeof( size ) == 4>::value )
{ {
memcpy( &item->memAlloc.size, &size, 4 ); memcpy( &item->memAlloc.size, &size, 4 );
memset( &item->memAlloc.size + 4, 0, 2 ); memset( &item->memAlloc.size + 4, 0, 2 );

View File

@ -231,6 +231,21 @@ namespace moodycamel { namespace details {
#endif #endif
} } } }
namespace
{
// to avoid MSVC warning 4127: conditional expression is constant
template <bool>
struct compile_time_condition
{
static const bool value = false;
};
template <>
struct compile_time_condition<true>
{
static const bool value = true;
};
}
#ifdef MOODYCAMEL_QUEUE_INTERNAL_DEBUG #ifdef MOODYCAMEL_QUEUE_INTERNAL_DEBUG
#include "internal/concurrentqueue_internal_debug.h" #include "internal/concurrentqueue_internal_debug.h"
#endif #endif
@ -797,7 +812,7 @@ public:
} }
// Destroy implicit producer hash tables // Destroy implicit producer hash tables
if (INITIAL_IMPLICIT_PRODUCER_HASH_SIZE != 0) { if (compile_time_condition<INITIAL_IMPLICIT_PRODUCER_HASH_SIZE != 0>::value) {
auto hash = implicitProducerHash.load(std::memory_order_relaxed); auto hash = implicitProducerHash.load(std::memory_order_relaxed);
while (hash != nullptr) { while (hash != nullptr) {
auto prev = hash->prev; auto prev = hash->prev;
@ -1504,7 +1519,7 @@ private:
template<InnerQueueContext context> template<InnerQueueContext context>
inline bool is_empty() const inline bool is_empty() const
{ {
if (context == explicit_context && BLOCK_SIZE <= EXPLICIT_BLOCK_EMPTY_COUNTER_THRESHOLD) { if (compile_time_condition<context == explicit_context && BLOCK_SIZE <= EXPLICIT_BLOCK_EMPTY_COUNTER_THRESHOLD>::value) {
// Check flags // Check flags
for (size_t i = 0; i < BLOCK_SIZE; ++i) { for (size_t i = 0; i < BLOCK_SIZE; ++i) {
if (!emptyFlags[i].load(std::memory_order_relaxed)) { if (!emptyFlags[i].load(std::memory_order_relaxed)) {
@ -1550,7 +1565,7 @@ private:
template<InnerQueueContext context> template<InnerQueueContext context>
inline bool set_many_empty(index_t i, size_t count) inline bool set_many_empty(index_t i, size_t count)
{ {
if (context == explicit_context && BLOCK_SIZE <= EXPLICIT_BLOCK_EMPTY_COUNTER_THRESHOLD) { if (compile_time_condition<context == explicit_context && BLOCK_SIZE <= EXPLICIT_BLOCK_EMPTY_COUNTER_THRESHOLD>::value) {
// Set flags // Set flags
std::atomic_thread_fence(std::memory_order_release); std::atomic_thread_fence(std::memory_order_release);
i = BLOCK_SIZE - 1 - static_cast<size_t>(i & static_cast<index_t>(BLOCK_SIZE - 1)) - count + 1; i = BLOCK_SIZE - 1 - static_cast<size_t>(i & static_cast<index_t>(BLOCK_SIZE - 1)) - count + 1;
@ -1586,7 +1601,7 @@ private:
template<InnerQueueContext context> template<InnerQueueContext context>
inline void reset_empty() inline void reset_empty()
{ {
if (context == explicit_context && BLOCK_SIZE <= EXPLICIT_BLOCK_EMPTY_COUNTER_THRESHOLD) { if (compile_time_condition<context == explicit_context && BLOCK_SIZE <= EXPLICIT_BLOCK_EMPTY_COUNTER_THRESHOLD>::value) {
// Reset flags // Reset flags
for (size_t i = 0; i != BLOCK_SIZE; ++i) { for (size_t i = 0; i != BLOCK_SIZE; ++i) {
emptyFlags[i].store(false, std::memory_order_relaxed); emptyFlags[i].store(false, std::memory_order_relaxed);
@ -3298,7 +3313,7 @@ private:
inline void populate_initial_implicit_producer_hash() inline void populate_initial_implicit_producer_hash()
{ {
if (INITIAL_IMPLICIT_PRODUCER_HASH_SIZE == 0) return; if (compile_time_condition<INITIAL_IMPLICIT_PRODUCER_HASH_SIZE == 0>::value) return;
implicitProducerHashCount.store(0, std::memory_order_relaxed); implicitProducerHashCount.store(0, std::memory_order_relaxed);
auto hash = &initialImplicitProducerHash; auto hash = &initialImplicitProducerHash;
@ -3640,7 +3655,7 @@ ConsumerToken::ConsumerToken(ConcurrentQueue<T, Traits>& queue)
: itemsConsumedFromCurrent(0), currentProducer(nullptr), desiredProducer(nullptr) : itemsConsumedFromCurrent(0), currentProducer(nullptr), desiredProducer(nullptr)
{ {
initialOffset = queue.nextExplicitConsumerId.fetch_add(1, std::memory_order_release); initialOffset = queue.nextExplicitConsumerId.fetch_add(1, std::memory_order_release);
lastKnownGlobalOffset = -1; lastKnownGlobalOffset = static_cast<std::uint32_t>(-1);
} }
template<typename T, typename Traits> template<typename T, typename Traits>
@ -3648,7 +3663,7 @@ ConsumerToken::ConsumerToken(BlockingConcurrentQueue<T, Traits>& queue)
: itemsConsumedFromCurrent(0), currentProducer(nullptr), desiredProducer(nullptr) : itemsConsumedFromCurrent(0), currentProducer(nullptr), desiredProducer(nullptr)
{ {
initialOffset = reinterpret_cast<ConcurrentQueue<T, Traits>*>(&queue)->nextExplicitConsumerId.fetch_add(1, std::memory_order_release); initialOffset = reinterpret_cast<ConcurrentQueue<T, Traits>*>(&queue)->nextExplicitConsumerId.fetch_add(1, std::memory_order_release);
lastKnownGlobalOffset = -1; lastKnownGlobalOffset = static_cast<std::uint32_t>(-1);
} }
template<typename T, typename Traits> template<typename T, typename Traits>

View File

@ -85,6 +85,8 @@
/// Platform and arch specifics /// Platform and arch specifics
#ifdef _MSC_VER #ifdef _MSC_VER
# pragma warning( push )
# pragma warning( disable : 4324 )
# define ALIGNED_STRUCT(name, alignment) __declspec(align(alignment)) struct name # define ALIGNED_STRUCT(name, alignment) __declspec(align(alignment)) struct name
# define FORCEINLINE __forceinline # define FORCEINLINE __forceinline
# define atomic_thread_fence_acquire() //_ReadWriteBarrier() # define atomic_thread_fence_acquire() //_ReadWriteBarrier()
@ -1769,13 +1771,13 @@ _memory_map_os(size_t size, size_t* offset) {
//Ok to MEM_COMMIT - according to MSDN, "actual physical pages are not allocated unless/until the virtual addresses are actually accessed" //Ok to MEM_COMMIT - according to MSDN, "actual physical pages are not allocated unless/until the virtual addresses are actually accessed"
void* ptr = VirtualAlloc(0, size + padding, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE); void* ptr = VirtualAlloc(0, size + padding, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE);
if (!ptr) { if (!ptr) {
assert("Failed to map virtual memory block" == 0); assert("Failed to map virtual memory block" && 0);
return 0; return 0;
} }
#else #else
void* ptr = mmap(0, size + padding, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS | MAP_UNINITIALIZED, -1, 0); void* ptr = mmap(0, size + padding, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS | MAP_UNINITIALIZED, -1, 0);
if ((ptr == MAP_FAILED) || !ptr) { if ((ptr == MAP_FAILED) || !ptr) {
assert("Failed to map virtual memory block" == 0); assert("Failed to map virtual memory block" && 0);
return 0; return 0;
} }
#endif #endif
@ -1813,12 +1815,12 @@ _memory_unmap_os(void* address, size_t size, size_t offset, int release) {
#if PLATFORM_WINDOWS #if PLATFORM_WINDOWS
if (!VirtualFree(address, release ? 0 : size, release ? MEM_RELEASE : MEM_DECOMMIT)) { if (!VirtualFree(address, release ? 0 : size, release ? MEM_RELEASE : MEM_DECOMMIT)) {
DWORD err = GetLastError(); DWORD err = GetLastError();
assert("Failed to unmap virtual memory block" == 0); assert("Failed to unmap virtual memory block" && err && 0);
} }
#else #else
MEMORY_UNUSED(release); MEMORY_UNUSED(release);
if (munmap(address, size)) { if (munmap(address, size)) {
assert("Failed to unmap virtual memory block" == 0); assert("Failed to unmap virtual memory block" && 0);
} }
#endif #endif
} }
@ -1854,7 +1856,7 @@ _memory_guard_validate(void* p) {
if (_memory_config.memory_overwrite) if (_memory_config.memory_overwrite)
_memory_config.memory_overwrite(p); _memory_config.memory_overwrite(p);
else else
assert("Memory overwrite before block start" == 0); assert("Memory overwrite before block start" && 0);
return; return;
} }
deadzone[i] = 0; deadzone[i] = 0;
@ -1866,7 +1868,7 @@ _memory_guard_validate(void* p) {
if (_memory_config.memory_overwrite) if (_memory_config.memory_overwrite)
_memory_config.memory_overwrite(p); _memory_config.memory_overwrite(p);
else else
assert("Memory overwrite after block end" == 0); assert("Memory overwrite after block end" && 0);
return; return;
} }
deadzone[i] = 0; deadzone[i] = 0;
@ -2086,4 +2088,8 @@ rpmalloc_global_statistics(rpmalloc_global_statistics_t* stats) {
} }
#ifdef _MSC_VER
# pragma warning( pop )
#endif
#endif #endif

View File

@ -25,6 +25,12 @@
namespace tracy namespace tracy
{ {
#ifdef _MSC_VER
typedef SOCKET socket_t;
#else
typedef int socket_t;
#endif
#ifdef _MSC_VER #ifdef _MSC_VER
struct __wsinit struct __wsinit
{ {
@ -86,7 +92,7 @@ bool Socket::Connect( const char* addr, const char* port )
hints.ai_socktype = SOCK_STREAM; hints.ai_socktype = SOCK_STREAM;
if( getaddrinfo( addr, port, &hints, &res ) != 0 ) return false; if( getaddrinfo( addr, port, &hints, &res ) != 0 ) return false;
int sock; int sock = 0;
for( ptr = res; ptr; ptr = ptr->ai_next ) for( ptr = res; ptr; ptr = ptr->ai_next )
{ {
if( ( sock = socket( ptr->ai_family, ptr->ai_socktype, ptr->ai_protocol ) ) == -1 ) continue; if( ( sock = socket( ptr->ai_family, ptr->ai_socktype, ptr->ai_protocol ) ) == -1 ) continue;
@ -174,7 +180,7 @@ int Socket::Recv( void* _buf, int len, const timeval* tv )
fd_set fds; fd_set fds;
FD_ZERO( &fds ); FD_ZERO( &fds );
FD_SET( m_sock, &fds ); FD_SET( static_cast<socket_t>(m_sock), &fds );
#ifndef _WIN32 #ifndef _WIN32
timeval _tv = *tv; timeval _tv = *tv;
@ -231,7 +237,7 @@ bool Socket::HasData()
fd_set fds; fd_set fds;
FD_ZERO( &fds ); FD_ZERO( &fds );
FD_SET( m_sock, &fds ); FD_SET( static_cast<socket_t>(m_sock), &fds );
return select( m_sock+1, &fds, nullptr, nullptr, &tv ) > 0; return select( m_sock+1, &fds, nullptr, nullptr, &tv ) > 0;
} }
@ -287,7 +293,7 @@ Socket* ListenSocket::Accept()
fd_set fds; fd_set fds;
FD_ZERO( &fds ); FD_ZERO( &fds );
FD_SET( m_sock, &fds ); FD_SET( static_cast<socket_t>(m_sock), &fds );
select( m_sock+1, &fds, nullptr, nullptr, &tv ); select( m_sock+1, &fds, nullptr, nullptr, &tv );
if( FD_ISSET( m_sock, &fds ) ) if( FD_ISSET( m_sock, &fds ) )

View File

@ -1,3 +1,11 @@
#if defined _MSC_VER || defined __CYGWIN__ || defined _WIN32
# ifndef WIN32_LEAN_AND_MEAN
# define WIN32_LEAN_AND_MEAN
# endif
# ifndef NOMINMAX
# define NOMINMAX
# endif
#endif
#ifdef _WIN32 #ifdef _WIN32
# include <windows.h> # include <windows.h>
#else #else

View File

@ -701,7 +701,7 @@ LZ4_FORCE_INLINE int LZ4_compress_generic(
cctx->dictSize += (U32)inputSize; cctx->dictSize += (U32)inputSize;
} }
cctx->currentOffset += (U32)inputSize; cctx->currentOffset += (U32)inputSize;
cctx->tableType = tableType; cctx->tableType = (U16)tableType;
if (inputSize<LZ4_minLength) goto _last_literals; /* Input too small, no compression (all literals) */ if (inputSize<LZ4_minLength) goto _last_literals; /* Input too small, no compression (all literals) */

View File

@ -596,7 +596,7 @@ LZ4_DEPRECATED("Use LZ4_resetStream() instead") LZ4LIB_API int LZ4_resetStrea
LZ4_DEPRECATED("Use LZ4_saveDict() instead") LZ4LIB_API char* LZ4_slideInputBuffer (void* state); LZ4_DEPRECATED("Use LZ4_saveDict() instead") LZ4LIB_API char* LZ4_slideInputBuffer (void* state);
/* Obsolete streaming decoding functions */ /* Obsolete streaming decoding functions */
LZ4_DEPRECATED("use LZ4_decompress_safe_usingDict() instead") LZ4LIB_API int LZ4_decompress_safe_withPrefix64k (const char* src, char* dst, int compressedSize, int maxDstSize); /*LZ4_DEPRECATED("use LZ4_decompress_safe_usingDict() instead")*/ LZ4LIB_API int LZ4_decompress_safe_withPrefix64k (const char* src, char* dst, int compressedSize, int maxDstSize);
LZ4_DEPRECATED("use LZ4_decompress_fast_usingDict() instead") LZ4LIB_API int LZ4_decompress_fast_withPrefix64k (const char* src, char* dst, int originalSize); LZ4_DEPRECATED("use LZ4_decompress_fast_usingDict() instead") LZ4LIB_API int LZ4_decompress_fast_withPrefix64k (const char* src, char* dst, int originalSize);
} }

View File

@ -19,7 +19,10 @@
#include <stdio.h> #include <stdio.h>
#include <assert.h> #include <assert.h>
#include <windows.h> #include <windows.h>
struct IUnknown; // Workaround for "combaseapi.h(229): error C2187: syntax error: 'identifier' was unexpected here" when using /permissive-
#include <ShObjIdl.h> #include <ShObjIdl.h>
#include "nfd_common.h" #include "nfd_common.h"