Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
M
Magisk
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
Magisk
Commits
41c07211
Commit
41c07211
authored
Jul 27, 2018
by
topjohnwu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use internal thread pool for update repos
parent
413d4bad
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
13 additions
and
32 deletions
+13
-32
UpdateRepos.java
...rc/full/java/com/topjohnwu/magisk/asyncs/UpdateRepos.java
+13
-32
No files found.
app/src/full/java/com/topjohnwu/magisk/asyncs/UpdateRepos.java
View file @
41c07211
package
com
.
topjohnwu
.
magisk
.
asyncs
;
import
android.database.Cursor
;
import
android.os.AsyncTask
;
import
android.text.TextUtils
;
import
com.topjohnwu.magisk.MagiskManager
;
...
...
@@ -29,7 +28,9 @@ import java.util.List;
import
java.util.Locale
;
import
java.util.Map
;
import
java.util.Set
;
import
java.util.concurrent.atomic.AtomicInteger
;
import
java.util.concurrent.ExecutorService
;
import
java.util.concurrent.Executors
;
import
java.util.concurrent.TimeUnit
;
public
class
UpdateRepos
extends
ParallelTask
<
Void
,
Void
,
Void
>
{
...
...
@@ -37,47 +38,27 @@ public class UpdateRepos extends ParallelTask<Void, Void, Void> {
private
static
final
int
LOAD_NEXT
=
1
;
private
static
final
int
LOAD_PREV
=
2
;
private
static
final
DateFormat
dateFormat
=
new
SimpleDateFormat
(
"yyyy-MM-dd'T'HH:mm:ss'Z'"
,
Locale
.
US
);
private
static
final
int
CPU_COUNT
=
Runtime
.
getRuntime
().
availableProcessors
();
private
static
final
int
CORE_POOL_SIZE
=
Math
.
max
(
2
,
CPU_COUNT
-
1
);
private
MagiskManager
mm
;
private
List
<
String
>
etags
,
newEtags
=
new
LinkedList
<>();
private
Set
<
String
>
cached
;
private
boolean
forceUpdate
;
private
AtomicInteger
taskCount
=
new
AtomicInteger
(
0
);
final
private
Object
allDone
=
new
Object
();
private
ExecutorService
threadPool
;
public
UpdateRepos
(
boolean
force
)
{
mm
=
MagiskManager
.
get
();
mm
.
repoLoadDone
.
reset
();
forceUpdate
=
force
;
}
private
void
queueTask
(
Runnable
task
)
{
// Thread pool's queue has an upper bound, batch it with 64 tasks
while
(
taskCount
.
get
()
>=
64
)
{
waitTasks
();
}
taskCount
.
incrementAndGet
();
AsyncTask
.
THREAD_POOL_EXECUTOR
.
execute
(()
->
{
task
.
run
();
if
(
taskCount
.
decrementAndGet
()
==
0
)
{
synchronized
(
allDone
)
{
allDone
.
notify
();
}
}
});
threadPool
=
Executors
.
newFixedThreadPool
(
CORE_POOL_SIZE
);
}
private
void
waitTasks
()
{
if
(
taskCount
.
get
()
==
0
)
return
;
synchronized
(
allDone
)
{
threadPool
.
shutdown
();
try
{
allDone
.
wait
();
}
catch
(
InterruptedException
e
)
{
// Wait again
waitTasks
();
}
}
threadPool
.
awaitTermination
(
Long
.
MAX_VALUE
,
TimeUnit
.
MILLISECONDS
);
}
catch
(
InterruptedException
ignored
)
{}
}
private
boolean
loadJSON
(
String
jsonString
)
throws
JSONException
,
ParseException
{
...
...
@@ -93,7 +74,7 @@ public class UpdateRepos extends ParallelTask<Void, Void, Void> {
String
name
=
rawRepo
.
getString
(
"name"
);
Date
date
=
dateFormat
.
parse
(
rawRepo
.
getString
(
"pushed_at"
));
Set
<
String
>
set
=
Collections
.
synchronizedSet
(
cached
);
queueTask
(()
->
{
threadPool
.
execute
(()
->
{
Repo
repo
=
mm
.
repoDB
.
getRepo
(
id
);
try
{
if
(
repo
==
null
)
...
...
@@ -187,7 +168,7 @@ public class UpdateRepos extends ParallelTask<Void, Void, Void> {
Cursor
c
=
mm
.
repoDB
.
getRawCursor
();
while
(
c
.
moveToNext
())
{
Repo
repo
=
new
Repo
(
c
);
queueTask
(()
->
{
threadPool
.
execute
(()
->
{
try
{
repo
.
update
();
mm
.
repoDB
.
addRepo
(
repo
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment