From dbf88cc20901ae4f4cdf4892606d3b5d71d839da Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Mon, 18 Nov 2013 14:21:06 +0000 Subject: [PATCH] From Stephan Huber, "minor ios-fixes/-enhancements * force _OPENTHREADS_ATOMIC_USE_BSD_ATOMIC for IOS device + simulator as the test does not pick the right implementation * fixed a small compile-bug for iphone-example * added a check to prevent multiple realization of a GraphicsWindowIOS-object " --- CMakeModules/CheckAtomicOps.cmake | 199 +++++++++--------- .../osgviewerIPhone/iphoneViewerAppDelegate.h | 1 - src/osgViewer/GraphicsWindowIOS.mm | 2 + 3 files changed, 107 insertions(+), 95 deletions(-) diff --git a/CMakeModules/CheckAtomicOps.cmake b/CMakeModules/CheckAtomicOps.cmake index e37532f32..a518e6ee8 100644 --- a/CMakeModules/CheckAtomicOps.cmake +++ b/CMakeModules/CheckAtomicOps.cmake @@ -1,4 +1,4 @@ -# Check for availability of atomic operations +# Check for availability of atomic operations # This module defines # OPENTHREADS_HAVE_ATOMIC_OPS @@ -15,123 +15,134 @@ IF (OPENTHREADS_ATOMIC_USE_MUTEX) SET(_OPENTHREADS_ATOMIC_USE_MUTEX 1) ELSE() + # as the test does not work for IOS hardcode the ATOMIC implementation + IF(OSG_BUILD_PLATFORM_IPHONE_SIMULATOR OR OSG_BUILD_PLATFORM_IPHONE) + SET(_OPENTHREADS_ATOMIC_USE_GCC_BUILTINS 0) + SET(_OPENTHREADS_ATOMIC_USE_MIPOSPRO_BUILTINS 0) + SET(_OPENTHREADS_ATOMIC_USE_SUN 0) + SET(_OPENTHREADS_ATOMIC_USE_WIN32_INTERLOCKED 0) + SET(_OPENTHREADS_ATOMIC_USE_MUTEX 0) - INCLUDE(CheckCXXSourceRuns) + SET(_OPENTHREADS_ATOMIC_USE_BSD_ATOMIC 1) - # Do step by step checking, - CHECK_CXX_SOURCE_RUNS(" - #include + ELSE() + INCLUDE(CheckCXXSourceRuns) - int main() - { - unsigned value = 0; - void* ptr = &value; - __sync_add_and_fetch(&value, 1); - __sync_synchronize(); - __sync_sub_and_fetch(&value, 1); - if (!__sync_bool_compare_and_swap(&value, 0, 1)) - return EXIT_FAILURE; + # Do step by step checking, + CHECK_CXX_SOURCE_RUNS(" + #include - if (!__sync_bool_compare_and_swap(&ptr, ptr, ptr)) - return EXIT_FAILURE; + int main() + { + unsigned value = 0; + void* ptr = &value; + __sync_add_and_fetch(&value, 1); + __sync_synchronize(); + __sync_sub_and_fetch(&value, 1); + if (!__sync_bool_compare_and_swap(&value, 0, 1)) + return EXIT_FAILURE; - return EXIT_SUCCESS; - } - " _OPENTHREADS_ATOMIC_USE_GCC_BUILTINS) + if (!__sync_bool_compare_and_swap(&ptr, ptr, ptr)) + return EXIT_FAILURE; - CHECK_CXX_SOURCE_RUNS(" - #include + return EXIT_SUCCESS; + } + " _OPENTHREADS_ATOMIC_USE_GCC_BUILTINS) - int main(int, const char**) - { - unsigned value = 0; - void* ptr = &value; - __add_and_fetch(&value, 1); - __synchronize(value); - __sub_and_fetch(&value, 1); - if (!__compare_and_swap(&value, 0, 1)) - return EXIT_FAILURE; + CHECK_CXX_SOURCE_RUNS(" + #include - if (!__compare_and_swap((unsigned long*)&ptr, (unsigned long)ptr, (unsigned long)ptr)) - return EXIT_FAILURE; + int main(int, const char**) + { + unsigned value = 0; + void* ptr = &value; + __add_and_fetch(&value, 1); + __synchronize(value); + __sub_and_fetch(&value, 1); + if (!__compare_and_swap(&value, 0, 1)) + return EXIT_FAILURE; - return EXIT_SUCCESS; - } - " _OPENTHREADS_ATOMIC_USE_MIPOSPRO_BUILTINS) + if (!__compare_and_swap((unsigned long*)&ptr, (unsigned long)ptr, (unsigned long)ptr)) + return EXIT_FAILURE; - CHECK_CXX_SOURCE_RUNS(" - #include - #include + return EXIT_SUCCESS; + } + " _OPENTHREADS_ATOMIC_USE_MIPOSPRO_BUILTINS) - int main(int, const char**) - { - uint_t value = 0; - void* ptr = &value; - atomic_inc_uint_nv(&value); - membar_consumer(); - atomic_dec_uint_nv(&value); - if (0 != atomic_cas_uint(&value, 0, 1)) - return EXIT_FAILURE; + CHECK_CXX_SOURCE_RUNS(" + #include + #include - if (ptr != atomic_cas_ptr(&ptr, ptr, ptr)) - return EXIT_FAILURE; + int main(int, const char**) + { + uint_t value = 0; + void* ptr = &value; + atomic_inc_uint_nv(&value); + membar_consumer(); + atomic_dec_uint_nv(&value); + if (0 != atomic_cas_uint(&value, 0, 1)) + return EXIT_FAILURE; - return EXIT_SUCCESS; - } - " _OPENTHREADS_ATOMIC_USE_SUN) + if (ptr != atomic_cas_ptr(&ptr, ptr, ptr)) + return EXIT_FAILURE; - CHECK_CXX_SOURCE_RUNS(" - #include - #include - #include + return EXIT_SUCCESS; + } + " _OPENTHREADS_ATOMIC_USE_SUN) - #pragma intrinsic(_InterlockedAnd) - #pragma intrinsic(_InterlockedOr) - #pragma intrinsic(_InterlockedXor) + CHECK_CXX_SOURCE_RUNS(" + #include + #include + #include - int main(int, const char**) - { - volatile long value = 0; - long data = 0; - long* volatile ptr = &data; + #pragma intrinsic(_InterlockedAnd) + #pragma intrinsic(_InterlockedOr) + #pragma intrinsic(_InterlockedXor) - InterlockedIncrement(&value); - MemoryBarrier(); - InterlockedDecrement(&value); + int main(int, const char**) + { + volatile long value = 0; + long data = 0; + long* volatile ptr = &data; - if (0 != InterlockedCompareExchange(&value, 1, 0)) - return EXIT_FAILURE; + InterlockedIncrement(&value); + MemoryBarrier(); + InterlockedDecrement(&value); - if (ptr != InterlockedCompareExchangePointer((PVOID volatile*)&ptr, (PVOID)ptr, (PVOID)ptr)) - return EXIT_FAILURE; + if (0 != InterlockedCompareExchange(&value, 1, 0)) + return EXIT_FAILURE; - return EXIT_SUCCESS; - } - " _OPENTHREADS_ATOMIC_USE_WIN32_INTERLOCKED) + if (ptr != InterlockedCompareExchangePointer((PVOID volatile*)&ptr, (PVOID)ptr, (PVOID)ptr)) + return EXIT_FAILURE; - CHECK_CXX_SOURCE_RUNS(" - #include + return EXIT_SUCCESS; + } + " _OPENTHREADS_ATOMIC_USE_WIN32_INTERLOCKED) - int main() - { - volatile int32_t value = 0; - long data = 0; - long * volatile ptr = &data; + CHECK_CXX_SOURCE_RUNS(" + #include - OSAtomicIncrement32(&value); - OSMemoryBarrier(); - OSAtomicDecrement32(&value); - OSAtomicCompareAndSwapInt(value, 1, &value); - OSAtomicCompareAndSwapPtr(ptr, ptr, (void * volatile *)&ptr); - } - " _OPENTHREADS_ATOMIC_USE_BSD_ATOMIC) + int main() + { + volatile int32_t value = 0; + long data = 0; + long * volatile ptr = &data; - IF(NOT _OPENTHREADS_ATOMIC_USE_GCC_BUILTINS AND - NOT _OPENTHREADS_ATOMIC_USE_MIPOSPRO_BUILTINS AND - NOT _OPENTHREADS_ATOMIC_USE_SUN AND - NOT _OPENTHREADS_ATOMIC_USE_WIN32_INTERLOCKED AND - NOT _OPENTHREADS_ATOMIC_USE_BSD_ATOMIC) - SET(_OPENTHREADS_ATOMIC_USE_MUTEX 1) + OSAtomicIncrement32(&value); + OSMemoryBarrier(); + OSAtomicDecrement32(&value); + OSAtomicCompareAndSwapInt(value, 1, &value); + OSAtomicCompareAndSwapPtr(ptr, ptr, (void * volatile *)&ptr); + } + " _OPENTHREADS_ATOMIC_USE_BSD_ATOMIC) + + IF(NOT _OPENTHREADS_ATOMIC_USE_GCC_BUILTINS AND + NOT _OPENTHREADS_ATOMIC_USE_MIPOSPRO_BUILTINS AND + NOT _OPENTHREADS_ATOMIC_USE_SUN AND + NOT _OPENTHREADS_ATOMIC_USE_WIN32_INTERLOCKED AND + NOT _OPENTHREADS_ATOMIC_USE_BSD_ATOMIC) + SET(_OPENTHREADS_ATOMIC_USE_MUTEX 1) + ENDIF() ENDIF() ENDIF() diff --git a/examples/osgviewerIPhone/iphoneViewerAppDelegate.h b/examples/osgviewerIPhone/iphoneViewerAppDelegate.h index 25fa77e2c..ddcc4ba59 100644 --- a/examples/osgviewerIPhone/iphoneViewerAppDelegate.h +++ b/examples/osgviewerIPhone/iphoneViewerAppDelegate.h @@ -5,7 +5,6 @@ #include #include -#include #include #include diff --git a/src/osgViewer/GraphicsWindowIOS.mm b/src/osgViewer/GraphicsWindowIOS.mm index 89b54e977..535b2dc85 100644 --- a/src/osgViewer/GraphicsWindowIOS.mm +++ b/src/osgViewer/GraphicsWindowIOS.mm @@ -746,6 +746,8 @@ void GraphicsWindowIOS::init() bool GraphicsWindowIOS::realizeImplementation() { + if (_realized) return true; + NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; BOOL bar_hidden = (_traits->windowDecoration) ? NO: YES;