STLdoc
STLdocumentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
concrtrm.h
Go to the documentation of this file.
1 /***
2 * ==++==
3 *
4 * Copyright (c) Microsoft Corporation. All rights reserved.
5 *
6 * ==--==
7 * =+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
8 *
9 * concrtrm.h
10 *
11 * Main public header file for ConcRT's Resource Manager. This is the only header file a client
12 * must include to build atop the resource manager.
13 *
14 * The core runtime, the Agents and Message Blocks Library, and the Parallel Patterns Library (PPL)
15 * are defined in different header files.
16 * =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
17 ****/
18 
19 #pragma once
20 
21 #include <crtdefs.h>
22 
23 #if !(defined (_M_X64) || defined (_M_IX86) || defined (_M_ARM) || defined (_M_ARM64))
24  #error ERROR: Concurrency Runtime is supported only on X64, X86, ARM, and ARM64 architectures.
25 #endif /* !(defined (_M_X64) || defined (_M_IX86) || defined (_M_ARM) || defined (_M_ARM64)) */
26 
27 #if defined (_M_CEE)
28  #error ERROR: Concurrency Runtime is not supported when compiling /clr.
29 #endif /* defined (_M_CEE) */
30 
31 #ifndef __cplusplus
32  #error ERROR: Concurrency Runtime is supported only for C++.
33 #endif /* __cplusplus */
34 
35 #pragma pack(push,_CRT_PACKING)
36 
41 
42 namespace Concurrency
43 {
44 #ifdef _CRT_USE_WINAPI_FAMILY_DESKTOP_APP
45  //
46  // Forward Declarations:
47  //
48  struct IScheduler;
49  struct IThreadProxy;
50  class SchedulerPolicy;
51 
62 
63  enum SwitchingProxyState
64  {
69 
70  Idle,
71 
76 
77  Blocking,
78 
83 
84  Nesting
85  };
86 
92 
93  struct DispatchState
94  {
98 
99  DispatchState() : m_dispatchStateSize(sizeof(DispatchState)), m_fIsPreviousContextAsynchronouslyBlocked(0), m_reserved(0)
100  {
101  }
102 
106 
107  unsigned long m_dispatchStateSize;
108 
114 
115  unsigned int m_fIsPreviousContextAsynchronouslyBlocked : 1;
116 
121 
122  unsigned int m_reserved : 31;
123  };
124 
135 
136  struct IExecutionContext
137  {
151 
152  virtual unsigned int GetId() const =0;
153 
164 
165  virtual IScheduler * GetScheduler() =0;
166 
180 
181  virtual IThreadProxy * GetProxy() =0;
182 
196 
197  virtual void SetProxy(_Inout_ IThreadProxy * pThreadProxy) =0;
198 
207 
208  virtual void Dispatch(_Inout_ DispatchState * pDispatchState) =0;
209  };
210 
222 
223  struct IThreadProxy
224  {
231 
232  virtual unsigned int GetId() const =0;
233 
278 
279  virtual void SwitchTo(_Inout_ IExecutionContext * pContext, SwitchingProxyState switchState) =0;
280 
324 
325  virtual void SwitchOut(SwitchingProxyState switchState = Blocking) =0;
326 
339 
340  virtual void YieldToSystem() = 0;
341  };
342 
347 
348  enum CriticalRegionType
349  {
353 
354  OutsideCriticalRegion,
355 
361 
362  InsideCriticalRegion,
363 
370 
371  InsideHyperCriticalRegion
372  };
373 
381 
382  struct IUMSThreadProxy : public IThreadProxy
383  {
393 
394  virtual int EnterCriticalRegion() =0;
395 
403 
404  virtual int ExitCriticalRegion() =0;
405 
419 
420  virtual int EnterHyperCriticalRegion() =0;
421 
429 
430  virtual int ExitHyperCriticalRegion() =0;
431 
440 
441  virtual CriticalRegionType GetCriticalRegionType() const =0;
442  };
443 
459 
460  struct IExecutionResource
461  {
475 
476  virtual unsigned int GetNodeId() const =0;
477 
488 
489  virtual unsigned int GetExecutionResourceId() const =0;
490 
518 
519  virtual void Remove(_Inout_ IScheduler * pScheduler) =0;
520 
546 
547  virtual unsigned int CurrentSubscriptionLevel() const =0;
548  };
549 
560 
561  struct IVirtualProcessorRoot : public IExecutionResource
562  {
569 
570  virtual unsigned int GetId() const =0;
571 
601 
602  virtual void Activate(_Inout_ IExecutionContext * pContext) =0;
603 
642 
643  virtual bool Deactivate(_Inout_ IExecutionContext * pContext) =0;
644 
667 
668  virtual void EnsureAllTasksVisible(_Inout_ IExecutionContext *pContext) =0;
669  };
670 
687 
688  struct IScheduler
689  {
702 
703  virtual unsigned int GetId() const =0;
704 
732 
733  virtual void Statistics(_Out_ unsigned int * pTaskCompletionRate, _Out_ unsigned int * pTaskArrivalRate, _Out_ unsigned int * pNumberOfTasksEnqueued) =0;
734 
743 
744  virtual SchedulerPolicy GetPolicy() const =0;
745 
763 
764  virtual void AddVirtualProcessors(_In_reads_(count) IVirtualProcessorRoot ** ppVirtualProcessorRoots, unsigned int count) =0;
765 
788 
789  virtual void RemoveVirtualProcessors(_In_reads_(count) IVirtualProcessorRoot ** ppVirtualProcessorRoots, unsigned int count) =0;
790 
818 
819  virtual void NotifyResourcesExternallyIdle(_In_reads_(count) IVirtualProcessorRoot ** ppVirtualProcessorRoots, unsigned int count) =0;
820 
848 
849  virtual void NotifyResourcesExternallyBusy(_In_reads_(count) IVirtualProcessorRoot ** ppVirtualProcessorRoots, unsigned int count) =0;
850  };
851 
859 
860  struct IUMSUnblockNotification
861  {
870 
871  virtual IExecutionContext* GetContext() =0;
872 
880 
881  virtual IUMSUnblockNotification* GetNextUnblockNotification() =0;
882  };
883 
898 
899  struct IUMSCompletionList
900  {
912 
913  virtual IUMSUnblockNotification *GetUnblockNotifications() =0;
914  };
915 
938 
939  struct IUMSScheduler : public IScheduler
940  {
954 
955  virtual void SetCompletionList(_Inout_ IUMSCompletionList * pCompletionList) =0;
956  };
957 
969 
970  struct ISchedulerProxy
971  {
1004 
1005  virtual IExecutionResource * RequestInitialVirtualProcessors(bool doSubscribeCurrentThread) =0;
1006 
1024 
1025  virtual void Shutdown() =0;
1026 
1042 
1043  virtual void BindContext(_Inout_ IExecutionContext * pContext) =0;
1044 
1054 
1055  virtual void UnbindContext(_Inout_ IExecutionContext * pContext) =0;
1056 
1075 
1076  virtual IExecutionResource * SubscribeCurrentThread() =0;
1077 
1094 
1095  virtual IVirtualProcessorRoot * CreateOversubscriber(_Inout_ IExecutionResource * pExecutionResource) =0;
1096  };
1097 
1104 
1105  struct ITopologyExecutionResource
1106  {
1116 
1117  virtual ITopologyExecutionResource *GetNext() const =0;
1118 
1125 
1126  virtual unsigned int GetId() const =0;
1127  };
1128 
1135 
1136  struct ITopologyNode
1137  {
1147 
1148  virtual ITopologyNode *GetNext() const =0;
1149 
1163 
1164  virtual unsigned int GetId() const =0;
1165 
1176 
1177  virtual unsigned long GetNumaNode() const =0;
1178 
1186 
1187  virtual unsigned int GetExecutionResourceCount() const =0;
1188 
1196 
1197  virtual ITopologyExecutionResource *GetFirstExecutionResource() const =0;
1198 
1199  };
1200 
1204 
1205  const unsigned int CONCRT_RM_VERSION_1 = 0x00010000;
1206 
1219 
1220  struct IResourceManager
1221  {
1229 
1230  virtual unsigned int Reference() =0;
1231 
1240 
1241  virtual unsigned int Release() =0;
1242 
1273 
1274  virtual ISchedulerProxy *RegisterScheduler(_Inout_ IScheduler * pScheduler, unsigned int version) =0;
1275 
1282 
1283  virtual unsigned int GetAvailableNodeCount() const =0;
1284 
1292 
1293  virtual ITopologyNode* GetFirstNode() const =0;
1294 
1317 
1318  virtual void CreateNodeTopology(unsigned int nodeCount, _In_reads_(nodeCount) unsigned int * pCoreCount, _In_reads_opt_(nodeCount) unsigned int ** pNodeDistance, _In_reads_(nodeCount) unsigned int * pProcessorGroups) =0;
1319 
1323 
1324  enum OSVersion
1325  {
1330 
1331  UnsupportedOS,
1332 
1336 
1337  XP,
1338 
1342 
1343  Win2k3,
1344 
1348 
1349  Vista,
1350 
1354 
1355  Win7OrLater,
1356 
1361 
1362  UmsThreadAwareOS,
1363 
1367 
1368  Win8OrLater
1369  };
1370  };
1371 
1386 
1387  _CONCRTIMP IResourceManager* __cdecl CreateResourceManager();
1388 
1399 
1400  _CONCRTIMP IResourceManager::OSVersion __cdecl GetOSVersion();
1401 
1412 
1413  _CONCRTIMP unsigned int __cdecl GetSchedulerId();
1414 
1425 
1426  _CONCRTIMP unsigned int __cdecl GetExecutionContextId();
1427 
1438 
1439  _CONCRTIMP unsigned int __cdecl GetProcessorCount();
1440 
1452 
1453  _CONCRTIMP unsigned int __cdecl GetProcessorNodeCount();
1454 #endif /* _CRT_USE_WINAPI_FAMILY_DESKTOP_APP */
1455 }
1456 
1457 namespace concurrency = ::Concurrency;
1458 
1459 #pragma pack(pop)
#define _Out_
Definition: sal.h:342
The Concurrency namespace provides classes and functions that provide access to the Concurrency Runti...
Definition: agents.h:43
_Iter_diff_t< _InIt > count(_InIt _First, _InIt _Last, const _Ty &_Val)
Definition: xutility:3318
#define _In_reads_opt_(size)
Definition: sal.h:317
#define _CONCRTIMP
Definition: crtdefs.h:48
#define _In_reads_(size)
Definition: sal.h:316
#define _Inout_
Definition: sal.h:375