26#ifndef _STLP_THREADS_C
27#define _STLP_THREADS_C
29#ifndef _STLP_INTERNAL_THREADS_H
33#if defined (_STLP_EXPOSE_GLOBALS_IMPLEMENTATION)
35#if defined (_STLP_SGI_THREADS)
37#elif defined (_STLP_UNIX)
38# ifndef _STLP_INTERNAL_CTIME
41# if defined (_STLP_USE_NAMESPACES) && !defined (_STLP_VENDOR_GLOBAL_CSTD)
42using _STLP_VENDOR_CSTD::time_t;
49#if defined (_STLP_USE_ATOMIC_SWAP_MUTEX)
53# undef _STLP_USE_ATOMIC_SWAP_MUTEX
56#if defined (_STLP_THREADS) && !defined (_STLP_USE_PTHREAD_SPINLOCK)
58unsigned _STLP_mutex_spin<__inst>::__max = _STLP_mutex_spin<__inst>::__low_max;
61unsigned _STLP_mutex_spin<__inst>::__last = 0;
64#if defined (_STLP_THREADS) && !defined (_STLP_USE_PTHREAD_SPINLOCK)
66# if defined (_STLP_SPARC_SOLARIS_THREADS)
69# define _STLP_NANOSLEEP __nanosleep
71# define _STLP_NANOSLEEP nanosleep
76_STLP_mutex_spin<__inst>::_S_nsec_sleep(
int __log_nsec,
unsigned int& __iteration) {
77# if defined (_STLP_WIN32THREADS)
78# if defined (_WIN32_WINNT) && (_WIN32_WINNT >= 0x0400)
79 if (__iteration <= 4000) {
88 if (__log_nsec <= 21) {
95 Sleep(1 << (__log_nsec - 20));
97# if defined (_WIN32_WINNT) && (_WIN32_WINNT >= 0x0400)
101# elif defined(_STLP_OS2THREADS)
102 if (__log_nsec <= 20) {
105 DosSleep(1 << (__log_nsec - 20));
107# elif defined (_STLP_UNIX)
111 __ts.
tv_nsec = 1 << __log_nsec;
112 _STLP_NANOSLEEP(&__ts, 0);
118_STLP_mutex_spin<__inst>::_M_do_lock(
volatile __stl_atomic_t* __lock) {
119# if defined(_STLP_ATOMIC_EXCHANGE)
121 unsigned __my_spin_max = _STLP_mutex_spin<0>::__max;
122 unsigned __my_last_spins = _STLP_mutex_spin<0>::__last;
123 volatile unsigned __junk = 17;
126 for (__i = 0; __i < __my_spin_max; ++__i) {
127 if (__i < __my_last_spins/2 || *__lock) {
128 __junk *= __junk; __junk *= __junk;
129 __junk *= __junk; __junk *= __junk;
136 _STLP_mutex_spin<0>::__last = __i;
137 _STLP_mutex_spin<0>::__max = _STLP_mutex_spin<0>::__high_max;
144 _STLP_mutex_spin<0>::__max = _STLP_mutex_spin<0>::__low_max;
146 for (__i = 0 ;; ++__i) {
147 int __log_nsec = __i + 6;
149 if (__log_nsec > 27) __log_nsec = 27;
153 _S_nsec_sleep(__log_nsec, __i);
#define _STLP_MUTEX_INITIALIZER
__stl_atomic_t _STLP_CALL _Atomic_swap(_STLP_VOLATILE __stl_atomic_t *__p, __stl_atomic_t __q)
#define _STLP_STATIC_MUTEX
#define _STLP_BEGIN_NAMESPACE
#define _STLP_END_NAMESPACE
VOID WINAPI DECLSPEC_HOTPATCH Sleep(IN DWORD dwMilliseconds)
BOOL WINAPI SwitchToThread(void)