FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
MadeLineProtoForHost/src/Pool.php at master · frankenstein-dr/MadeLineProtoForHost · GitHub
frankenstein-dr
/
MadeLineProtoForHost
Public
forked from
wecanco/MadeLineProtoForHost
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
MadeLineProtoForHost
/
src
/
Pool.php
Copy path
More file actions
More file actions
Latest commit
History
History
History
69 lines (59 loc) · 1.8 KB
Breadcrumbs
MadeLineProtoForHost
/
src
/
Pool.php
Copy path
File metadata and controls
69 lines (59 loc) · 1.8 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
<?php
if
(!
extension_loaded
(
'
pthreads
'
)) {
class
Pool
{
public
function
__construct
(
$
size
,
$
class
= \Worker::class,
$
ctor
= [])
{
$
this
->
size
=
$
size
;
$
this
->
clazz
=
$
class
;
$
this
->
ctor
=
$
ctor
;
}
public
function
submit
(
Threaded
$
collectable
)
{
if
(
$
this
->
last
>
$
this
->
size
) {
$
this
->
last
=
0
;
}
if
(!
isset
(
$
this
->
workers
[
$
this
->
last
])) {
$
this
->
workers
[
$
this
->
last
] =
new
$
this
->
clazz
(...
$
this
->
ctor
);
$
this
->
workers
[
$
this
->
last
]->
start
();
}
$
this
->
workers
[
$
this
->
last
++]->
stack
(
$
collectable
);
}
public
function
submitTo
(
$
worker
,
Threaded
$
collectable
)
{
if
(
isset
(
$
this
->
workers
[
$
worker
])) {
$
this
->
workers
[
$
worker
]->
stack
(
$
collectable
);
}
}
public
function
collect
(
Closure
$
collector
=
null
)
{
$
total
=
0
;
foreach
(
$
this
->
workers
as
$
worker
) {
$
total
+=
$
worker
->
collect
(
$
collector
);
}
return
$
total
;
}
public
function
resize
(
$
size
)
{
if
(
$
size
<
$
this
->
size
) {
while
(
$
this
->
size
>
$
size
) {
if
(
isset
(
$
this
->
workers
[
$
this
->
size
-
1
])) {
$
this
->
workers
[
$
this
->
size
-
1
]->
shutdown
();
}
unset(
$
this
->
workers
[
$
this
->
size
-
1
]);
$
this
->
size
--;
}
}
}
public
function
shutdown
()
{
$
this
->
workers
=
null
;
}
protected
$
workers
;
protected
$
size
;
protected
$
last
;
protected
$
clazz
;
protected
$
ctor
;
}
}
Back
|
FazBrowse Home
|
New Git URL