From bc41a46dab60af0716aa01801e2693a4772535d6 Mon Sep 17 00:00:00 2001 From: Julian Storer Date: Tue, 9 Feb 2010 15:08:59 +0000 Subject: [PATCH] Fix for atomics in OSX10.4, and popup menus on unusual monitor arrangements. --- amalgamation/juce_amalgamated_template.cpp | 2 +- juce_amalgamated.cpp | 5 ++++- juce_amalgamated.h | 8 ++++++-- src/core/juce_Atomic.h | 8 ++++++-- src/gui/components/menus/juce_PopupMenu.cpp | 3 +++ 5 files changed, 20 insertions(+), 6 deletions(-) diff --git a/amalgamation/juce_amalgamated_template.cpp b/amalgamation/juce_amalgamated_template.cpp index 1bade1c5b9..8d9fd56c9f 100644 --- a/amalgamation/juce_amalgamated_template.cpp +++ b/amalgamation/juce_amalgamated_template.cpp @@ -79,7 +79,7 @@ #define NO_DUMMY_DECL #if JUCE_BUILD_NATIVE - #include "../src/../juce_amalgamated.h" + #include "../juce_amalgamated.h" // FORCE_AMALGAMATOR_INCLUDE #endif #if (defined(_MSC_VER) && (_MSC_VER <= 1200)) diff --git a/juce_amalgamated.cpp b/juce_amalgamated.cpp index 7f65e49ce1..d6427648af 100644 --- a/juce_amalgamated.cpp +++ b/juce_amalgamated.cpp @@ -613,7 +613,7 @@ public: #define NO_DUMMY_DECL #if JUCE_BUILD_NATIVE - #include "src/../juce_amalgamated.h" + #include "juce_amalgamated.h" // FORCE_AMALGAMATOR_INCLUDE #endif #if (defined(_MSC_VER) && (_MSC_VER <= 1200)) @@ -69029,6 +69029,9 @@ private: int deltaY = wantedY - currentY; + windowPos.setSize (jmin (windowPos.getWidth(), mon.getWidth()), + jmin (windowPos.getHeight(), mon.getHeight())); + const int newY = jlimit (mon.getY(), mon.getBottom() - windowPos.getHeight(), windowPos.getY() + deltaY); diff --git a/juce_amalgamated.h b/juce_amalgamated.h index 4a4f4508f8..ffe59966fc 100644 --- a/juce_amalgamated.h +++ b/juce_amalgamated.h @@ -3157,10 +3157,14 @@ inline void Atomic::decrement (int32& variable) { OSAtomicDecrement32 ((int32_ inline int32 Atomic::decrementAndReturn (int32& variable) { return OSAtomicDecrement32 ((int32_t*) &variable); } inline int32 Atomic::compareAndExchange (int32& destination, int32 newValue, int32 oldValue) { return OSAtomicCompareAndSwap32Barrier (oldValue, newValue, (int32_t*) &destination); } -inline void* Atomic::swapPointers (void* volatile* value1, void* volatile value2) +inline void* Atomic::swapPointers (void* volatile* value1, void* value2) { void* currentVal = *value1; +#if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5 && ! JUCE_64BIT + while (! OSAtomicCompareAndSwap32 ((int32_t) currentVal, (int32_t) value2, (int32_t*) value1)) { currentVal = *value1; } +#else while (! OSAtomicCompareAndSwapPtr (currentVal, value2, value1)) { currentVal = *value1; } +#endif return currentVal; } @@ -3172,7 +3176,7 @@ inline void Atomic::decrement (int32& variable) { __sync_add_and_fetch (&varia inline int32 Atomic::decrementAndReturn (int32& variable) { return __sync_add_and_fetch (&variable, -1); } inline int32 Atomic::compareAndExchange (int32& destination, int32 newValue, int32 oldValue) { return __sync_val_compare_and_swap (&destination, oldValue, newValue); } -inline void* Atomic::swapPointers (void* volatile* value1, void* volatile value2) +inline void* Atomic::swapPointers (void* volatile* value1, void* value2) { void* currentVal = *value1; while (! __sync_bool_compare_and_swap (value1, currentVal, value2)) { currentVal = *value1; } diff --git a/src/core/juce_Atomic.h b/src/core/juce_Atomic.h index 40772f7359..44fde2ee99 100644 --- a/src/core/juce_Atomic.h +++ b/src/core/juce_Atomic.h @@ -65,10 +65,14 @@ inline void Atomic::decrement (int32& variable) { OSAtomicDecrem inline int32 Atomic::decrementAndReturn (int32& variable) { return OSAtomicDecrement32 ((int32_t*) &variable); } inline int32 Atomic::compareAndExchange (int32& destination, int32 newValue, int32 oldValue) { return OSAtomicCompareAndSwap32Barrier (oldValue, newValue, (int32_t*) &destination); } -inline void* Atomic::swapPointers (void* volatile* value1, void* volatile value2) +inline void* Atomic::swapPointers (void* volatile* value1, void* value2) { void* currentVal = *value1; +#if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5 && ! JUCE_64BIT + while (! OSAtomicCompareAndSwap32 ((int32_t) currentVal, (int32_t) value2, (int32_t*) value1)) { currentVal = *value1; } +#else while (! OSAtomicCompareAndSwapPtr (currentVal, value2, value1)) { currentVal = *value1; } +#endif return currentVal; } @@ -81,7 +85,7 @@ inline void Atomic::decrement (int32& variable) { __sync_add_and inline int32 Atomic::decrementAndReturn (int32& variable) { return __sync_add_and_fetch (&variable, -1); } inline int32 Atomic::compareAndExchange (int32& destination, int32 newValue, int32 oldValue) { return __sync_val_compare_and_swap (&destination, oldValue, newValue); } -inline void* Atomic::swapPointers (void* volatile* value1, void* volatile value2) +inline void* Atomic::swapPointers (void* volatile* value1, void* value2) { void* currentVal = *value1; while (! __sync_bool_compare_and_swap (value1, currentVal, value2)) { currentVal = *value1; } diff --git a/src/gui/components/menus/juce_PopupMenu.cpp b/src/gui/components/menus/juce_PopupMenu.cpp index 3af507bcbe..e8f59b295a 100644 --- a/src/gui/components/menus/juce_PopupMenu.cpp +++ b/src/gui/components/menus/juce_PopupMenu.cpp @@ -1002,6 +1002,9 @@ private: int deltaY = wantedY - currentY; + windowPos.setSize (jmin (windowPos.getWidth(), mon.getWidth()), + jmin (windowPos.getHeight(), mon.getHeight())); + const int newY = jlimit (mon.getY(), mon.getBottom() - windowPos.getHeight(), windowPos.getY() + deltaY);