forked from mikerabat/mrmath
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMtxThreadPool.pas
111 lines (82 loc) · 2.9 KB
/
MtxThreadPool.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
// ###################################################################
// #### This file is part of the mathematics library project, and is
// #### offered under the licence agreement described on
// #### http://www.mrsoft.org/
// ####
// #### Copyright:(c) 2011, Michael R. . All rights reserved.
// ####
// #### Unless required by applicable law or agreed to in writing, software
// #### distributed under the License is distributed on an "AS IS" BASIS,
// #### WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// #### See the License for the specific language governing permissions and
// #### limitations under the License.
// ###################################################################
// ###################################################################
// #### certain MACOS contributions and testing William Cantrall
// ###################################################################
unit MtxThreadPool;
// #####################################################
// #### Thread pool for async matrix operations stub.
// #### The real implementation is OS dependent!
// #####################################################
interface
uses MatrixConst;
type
TMtxProc = function(obj : TObject) : integer;
type
IMtxAsyncCall = interface
['{B5263EB3-FFDE-4D66-B556-31D5E0D05BAC}']
function GetResult : integer;
procedure ExecuteAsync;
function Sync: Integer;
end;
IMtxAsyncCallGroup = interface
['{11438431-7A6A-4FB9-B67A-58CE23E324DB}']
procedure AddTask(proc : TMtxProc; obj : TObject);
procedure SyncAll;
end;
procedure InitMtxThreadPool;
procedure FinalizeMtxThreadPool;
function MtxInitTaskGroup : IMtxAsyncCallGroup;
var numCPUCores : TASMNativeInt = 0;
numRealCores : TASMNativeInt = 0; // cores without hyperthreading
numCoresForSimpleFuncs : TASMNativeInt = 0; // for median and scaling operations
implementation
// ###########################################
// #### Windows Thread Pooling
// ###########################################
{$IFDEF MSWINDOWS }
{.$DEFINE USE_OS_THREADPOOL}
uses {$IFDEF USE_OS_THREADPOOL}SimpleWinThreadPool{$ELSE} WinThreadPool{$ENDIF};
procedure InitMtxThreadPool;
begin
InitWinMtxThreadPool;
end;
procedure FinalizeMtxThreadPool;
begin
FinalizeWinMtxThreadPool;
end;
function MtxInitTaskGroup : IMtxAsyncCallGroup;
begin
Result := InitWinThreadGroup;
end;
{$ENDIF}
// ###########################################
// #### MACOS Thread pooling
// ###########################################
{$IFDEF MACOS }
uses MacOsThreadPool;
procedure InitMtxThreadPool;
begin
InitMacMtxThreadPool;
end;
procedure FinalizeMtxThreadPool;
begin
FinalizeMacMtxThreadPool;
end;
function MtxInitTaskGroup : IMtxAsyncCallGroup;
begin
Result := InitMacMtxGroup;
end;
{$ENDIF}
end.