Stop using thread pools

This commit is contained in:
Mygod
2021-11-26 23:05:25 -05:00
parent de3226e27a
commit 1cf961b23c
4 changed files with 5 additions and 10 deletions

View File

@@ -404,7 +404,7 @@ class RootServer {
mainInitialized.await() mainInitialized.await()
CoroutineScope(Dispatchers.Main.immediate + job) CoroutineScope(Dispatchers.Main.immediate + job)
} }
val callbackWorker = newSingleThreadContext("callbackWorker") val callbackWorker = Dispatchers.IO.limitedParallelism(1)
// access to cancellables shall be wrapped in defaultWorker // access to cancellables shall be wrapped in defaultWorker
val cancellables = LongSparseArray<() -> Unit>() val cancellables = LongSparseArray<() -> Unit>()

View File

@@ -59,7 +59,7 @@ class LocalOnlyHotspotService : IpNeighbourMonitoringService(), CoroutineScope {
/** /**
* Writes and critical reads to routingManager should be protected with this context. * Writes and critical reads to routingManager should be protected with this context.
*/ */
private val dispatcher = newSingleThreadContext("LocalOnlyHotspotService") private val dispatcher = Dispatchers.IO.limitedParallelism(1)
override val coroutineContext = dispatcher + Job() override val coroutineContext = dispatcher + Job()
private var routingManager: RoutingManager? = null private var routingManager: RoutingManager? = null
private var timeoutMonitor: TetherTimeoutMonitor? = null private var timeoutMonitor: TetherTimeoutMonitor? = null
@@ -167,10 +167,7 @@ class LocalOnlyHotspotService : IpNeighbourMonitoringService(), CoroutineScope {
launch { launch {
routingManager?.stop() routingManager?.stop()
routingManager = null routingManager = null
if (exit) { if (exit) cancel()
cancel()
dispatcher.close()
}
} }
} }
} }

View File

@@ -241,7 +241,7 @@ class RepeaterService : Service(), CoroutineScope, WifiP2pManager.ChannelListene
/** /**
* Writes and critical reads to routingManager should be protected with this context. * Writes and critical reads to routingManager should be protected with this context.
*/ */
private val dispatcher = newSingleThreadContext("RepeaterService") private val dispatcher = Dispatchers.IO.limitedParallelism(1)
override val coroutineContext = dispatcher + Job() override val coroutineContext = dispatcher + Job()
private var routingManager: RoutingManager? = null private var routingManager: RoutingManager? = null
private var persistNextGroup = false private var persistNextGroup = false
@@ -529,7 +529,6 @@ class RepeaterService : Service(), CoroutineScope, WifiP2pManager.ChannelListene
launch { // force clean to prevent leakage launch { // force clean to prevent leakage
cleanLocked() cleanLocked()
cancel() cancel()
dispatcher.close()
} }
app.pref.unregisterOnSharedPreferenceChangeListener(this) app.pref.unregisterOnSharedPreferenceChangeListener(this)
if (Build.VERSION.SDK_INT < 29) unregisterReceiver(deviceListener) if (Build.VERSION.SDK_INT < 29) unregisterReceiver(deviceListener)

View File

@@ -55,7 +55,7 @@ class TetheringService : IpNeighbourMonitoringService(), TetheringManager.Tether
/** /**
* Writes and critical reads to downstreams should be protected with this context. * Writes and critical reads to downstreams should be protected with this context.
*/ */
private val dispatcher = newSingleThreadContext("TetheringService") private val dispatcher = Dispatchers.IO.limitedParallelism(1)
override val coroutineContext = dispatcher + Job() override val coroutineContext = dispatcher + Job()
private val binder = Binder() private val binder = Binder()
private val downstreams = ConcurrentHashMap<String, Downstream>() private val downstreams = ConcurrentHashMap<String, Downstream>()
@@ -144,7 +144,6 @@ class TetheringService : IpNeighbourMonitoringService(), TetheringManager.Tether
unregisterReceiver() unregisterReceiver()
downstreams.values.forEach { it.stop() } // force clean to prevent leakage downstreams.values.forEach { it.stop() } // force clean to prevent leakage
cancel() cancel()
dispatcher.close()
} }
super.onDestroy() super.onDestroy()
} }