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
"
This commit is contained in:
Robert Osfield 2013-11-18 14:21:06 +00:00
parent d8c1c4bbeb
commit dbf88cc209
3 changed files with 107 additions and 95 deletions

View File

@ -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 <cstdlib>
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 <cstdlib>
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 <stdlib.h>
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 <stdlib.h>
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 <atomic.h>
#include <cstdlib>
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 <atomic.h>
#include <cstdlib>
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 <windows.h>
#include <intrin.h>
#include <cstdlib>
return EXIT_SUCCESS;
}
" _OPENTHREADS_ATOMIC_USE_SUN)
#pragma intrinsic(_InterlockedAnd)
#pragma intrinsic(_InterlockedOr)
#pragma intrinsic(_InterlockedXor)
CHECK_CXX_SOURCE_RUNS("
#include <windows.h>
#include <intrin.h>
#include <cstdlib>
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 <libkern/OSAtomic.h>
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 <libkern/OSAtomic.h>
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()

View File

@ -5,7 +5,6 @@
#include <osgDB/ReadFile>
#include <osg/MatrixTransform>
#include <osg/CameraNode>
#include <osgText/Text>
#include <osgViewer/Viewer>

View File

@ -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;