More msvc compat

Signed-off-by: falkTX <falktx@falktx.com>
This commit is contained in:
falkTX 2023-05-06 17:55:48 +02:00
parent 1d0a4cb81e
commit 4aa25f7264
No known key found for this signature in database
GPG Key ID: CDBAA37ABC74FBA0
4 changed files with 39 additions and 26 deletions

View File

@ -1,6 +1,6 @@
/*
* Carla math utils
* Copyright (C) 2011-2022 Filipe Coelho <falktx@falktx.com>
* Copyright (C) 2011-2023 Filipe Coelho <falktx@falktx.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
@ -173,10 +173,12 @@ void carla_addFloats(float dest[], const float src[], const std::size_t count) n
for (std::size_t i=0; i<count; ++i)
{
#ifdef __GNUC__
if (!std::isfinite(dest[i]))
__builtin_unreachable();
if (!std::isfinite(src[i]))
__builtin_unreachable();
#endif
*dest++ += *src++;
}
}
@ -211,8 +213,10 @@ void carla_fillFloatsWithSingleValue(float data[], const float& value, const std
{
for (std::size_t i=0; i<count; ++i)
{
#ifdef __GNUC__
if (!std::isfinite(data[i]))
__builtin_unreachable();
#endif
*data++ = value;
}
}
@ -260,8 +264,10 @@ float carla_findMaxNormalizedFloat(const float floats[], const std::size_t count
for (std::size_t i=1; i<count; ++i)
{
#ifdef __GNUC__
if (!std::isfinite(floats[i]))
__builtin_unreachable();
#endif
tmp = std::abs(floats[i]);
@ -292,8 +298,10 @@ void carla_multiply(float data[], const float& multiplier, const std::size_t cou
{
for (std::size_t i=0; i<count; ++i)
{
#ifdef __GNUC__
if (!std::isfinite(data[i]))
__builtin_unreachable();
#endif
*data++ *= multiplier;
}
}

View File

@ -1,6 +1,6 @@
/*
* Carla Mutex
* Copyright (C) 2013-2022 Filipe Coelho <falktx@falktx.com>
* Copyright (C) 2013-2023 Filipe Coelho <falktx@falktx.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
@ -39,7 +39,12 @@ public:
{
pthread_mutexattr_t attr;
pthread_mutexattr_init(&attr);
#ifdef __GNUC__
pthread_mutexattr_setprotocol(&attr, inheritPriority ? PTHREAD_PRIO_INHERIT : PTHREAD_PRIO_NONE);
#else
// unsupported?
(void)inheritPriority;
#endif
pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_NORMAL);
pthread_mutex_init(&fMutex, &attr);
pthread_mutexattr_destroy(&attr);
@ -110,22 +115,22 @@ public:
* Constructor.
*/
CarlaRecursiveMutex() noexcept
#ifdef CARLA_OS_WIN
#ifdef CARLA_OS_WIN
: fSection()
#else
#else
: fMutex()
#endif
#endif
{
#ifdef CARLA_OS_WIN
#ifdef CARLA_OS_WIN
InitializeCriticalSection(&fSection);
#else
#else
pthread_mutexattr_t attr;
pthread_mutexattr_init(&attr);
pthread_mutexattr_setprotocol(&attr, PTHREAD_PRIO_INHERIT);
pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
pthread_mutex_init(&fMutex, &attr);
pthread_mutexattr_destroy(&attr);
#endif
#endif
}
/*
@ -133,11 +138,11 @@ public:
*/
~CarlaRecursiveMutex() noexcept
{
#ifdef CARLA_OS_WIN
#ifdef CARLA_OS_WIN
DeleteCriticalSection(&fSection);
#else
#else
pthread_mutex_destroy(&fMutex);
#endif
#endif
}
/*
@ -145,12 +150,12 @@ public:
*/
bool lock() const noexcept
{
#ifdef CARLA_OS_WIN
#ifdef CARLA_OS_WIN
EnterCriticalSection(&fSection);
return true;
#else
#else
return (pthread_mutex_lock(&fMutex) == 0);
#endif
#endif
}
/*
@ -159,11 +164,11 @@ public:
*/
bool tryLock() const noexcept
{
#ifdef CARLA_OS_WIN
#ifdef CARLA_OS_WIN
return (TryEnterCriticalSection(&fSection) != FALSE);
#else
#else
return (pthread_mutex_trylock(&fMutex) == 0);
#endif
#endif
}
/*
@ -171,19 +176,19 @@ public:
*/
void unlock() const noexcept
{
#ifdef CARLA_OS_WIN
#ifdef CARLA_OS_WIN
LeaveCriticalSection(&fSection);
#else
#else
pthread_mutex_unlock(&fMutex);
#endif
#endif
}
private:
#ifdef CARLA_OS_WIN
#ifdef CARLA_OS_WIN
mutable CRITICAL_SECTION fSection;
#else
#else
mutable pthread_mutex_t fMutex;
#endif
#endif
CARLA_DECLARE_NON_COPYABLE(CarlaRecursiveMutex)
};

View File

@ -1,6 +1,6 @@
/*
* Carla String
* Copyright (C) 2013-2019 Filipe Coelho <falktx@falktx.com>
* Copyright (C) 2013-2023 Filipe Coelho <falktx@falktx.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
@ -419,7 +419,7 @@ public:
if (char* const subStrBuf = std::strstr(fBuffer, strBuf))
{
const ssize_t ret(subStrBuf - fBuffer);
const ssize_t ret = subStrBuf - fBuffer;
if (ret < 0)
{

View File

@ -27,7 +27,7 @@
#include <cstring>
#ifdef CARLA_PROPER_CPP11_SUPPORT
# ifndef _MSC_VER
# ifdef __GNUC__
# include <cxxabi.h>
# endif
# include <cstdint>