From add254d996c1c5efa1c48f37402d9a97e7d2cc26 Mon Sep 17 00:00:00 2001
From: askiiart <dev@askiiart.net>
Date: Fri, 17 Jan 2025 16:42:56 -0600
Subject: [PATCH] make threads floats

---
 docs/config-reference.md |  8 +++++---
 src/data.rs              | 24 ++++++++++++------------
 src/main.rs              |  2 +-
 3 files changed, 18 insertions(+), 16 deletions(-)

diff --git a/docs/config-reference.md b/docs/config-reference.md
index fad988e..67d3921 100644
--- a/docs/config-reference.md
+++ b/docs/config-reference.md
@@ -16,7 +16,7 @@ Note: This primarily uses LibreWolf and Fedora as examples of packages and distr
 
 - `log-level` (integer): Log level `0`-`3` (error, warning, info, or debug)
   - Default: 1 - warning
-- `max-threads` (integer): The maximum number of threads to be used
+- `max-threads` (float): The maximum number of threads to be used
   - **See also**: [`threads`](#job-config)
   - Default is CPU's threads - 2
 - `max-jobs` (integer): The maximum number of jobs to be run at once
@@ -26,7 +26,7 @@ Note: This primarily uses LibreWolf and Fedora as examples of packages and distr
 
 **Multithreading notes (IMPORTANT)**: Gregory will first run compilation jobs, then packaging jobs for whatever programs are done, then run the `update-repo` for whichever distros are finished. For this reason, the distro names listed under `packaging` and `update-repo` *must* match.
 
-**Multithreading/multiple jobs is not implemented yet**
+**Multithreading is not implemented yet**
 
 ## Job config
 
@@ -35,7 +35,7 @@ Note: This primarily uses LibreWolf and Fedora as examples of packages and distr
   - If you just want to run stuff, you don't need this, but it's *highly* recommended as it allows you to filter your logs.
 - `revision` (string): A revision id for the job, such as a version number for a compilation script
   - Default is `1`
-- `threads` (integer): The maximum number of vCPUs/threads to dedicate to a job; this can be a fractional number
+- `threads` (float): The maximum number of vCPUs/threads to dedicate to a job; this can be a fractional number
   - Set this as less than or equal to the max number of threads the thing you're running will use
   - See `--cpus` in the [`podman run` docs](https://docs.podman.io/en/latest/markdown/podman-run.1.html#cpus)
   - *Root may be required for this argument*
@@ -48,6 +48,8 @@ Note: This primarily uses LibreWolf and Fedora as examples of packages and distr
 - `shell` (string): The shell to run the commands in
   - Default: `/bin/sh`
 
+Note: `id` and `revision` are *not* for the package version, they are for 
+
 ## Packages (`packages`)
 
 Example:
diff --git a/src/data.rs b/src/data.rs
index f0c9eba..adc00c9 100644
--- a/src/data.rs
+++ b/src/data.rs
@@ -22,7 +22,7 @@ pub(crate) struct Config {
     pub(crate) max_jobs: u32,
     /// Maximum number of threads to use
     #[serde(default = "max_threads", rename = "max-threads")]
-    pub(crate) max_threads: u32,
+    pub(crate) max_threads: f32,
     #[serde(default = "data", rename = "data-dir")]
     pub(crate) data_dir: String,
     /// Holds the packages, including their compilation and packaging
@@ -52,7 +52,7 @@ pub(crate) struct Job {
     ///
     /// If `threads` isn't specified, it will fall back to `max_threads` (from [`Config`]); the same behavior applies if `threads` is greater than `max_threads`
     #[serde(default = "job_threads")]
-    pub(crate) threads: u32,
+    pub(crate) threads: f32,
     /// The OCI image to run it in
     ///
     /// For example, `docker.io/library/debian:latest`
@@ -123,15 +123,15 @@ pub(crate) fn log_level() -> u8 {
     return 1;
 }
 
-/// Returns the default number of max threads
-pub(crate) fn max_threads() -> u32 {
-    let total_threads = thread::available_parallelism().unwrap().get() as u32;
-    if total_threads >= 32 {
-        return total_threads - 4;
-    } else if total_threads >= 12 {
-        return total_threads - 2;
-    } else if total_threads >= 3 {
-        return total_threads - 1;
+/// Returns the default number of max threads.
+pub(crate) fn max_threads() -> f32 {
+    let total_threads = thread::available_parallelism().unwrap().get() as f32;
+    if total_threads >= 32.0 {
+        return total_threads - 4.0;
+    } else if total_threads >= 12.0 {
+        return total_threads - 2.0;
+    } else if total_threads >= 3.0 {
+        return total_threads - 1.0;
     } else {
         return total_threads;
     }
@@ -148,7 +148,7 @@ pub(crate) fn volumes() -> HashMap<String, String> {
 }
 
 /// Returns the default number of threads for a job - [`max_threads()`]
-pub(crate) fn job_threads() -> u32 {
+pub(crate) fn job_threads() -> f32 {
     return max_threads();
 }
 
diff --git a/src/main.rs b/src/main.rs
index 0d8e0ef..b64561d 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -79,7 +79,7 @@ fn run(config_path: String) {
 
 fn run_job(conf: Config, job: Job) -> JobExitStatus {
     // limit threads to max_threads in the config
-    let mut threads: u32 = job.threads;
+    let mut threads = job.threads;
     if job.threads > conf.max_threads {
         threads = conf.max_threads;
     }