-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathbmk_pm_ng.bmx
64 lines (42 loc) · 1.13 KB
/
bmk_pm_ng.bmx
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
SuperStrict
Import BRL.ThreadPool
Import "bmk_ng_utils.bmx"
Type TProcessManager
Field pool:TThreadPoolExecutor
Field cpuCount:Int
Field threads:TList = New TList
Method New()
cpuCount = GetCoreCount()
pool = TThreadPoolExecutor.newFixedThreadPool(Max(1, cpuCount - 1))
End Method
Method CheckTasks()
While pool.getActiveCount() = pool.maxThreads
Delay 5
Wend
End Method
Method WaitForTasks()
While pool.getActiveCount() Or Not pool.IsQueueEmpty()
Delay 5
Wend
End Method
Method DoSystem(cmd:String, src:String, obj:String, supp:String)
CheckTasks()
pool.execute(new TThreadPoolTask.Create(TProcessTask._DoTasks, CreateProcessTask(cmd, src, obj, supp)))
End Method
Method AddTask:Int(func:Object(data:Object), data:Object)
CheckTasks()
pool.execute(new TThreadPoolTask.Create(func, data))
End Method
End Type
Type TThreadPoolTask Extends TRunnable
Field func:Object(data:Object)
Field data:Object
Method Create:TThreadPoolTask(func:Object(data:Object), data:Object)
Self.func = func
Self.data = data
Return self
End Method
Method run()
func(data)
End Method
End Type