From 4aa25f7264c3e4dbddbb8e0a8ce496beb9e4d58d Mon Sep 17 00:00:00 2001 From: falkTX Date: Sat, 6 May 2023 17:55:48 +0200 Subject: [PATCH] More msvc compat Signed-off-by: falkTX --- source/utils/CarlaMathUtils.hpp | 10 ++++++- source/utils/CarlaMutex.hpp | 49 ++++++++++++++++++--------------- source/utils/CarlaString.hpp | 4 +-- source/utils/CarlaUtils.hpp | 2 +- 4 files changed, 39 insertions(+), 26 deletions(-) diff --git a/source/utils/CarlaMathUtils.hpp b/source/utils/CarlaMathUtils.hpp index 79c1f4938..7fdd55ab9 100644 --- a/source/utils/CarlaMathUtils.hpp +++ b/source/utils/CarlaMathUtils.hpp @@ -1,6 +1,6 @@ /* * Carla math utils - * Copyright (C) 2011-2022 Filipe Coelho + * Copyright (C) 2011-2023 Filipe Coelho * * 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 + * Copyright (C) 2013-2023 Filipe Coelho * * 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) }; diff --git a/source/utils/CarlaString.hpp b/source/utils/CarlaString.hpp index 048bf6f98..d2617c145 100644 --- a/source/utils/CarlaString.hpp +++ b/source/utils/CarlaString.hpp @@ -1,6 +1,6 @@ /* * Carla String - * Copyright (C) 2013-2019 Filipe Coelho + * Copyright (C) 2013-2023 Filipe Coelho * * 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) { diff --git a/source/utils/CarlaUtils.hpp b/source/utils/CarlaUtils.hpp index b8e6d1287..8143b2ee3 100644 --- a/source/utils/CarlaUtils.hpp +++ b/source/utils/CarlaUtils.hpp @@ -27,7 +27,7 @@ #include #ifdef CARLA_PROPER_CPP11_SUPPORT -# ifndef _MSC_VER +# ifdef __GNUC__ # include # endif # include