8#ifndef INCLUDED_BSLMT_THREADUTILIMPL_WIN32
9#define INCLUDED_BSLMT_THREADUTILIMPL_WIN32
86#include <bslscm_version.h>
90#ifdef BSLMT_PLATFORM_WIN32_THREADS
102#include <bsl_string.h>
104typedef unsigned long DWORD;
110 __declspec(dllimport)
void __stdcall Sleep(
114 __declspec(dllimport) DWORD __stdcall SleepEx(
115 DWORD dwMilliseconds,
119 __declspec(dllimport) DWORD __stdcall GetCurrentThreadId(
123 __declspec(dllimport) HANDLE __stdcall GetCurrentThread(
127 __declspec(dllimport)
void* __stdcall TlsGetValue(
131 __declspec(dllimport) BOOL __stdcall TlsSetValue(
145 typedef void *(*bslmt_ThreadFunction)(
void *);
156template <
class THREAD_POLICY>
157struct ThreadUtilImpl;
166struct ThreadUtilImpl<Platform::Win32Threads> {
181 typedef HANDLE NativeHandle;
191 static const Handle INVALID_HANDLE;
203 static int create(Handle *thread,
204 const ThreadAttributes& attribute,
218 static int create(Handle *thread,
228 static int getMinSchedulingPriority(
237 static int getMaxSchedulingPriority(
243 static void getThreadName(
bsl::string *threadName);
251 static int join(Handle& thread,
void **status = 0);
274 static void microSleep(
int microseconds,
int seconds = 0);
295 static void exit(
void *status);
301 static Handle self();
308 static int detach(Handle& threadHandle);
314 static NativeHandle nativeHandle(
const Handle& threadHandle);
318 static bool areEqual(
const Handle& a,
const Handle& b);
344 static Id handleToId(
const Handle& threadHandle);
360 static int idAsInt(
const Id& threadId);
364 static bool areEqualId(
const Id& a,
const Id& b);
376 static int deleteKey(Key& key);
382 static void *getSpecific(
const Key& key);
386 static int setSpecific(
const Key& key,
const void *value);
390 static unsigned int hardwareConcurrency();
397bool operator==(
const ThreadUtilImpl<Platform::Win32Threads>::Handle& lhs,
398 const ThreadUtilImpl<Platform::Win32Threads>::Handle& rhs);
402bool operator!=(
const ThreadUtilImpl<Platform::Win32Threads>::Handle& lhs,
403 const ThreadUtilImpl<Platform::Win32Threads>::Handle& rhs);
416int ThreadUtilImpl<bslmt::Platform::Win32Threads>::
423int ThreadUtilImpl<bslmt::Platform::Win32Threads>::
430void ThreadUtilImpl<bslmt::Platform::Win32Threads>::yield()
436void ThreadUtilImpl<bslmt::Platform::Win32Threads>::sleep(
443 ::Sleep(milliSeconds);
447void ThreadUtilImpl<bslmt::Platform::Win32Threads>::microSleep(
451 enum { k_MILLION = 1000 * 1000 };
454 (microsecs % k_MILLION) * 1000);
458 ::Sleep(milliSeconds);
462ThreadUtilImpl<bslmt::Platform::Win32Threads>::Handle
463ThreadUtilImpl<bslmt::Platform::Win32Threads>::self()
466 h.d_id = GetCurrentThreadId();
467 h.d_handle = GetCurrentThread();
472ThreadUtilImpl<bslmt::Platform::Win32Threads>::NativeHandle
473ThreadUtilImpl<bslmt::Platform::Win32Threads>::nativeHandle(
474 const Handle& handle)
476 return handle.d_handle;
480ThreadUtilImpl<bslmt::Platform::Win32Threads>::Id
481ThreadUtilImpl<bslmt::Platform::Win32Threads>::selfId()
483 return GetCurrentThreadId();
488ThreadUtilImpl<bslmt::Platform::Win32Threads>::selfIdAsInt()
490 return idAsInt(selfId());
495ThreadUtilImpl<bslmt::Platform::Win32Threads>::selfIdAsUint64()
497 return idAsUint64(selfId());
501ThreadUtilImpl<bslmt::Platform::Win32Threads>::Id
502ThreadUtilImpl<bslmt::Platform::Win32Threads>::handleToId(
503 const Handle& threadHandle)
505 return threadHandle.d_id;
510ThreadUtilImpl<bslmt::Platform::Win32Threads>::idAsUint64(
517int ThreadUtilImpl<bslmt::Platform::Win32Threads>::idAsInt(
520 return static_cast<int>(threadId);
524bool ThreadUtilImpl<bslmt::Platform::Win32Threads>::areEqualId(
532void *ThreadUtilImpl<bslmt::Platform::Win32Threads>::getSpecific(
535 return TlsGetValue(key);
539int ThreadUtilImpl<bslmt::Platform::Win32Threads>::setSpecific(
543 return 0 == TlsSetValue(key, (
void*)value) ? 1 : 0;
566 return !(lhs == rhs);
Definition bslstl_string.h:1281
SchedulingPolicy
Definition bslmt_threadattributes.h:376
@ e_UNSET_PRIORITY
Definition bslmt_threadattributes.h:406
Definition bsls_timeinterval.h:301
Definition bslstl_stringref.h:372
void(* bslmt_KeyDestructorFunction)(void *)
Definition bslmt_threadutil.h:361
void *(* bslmt_ThreadFunction)(void *)
Definition bslmt_threadutil.h:355
#define BSLS_IDENT(str)
Definition bsls_ident.h:195
bool operator!=(const FileCleanerConfiguration &lhs, const FileCleanerConfiguration &rhs)
bool operator==(const FileCleanerConfiguration &lhs, const FileCleanerConfiguration &rhs)
Definition bslmt_barrier.h:344
bool operator==(const ThreadAttributes &lhs, const ThreadAttributes &rhs)
bool operator!=(const ThreadAttributes &lhs, const ThreadAttributes &rhs)
static void toMillisec(unsigned int *dst, const bsls::TimeInterval &src)
Definition bslmt_entrypointfunctoradapter.h:221
Enum
Definition bsls_systemclocktype.h:117
@ e_REALTIME
Definition bsls_systemclocktype.h:120
unsigned long long Uint64
Definition bsls_types.h:137