diff options
author | teymour-aldridge <teymour.aldridge@icloud.com> | 2020-12-27 19:49:54 +0000 |
---|---|---|
committer | teymour-aldridge <teymour.aldridge@icloud.com> | 2020-12-28 11:01:38 +0000 |
commit | 1f38e3411d76c5ad89a51d8b3c631bcf94aa1b21 (patch) | |
tree | 81d25297d62114803bb29d0e33d7449a92b5012d | |
parent | cbda5c3e3ec9f3834f6b0757f0e004762d8b2371 (diff) | |
download | servo-1f38e3411d76c5ad89a51d8b3c631bcf94aa1b21.tar.gz servo-1f38e3411d76c5ad89a51d8b3c631bcf94aa1b21.zip |
Fix num_threads to avoid divide by zero error when running without a thread pool
Signed-off-by: teymour-aldridge <teymour.aldridge@icloud.com>
-rw-r--r-- | components/layout_thread/lib.rs | 2 | ||||
-rw-r--r-- | components/style/global_style_data.rs | 10 |
2 files changed, 8 insertions, 4 deletions
diff --git a/components/layout_thread/lib.rs b/components/layout_thread/lib.rs index 7446e13a3b5..7cb926f10a4 100644 --- a/components/layout_thread/lib.rs +++ b/components/layout_thread/lib.rs @@ -1404,7 +1404,7 @@ impl LayoutThread { let pool; let (thread_pool, num_threads) = if self.parallel_flag { pool = STYLE_THREAD_POOL.pool(); - (pool.as_ref(), STYLE_THREAD_POOL.num_threads) + (pool.as_ref(), STYLE_THREAD_POOL.num_threads.unwrap_or(1)) } else { (None, 1) }; diff --git a/components/style/global_style_data.rs b/components/style/global_style_data.rs index a9e79bf6820..872d97745f4 100644 --- a/components/style/global_style_data.rs +++ b/components/style/global_style_data.rs @@ -26,8 +26,8 @@ pub struct GlobalStyleData { /// Global thread pool. pub struct StyleThreadPool { - /// How many threads parallel styling can use. - pub num_threads: usize, + /// How many threads parallel styling can use. If not using a thread pool, this is set to `None`. + pub num_threads: Option<usize>, /// The parallel styling thread pool. /// @@ -160,7 +160,11 @@ lazy_static! { }; StyleThreadPool { - num_threads, + num_threads: if num_threads > 0 { + Some(num_threads) + } else { + None + }, style_thread_pool: RwLock::new(pool), } }; |