diff -r e1b950c65cb4 -r 837f303aceeb epoc32/include/stdapis/stlportv5/stl/_threads.c --- a/epoc32/include/stdapis/stlportv5/stl/_threads.c Wed Mar 31 12:27:01 2010 +0100 +++ b/epoc32/include/stdapis/stlportv5/stl/_threads.c Wed Mar 31 12:33:34 2010 +0100 @@ -1,5 +1,5 @@ /* - * + * Portions Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies). All rights reserved. * * Copyright (c) 1994 * Hewlett-Packard Company @@ -10,13 +10,13 @@ * Copyright (c) 1997 * Moscow Center for SPARC Technology * - * Copyright (c) 1999 + * Copyright (c) 1999 * Boris Fomitchev * * This material is provided "as is", with absolutely no warranty expressed * or implied. Any use is at your own risk. * - * Permission to use or copy this software for any purpose is hereby granted + * Permission to use or copy this software for any purpose is hereby granted * without fee, provided the above notices are retained on all copies. * Permission to modify the code and to distribute modified code is granted, * provided the above notices are retained, and a notice that the code was @@ -27,106 +27,111 @@ #define _STLP_THREADS_C #ifndef _STLP_INTERNAL_THREADS_H -# include +# include #endif -# if defined (_STLP_EXPOSE_GLOBALS_IMPLEMENTATION) +#if defined (_STLP_EXPOSE_GLOBALS_IMPLEMENTATION) -# if defined(_STLP_SGI_THREADS) +#if defined (_STLP_SGI_THREADS) # include -# elif defined (_STLP_UNIX) -# include -# if defined (_STLP_USE_NAMESPACES) && ! defined (_STLP_VENDOR_GLOBAL_CSTD) +#elif defined (_STLP_UNIX) +# ifndef _STLP_INTERNAL_CTIME +# include +# endif +# if defined (_STLP_USE_NAMESPACES) && !defined (_STLP_VENDOR_GLOBAL_CSTD) using _STLP_VENDOR_CSTD::time_t; -# endif +# endif # include -# endif +#endif _STLP_BEGIN_NAMESPACE -# if (_STLP_STATIC_TEMPLATE_DATA > 0) +#if (_STLP_STATIC_TEMPLATE_DATA > 0) -# ifdef _STLP_THREADS -# if !defined(_STLP_ATOMIC_EXCHANGE) && (defined(_STLP_PTHREADS) || defined(_STLP_UITHREADS) || defined(_STLP_OS2THREADS) || defined(_STLP_USE_PTHREAD_SPINLOCK)) -template +# if defined (_STLP_USE_ATOMIC_SWAP_MUTEX) +#if !defined(__SYMBIAN32__WSD__) +template _STLP_STATIC_MUTEX -_Swap_lock_struct<__dummy>::_S_swap_lock _STLP_MUTEX_INITIALIZER; +_Atomic_swap_struct<__32bits>::_S_swap_lock _STLP_MUTEX_INITIALIZER; +#endif +# undef _STLP_USE_ATOMIC_SWAP_MUTEX # endif -# endif //_STLP_THREADS -# ifndef _STLP_USE_PTHREAD_SPINLOCK +# if defined (_STLP_THREADS) && !defined (_STLP_USE_PTHREAD_SPINLOCK) +//Note: For SYMBIAN Emulator, these entries are to be considered WSD. +//Still, EWSD solution can't be applied since it's templated. template unsigned _STLP_mutex_spin<__inst>::__max = _STLP_mutex_spin<__inst>::__low_max; template unsigned _STLP_mutex_spin<__inst>::__last = 0; + # endif // _STLP_USE_PTHREAD_SPINLOCK -# else /* ( _STLP_STATIC_TEMPLATE_DATA > 0 ) */ +#else /* ( _STLP_STATIC_TEMPLATE_DATA > 0 ) */ -# if defined(_STLP_PTHREADS) || defined(_STLP_UITHREADS) || defined(_STLP_OS2THREADS) -__DECLARE_INSTANCE(_STLP_STATIC_MUTEX, _Swap_lock_struct<0>::_S_swap_lock, +# if defined (_STLP_USE_ATOMIC_SWAP_MUTEX) +__DECLARE_INSTANCE(_STLP_STATIC_MUTEX, _Atomic_swap_struct::_S_swap_lock, _STLP_MUTEX_INITIALIZER ); +# undef _STLP_USE_ATOMIC_SWAP_MUTEX # endif /* _STLP_PTHREADS */ -# ifndef _STLP_USE_PTHREAD_SPINLOCK +# if defined (_STLP_THREADS) && !defined (_STLP_USE_PTHREAD_SPINLOCK) __DECLARE_INSTANCE(unsigned, _STLP_mutex_spin<0>::__max, =30); __DECLARE_INSTANCE(unsigned, _STLP_mutex_spin<0>::__last, =0); # endif // _STLP_USE_PTHREAD_SPINLOCK -# endif /* ( _STLP_STATIC_TEMPLATE_DATA > 0 ) */ +#endif /* ( _STLP_STATIC_TEMPLATE_DATA > 0 ) */ -#ifndef _STLP_USE_PTHREAD_SPINLOCK +#if defined (_STLP_THREADS) && !defined (_STLP_USE_PTHREAD_SPINLOCK) -#ifdef _STLP_SPARC_SOLARIS_THREADS +# if defined (_STLP_SPARC_SOLARIS_THREADS) // underground function in libc.so; we do not want dependance on librt extern "C" int __nanosleep(const struct timespec*, struct timespec*); -# define _STLP_NANOSLEEP __nanosleep -#else -# define _STLP_NANOSLEEP nanosleep -#endif +# define _STLP_NANOSLEEP __nanosleep +# else +# define _STLP_NANOSLEEP nanosleep +# endif template void _STLP_CALL _STLP_mutex_spin<__inst>::_S_nsec_sleep(int __log_nsec) { -# if defined(_STLP_WIN32THREADS) - if (__log_nsec <= 20) { - // Note from boost (www.boost.org): - // Changed to Sleep(1) from Sleep(0). - // According to MSDN, Sleep(0) will never yield - // to a lower-priority thread, whereas Sleep(1) - // will. Performance seems not to be affected. - Sleep(1); - } else { - Sleep(1 << (__log_nsec - 20)); - } -# elif defined(_STLP_OS2THREADS) - if (__log_nsec <= 20) { - DosSleep(0); - } else { - DosSleep(1 << (__log_nsec - 20)); - } -# elif defined (_STLP_UNIX) - timespec __ts; - /* Max sleep is 2**27nsec ~ 60msec */ - __ts.tv_sec = 0; - __ts.tv_nsec = 1 << __log_nsec; - _STLP_NANOSLEEP(&__ts, 0); -# endif +# if defined (_STLP_WIN32THREADS) + if (__log_nsec <= 20) { + // Note from boost (www.boost.org): + // Changed to Sleep(1) from Sleep(0). + // According to MSDN, Sleep(0) will never yield + // to a lower-priority thread, whereas Sleep(1) + // will. Performance seems not to be affected. + Sleep(1); + } else { + Sleep(1 << (__log_nsec - 20)); } - +# elif defined(_STLP_OS2THREADS) + if (__log_nsec <= 20) { + DosSleep(0); + } else { + DosSleep(1 << (__log_nsec - 20)); + } +# elif defined (_STLP_UNIX) + timespec __ts; + /* Max sleep is 2**27nsec ~ 60msec */ + __ts.tv_sec = 0; + __ts.tv_nsec = 1 << __log_nsec; + _STLP_NANOSLEEP(&__ts, 0); +# endif +} template void _STLP_CALL -_STLP_mutex_spin<__inst>::_M_do_lock(volatile __stl_atomic_t* __lock) -{ -#if defined(_STLP_ATOMIC_EXCHANGE) +_STLP_mutex_spin<__inst>::_M_do_lock(volatile __stl_atomic_t* __lock) { +# if defined(_STLP_ATOMIC_EXCHANGE) if (_Atomic_swap(__lock, 1)) { unsigned __my_spin_max = _STLP_mutex_spin<0>::__max; unsigned __my_last_spins = _STLP_mutex_spin<0>::__last; - volatile unsigned __junk = 17; // Value doesn't matter. + volatile unsigned __junk = 17; // Value doesn't matter. unsigned __i; - + for (__i = 0; __i < __my_spin_max; ++__i) { if (__i < __my_last_spins/2 || *__lock) { __junk *= __junk; __junk *= __junk; @@ -139,32 +144,31 @@ // Thus it makes sense to spin longer the next time. _STLP_mutex_spin<0>::__last = __i; _STLP_mutex_spin<0>::__max = _STLP_mutex_spin<0>::__high_max; - return; + return; } } } - + // We are probably being scheduled against the other process. Sleep. _STLP_mutex_spin<0>::__max = _STLP_mutex_spin<0>::__low_max; - + for (__i = 0 ;; ++__i) { int __log_nsec = __i + 6; - + if (__log_nsec > 27) __log_nsec = 27; if (!_Atomic_swap(__lock, 1)) { - break; + break; } _S_nsec_sleep(__log_nsec); } - } /* first _Atomic_swap */ -# endif +# endif } #endif // _STLP_USE_PTHREAD_SPINLOCK _STLP_END_NAMESPACE -# endif /* BUILDING_STLPORT */ +#endif /* _STLP_EXPOSE_GLOBALS_IMPLEMENTATION */ #endif /* _STLP_THREADS_C */ // Local Variables: