Browse Source

More msvc compat

Signed-off-by: falkTX <falktx@falktx.com>
pull/1775/head
falkTX 2 years ago
parent
commit
4aa25f7264
Signed by: falkTX <falktx@falktx.com> GPG Key ID: CDBAA37ABC74FBA0
4 changed files with 39 additions and 26 deletions
  1. +9
    -1
      source/utils/CarlaMathUtils.hpp
  2. +27
    -22
      source/utils/CarlaMutex.hpp
  3. +2
    -2
      source/utils/CarlaString.hpp
  4. +1
    -1
      source/utils/CarlaUtils.hpp

+ 9
- 1
source/utils/CarlaMathUtils.hpp View File

@@ -1,6 +1,6 @@
/* /*
* Carla math utils * 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 * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as * 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) for (std::size_t i=0; i<count; ++i)
{ {
#ifdef __GNUC__
if (!std::isfinite(dest[i])) if (!std::isfinite(dest[i]))
__builtin_unreachable(); __builtin_unreachable();
if (!std::isfinite(src[i])) if (!std::isfinite(src[i]))
__builtin_unreachable(); __builtin_unreachable();
#endif
*dest++ += *src++; *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) for (std::size_t i=0; i<count; ++i)
{ {
#ifdef __GNUC__
if (!std::isfinite(data[i])) if (!std::isfinite(data[i]))
__builtin_unreachable(); __builtin_unreachable();
#endif
*data++ = value; *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) for (std::size_t i=1; i<count; ++i)
{ {
#ifdef __GNUC__
if (!std::isfinite(floats[i])) if (!std::isfinite(floats[i]))
__builtin_unreachable(); __builtin_unreachable();
#endif


tmp = std::abs(floats[i]); 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) for (std::size_t i=0; i<count; ++i)
{ {
#ifdef __GNUC__
if (!std::isfinite(data[i])) if (!std::isfinite(data[i]))
__builtin_unreachable(); __builtin_unreachable();
#endif
*data++ *= multiplier; *data++ *= multiplier;
} }
} }


+ 27
- 22
source/utils/CarlaMutex.hpp View File

@@ -1,6 +1,6 @@
/* /*
* Carla Mutex * 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 * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as * modify it under the terms of the GNU General Public License as
@@ -39,7 +39,12 @@ public:
{ {
pthread_mutexattr_t attr; pthread_mutexattr_t attr;
pthread_mutexattr_init(&attr); pthread_mutexattr_init(&attr);
#ifdef __GNUC__
pthread_mutexattr_setprotocol(&attr, inheritPriority ? PTHREAD_PRIO_INHERIT : PTHREAD_PRIO_NONE); pthread_mutexattr_setprotocol(&attr, inheritPriority ? PTHREAD_PRIO_INHERIT : PTHREAD_PRIO_NONE);
#else
// unsupported?
(void)inheritPriority;
#endif
pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_NORMAL); pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_NORMAL);
pthread_mutex_init(&fMutex, &attr); pthread_mutex_init(&fMutex, &attr);
pthread_mutexattr_destroy(&attr); pthread_mutexattr_destroy(&attr);
@@ -110,22 +115,22 @@ public:
* Constructor. * Constructor.
*/ */
CarlaRecursiveMutex() noexcept CarlaRecursiveMutex() noexcept
#ifdef CARLA_OS_WIN
#ifdef CARLA_OS_WIN
: fSection() : fSection()
#else
#else
: fMutex() : fMutex()
#endif
#endif
{ {
#ifdef CARLA_OS_WIN
#ifdef CARLA_OS_WIN
InitializeCriticalSection(&fSection); InitializeCriticalSection(&fSection);
#else
#else
pthread_mutexattr_t attr; pthread_mutexattr_t attr;
pthread_mutexattr_init(&attr); pthread_mutexattr_init(&attr);
pthread_mutexattr_setprotocol(&attr, PTHREAD_PRIO_INHERIT); pthread_mutexattr_setprotocol(&attr, PTHREAD_PRIO_INHERIT);
pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE); pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
pthread_mutex_init(&fMutex, &attr); pthread_mutex_init(&fMutex, &attr);
pthread_mutexattr_destroy(&attr); pthread_mutexattr_destroy(&attr);
#endif
#endif
} }


/* /*
@@ -133,11 +138,11 @@ public:
*/ */
~CarlaRecursiveMutex() noexcept ~CarlaRecursiveMutex() noexcept
{ {
#ifdef CARLA_OS_WIN
#ifdef CARLA_OS_WIN
DeleteCriticalSection(&fSection); DeleteCriticalSection(&fSection);
#else
#else
pthread_mutex_destroy(&fMutex); pthread_mutex_destroy(&fMutex);
#endif
#endif
} }


/* /*
@@ -145,12 +150,12 @@ public:
*/ */
bool lock() const noexcept bool lock() const noexcept
{ {
#ifdef CARLA_OS_WIN
#ifdef CARLA_OS_WIN
EnterCriticalSection(&fSection); EnterCriticalSection(&fSection);
return true; return true;
#else
#else
return (pthread_mutex_lock(&fMutex) == 0); return (pthread_mutex_lock(&fMutex) == 0);
#endif
#endif
} }


/* /*
@@ -159,11 +164,11 @@ public:
*/ */
bool tryLock() const noexcept bool tryLock() const noexcept
{ {
#ifdef CARLA_OS_WIN
#ifdef CARLA_OS_WIN
return (TryEnterCriticalSection(&fSection) != FALSE); return (TryEnterCriticalSection(&fSection) != FALSE);
#else
#else
return (pthread_mutex_trylock(&fMutex) == 0); return (pthread_mutex_trylock(&fMutex) == 0);
#endif
#endif
} }


/* /*
@@ -171,19 +176,19 @@ public:
*/ */
void unlock() const noexcept void unlock() const noexcept
{ {
#ifdef CARLA_OS_WIN
#ifdef CARLA_OS_WIN
LeaveCriticalSection(&fSection); LeaveCriticalSection(&fSection);
#else
#else
pthread_mutex_unlock(&fMutex); pthread_mutex_unlock(&fMutex);
#endif
#endif
} }


private: private:
#ifdef CARLA_OS_WIN
#ifdef CARLA_OS_WIN
mutable CRITICAL_SECTION fSection; mutable CRITICAL_SECTION fSection;
#else
#else
mutable pthread_mutex_t fMutex; mutable pthread_mutex_t fMutex;
#endif
#endif


CARLA_DECLARE_NON_COPYABLE(CarlaRecursiveMutex) CARLA_DECLARE_NON_COPYABLE(CarlaRecursiveMutex)
}; };


+ 2
- 2
source/utils/CarlaString.hpp View File

@@ -1,6 +1,6 @@
/* /*
* Carla String * 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 * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as * 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)) if (char* const subStrBuf = std::strstr(fBuffer, strBuf))
{ {
const ssize_t ret(subStrBuf - fBuffer);
const ssize_t ret = subStrBuf - fBuffer;


if (ret < 0) if (ret < 0)
{ {


+ 1
- 1
source/utils/CarlaUtils.hpp View File

@@ -27,7 +27,7 @@
#include <cstring> #include <cstring>


#ifdef CARLA_PROPER_CPP11_SUPPORT #ifdef CARLA_PROPER_CPP11_SUPPORT
# ifndef _MSC_VER
# ifdef __GNUC__
# include <cxxabi.h> # include <cxxabi.h>
# endif # endif
# include <cstdint> # include <cstdint>


Loading…
Cancel
Save