aboutsummaryrefslogtreecommitdiff
path: root/src/client/bridge
diff options
context:
space:
mode:
authorZeyla Hellyer <[email protected]>2017-10-09 11:30:56 -0700
committerZeyla Hellyer <[email protected]>2017-10-09 11:30:56 -0700
commit8109619184867fc843a1e73d18d37726a34f7fbf (patch)
tree68ad2b22c2e650bc01b62e4208e21bbcc38014fb /src/client/bridge
parentAdd a threadpool to the shard runner (diff)
downloadserenity-8109619184867fc843a1e73d18d37726a34f7fbf.tar.xz
serenity-8109619184867fc843a1e73d18d37726a34f7fbf.zip
Make the client threadpool user-customizable
In addition to making the threadpool used by client shards customizable by the user, make only a single threadpool (as opposed to one per shard) and share it across all shards.
Diffstat (limited to 'src/client/bridge')
-rw-r--r--src/client/bridge/gateway/shard_manager.rs5
-rw-r--r--src/client/bridge/gateway/shard_queuer.rs4
-rw-r--r--src/client/bridge/gateway/shard_runner.rs32
3 files changed, 26 insertions, 15 deletions
diff --git a/src/client/bridge/gateway/shard_manager.rs b/src/client/bridge/gateway/shard_manager.rs
index 5dbe0c3..2068bef 100644
--- a/src/client/bridge/gateway/shard_manager.rs
+++ b/src/client/bridge/gateway/shard_manager.rs
@@ -12,6 +12,7 @@ use super::{
ShardQueuerMessage,
ShardRunnerInfo,
};
+use threadpool::ThreadPool;
use typemap::ShareMap;
#[cfg(feature = "framework")]
@@ -40,6 +41,7 @@ impl ShardManager {
data: Arc<ParkingLotMutex<ShareMap>>,
event_handler: Arc<H>,
framework: Arc<Mutex<Option<Box<Framework + Send>>>>,
+ threadpool: ThreadPool,
) -> Self where H: EventHandler + Send + Sync + 'static {
let (thread_tx, thread_rx) = mpsc::channel();
let (shard_queue_tx, shard_queue_rx) = mpsc::channel();
@@ -56,6 +58,7 @@ impl ShardManager {
rx: shard_queue_rx,
token: token.clone(),
ws_url: ws_url.clone(),
+ threadpool,
};
thread::spawn(move || {
@@ -81,6 +84,7 @@ impl ShardManager {
token: Arc<Mutex<String>>,
data: Arc<ParkingLotMutex<ShareMap>>,
event_handler: Arc<H>,
+ threadpool: ThreadPool,
) -> Self where H: EventHandler + Send + Sync + 'static {
let (thread_tx, thread_rx) = mpsc::channel();
let (shard_queue_tx, shard_queue_rx) = mpsc::channel();
@@ -96,6 +100,7 @@ impl ShardManager {
rx: shard_queue_rx,
token: token.clone(),
ws_url: ws_url.clone(),
+ threadpool,
};
thread::spawn(move || {
diff --git a/src/client/bridge/gateway/shard_queuer.rs b/src/client/bridge/gateway/shard_queuer.rs
index f35acb7..ea49de4 100644
--- a/src/client/bridge/gateway/shard_queuer.rs
+++ b/src/client/bridge/gateway/shard_queuer.rs
@@ -14,6 +14,7 @@ use super::{
ShardRunner,
ShardRunnerInfo,
};
+use threadpool::ThreadPool;
use typemap::ShareMap;
#[cfg(feature = "framework")]
@@ -34,6 +35,7 @@ pub struct ShardQueuer<H: EventHandler + Send + Sync + 'static> {
pub manager_tx: Sender<ShardManagerMessage>,
pub runners: Arc<ParkingLotMutex<HashMap<ShardId, ShardRunnerInfo>>>,
pub rx: Receiver<ShardQueuerMessage>,
+ pub threadpool: ThreadPool,
pub token: Arc<Mutex<String>>,
pub ws_url: Arc<Mutex<String>>,
}
@@ -88,6 +90,7 @@ impl<H: EventHandler + Send + Sync + 'static> ShardQueuer<H> {
self.framework.clone(),
self.data.clone(),
self.event_handler.clone(),
+ self.threadpool.clone(),
)
} else {
ShardRunner::new(
@@ -95,6 +98,7 @@ impl<H: EventHandler + Send + Sync + 'static> ShardQueuer<H> {
self.manager_tx.clone(),
self.data.clone(),
self.event_handler.clone(),
+ self.threadpool.clone(),
)
}};
diff --git a/src/client/bridge/gateway/shard_runner.rs b/src/client/bridge/gateway/shard_runner.rs
index 6f6b050..1b1de0e 100644
--- a/src/client/bridge/gateway/shard_runner.rs
+++ b/src/client/bridge/gateway/shard_runner.rs
@@ -30,16 +30,17 @@ pub struct ShardRunner<H: EventHandler + Send + Sync + 'static> {
impl<H: EventHandler + Send + Sync + 'static> ShardRunner<H> {
#[cfg(feature = "framework")]
- pub fn new(shard: LockedShard,
- manager_tx: Sender<ShardManagerMessage>,
- framework: Arc<Mutex<Option<Box<Framework + Send>>>>,
- data: Arc<ParkingLotMutex<ShareMap>>,
- event_handler: Arc<H>) -> Self {
+ pub fn new(
+ shard: LockedShard,
+ manager_tx: Sender<ShardManagerMessage>,
+ framework: Arc<Mutex<Option<Box<Framework + Send>>>>,
+ data: Arc<ParkingLotMutex<ShareMap>>,
+ event_handler: Arc<H>,
+ threadpool: ThreadPool,
+ ) -> Self {
let (tx, rx) = mpsc::channel();
let shard_info = shard.lock().shard_info();
- let name = format!("threadpool {:?}", shard_info);
-
Self {
runner_rx: rx,
runner_tx: tx,
@@ -49,20 +50,21 @@ impl<H: EventHandler + Send + Sync + 'static> ShardRunner<H> {
manager_tx,
shard,
shard_info,
- threadpool: ThreadPool::with_name(name, 15),
+ threadpool,
}
}
#[cfg(not(feature = "framework"))]
- pub fn new(shard: LockedShard,
- manager_tx: Sender<ShardManagerMessage>,
- data: Arc<ParkingLotMutex<ShareMap>>,
- event_handler: Arc<H>) -> Self {
+ pub fn new(
+ shard: LockedShard,
+ manager_tx: Sender<ShardManagerMessage>,
+ data: Arc<ParkingLotMutex<ShareMap>>,
+ event_handler: Arc<H>,
+ threadpool: ThreadPool,
+ ) -> Self {
let (tx, rx) = mpsc::channel();
let shard_info = shard.lock().shard_info();
- let name = format!("threadpool {:?}", shard_info);
-
Self {
runner_rx: rx,
runner_tx: tx,
@@ -71,7 +73,7 @@ impl<H: EventHandler + Send + Sync + 'static> ShardRunner<H> {
manager_tx,
shard,
shard_info,
- threadpool: ThreadPool::with_name(name, 15),
+ threadpool,
}
}