// ==++== // // Copyright (c) Microsoft Corporation. All rights reserved. // // ==--== // =+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+ // // Platform.h : abstracts the underlying platform APIs // // =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- #pragma once // Windows headers that we need #include #include #include #include #undef Yield // The windows headers #define Yield, a name we want to use #include #include #include namespace Concurrency { namespace details { namespace platform { /****************** Events ***************************/ /// /// Creates an auto reset event /// HANDLE __CreateAutoResetEvent(bool initialSet = false); /// /// Creates a manual reset event /// HANDLE __CreateManualResetEvent(bool initialSet = false); /************** Tickcount ***************************/ /// /// Gets the current tick count /// ULONGLONG __GetTickCount64(); /************** Windows critical section ***************************/ /// /// Initializes the critical section /// BOOL __InitializeCriticalSectionEx(CRITICAL_SECTION * cs, DWORD spinCount); /************** Thread Local Storage *****************************/ /// /// Allocates a TLS slot /// DWORD __TlsAlloc(); /// /// Frees a TLS slot /// void __TlsFree(DWORD index); /// /// Gets the value stored in the specified TLS slot /// PVOID __TlsGetValue(DWORD index); /// /// Stores a value in the specified TLS slot /// void __TlsSetValue(DWORD index, PVOID value); /************** Thread Priority ***************************/ /// /// Sets the thread priority /// void __SetThreadPriority(HANDLE hThread, int priority); /// /// Retrieves the thread priority /// int __GetThreadPriority(HANDLE hThread); /************** Thread Affinity ***************************/ /// /// Retrieves the thread group affinity /// BOOL __GetThreadGroupAffinity(HANDLE hThread, PGROUP_AFFINITY affinity); /// /// Sets the thread group affinity /// BOOL __SetThreadGroupAffinity(HANDLE hThread, const GROUP_AFFINITY * affinity); /************** Thread yield ***************************/ /// /// Yield execution to another ready thread /// void __SwitchToThread(); /// /// Yield execution to another ready thread (ms is assumed to be 0 or 1) /// void __Sleep(DWORD ms); /************ Thread *********************************************/ /// /// Creates a thread /// HANDLE __CreateThread(LPSECURITY_ATTRIBUTES lpAttributes, size_t stackSize, LPTHREAD_START_ROUTINE startAddress, LPVOID param, DWORD flags, LPDWORD threadId); /// /// Releases the thread handle /// void __CloseThreadHandle(HANDLE hThread); /// /// Waits for the thread to exit /// DWORD __WaitForThread(HANDLE hThread, DWORD timeout); /// /// Signals hSignal object and waits for hWait. Returns the reason for returning from wait /// DWORD __SignalObjectAndWait(HANDLE hSignal, HANDLE hWait, DWORD ms, BOOL alertable); /************ Timer *********************************************/ /// /// Creates a timer /// BOOL __CreateTimerQueueTimer( PHANDLE phNewTimer, HANDLE timerQueue, WAITORTIMERCALLBACK lpStartAddress, PVOID lpParameter, DWORD dueTime, DWORD period, ULONG flags ); /// /// Deletes the timer /// void __DeleteTimerQueueTimer(HANDLE timerQueue, HANDLE hTimer, HANDLE completionEvent); /// /// Changes the due time of the timer. /// BOOL __ChangeTimerQueueTimer(HANDLE timerQueue, HANDLE hTimer, ULONG dueTime, ULONG period); /************** RegisterWaitForsingleObject ***********/ /// /// Registers a waiter for the given handle. The callback is invoked when the handle is signalled /// HANDLE __RegisterWaitForSingleObject(HANDLE hEvent, WAITORTIMERCALLBACK callback, PVOID context); /// /// Removes the waiter for the given handle. Pending callbacks are cancelled. If a callback is /// already running then this will NOT wait for the callback to complete. /// void __UnregisterWait(HANDLE hWait); /************** System Info ***************************/ /// /// Retrieves the information about the relationships of logical processors and related hardware /// PSYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX __GetLogicalProcessorInformationEx(LOGICAL_PROCESSOR_RELATIONSHIP relation, PDWORD retLength); /// /// Retrieves the information about logical processors and related hardware /// /// Retrieves the processor group and number of the logical processor where the thread is running /// void __GetCurrentProcessorNumberEx(PPROCESSOR_NUMBER procNum); /// /// Returns the highest numa node number /// ULONG __GetNumaHighestNodeNumber(); /// /// Returns current thread ID /// #if defined(_CRTBLD) && !defined(CRTDLL2) _CONCRTIMP #endif long __cdecl GetCurrentThreadId(); }}} // namespace Concurrency::details::platform