]> git.proxmox.com Git - pve-lxc-syscalld.git/commitdiff
started working on a replacement executor
authorWolfgang Bumiller <w.bumiller@proxmox.com>
Thu, 24 Oct 2019 12:42:04 +0000 (14:42 +0200)
committerWolfgang Bumiller <w.bumiller@proxmox.com>
Thu, 24 Oct 2019 12:48:57 +0000 (14:48 +0200)
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
src/executor/mod.rs [new file with mode: 0644]
src/executor/thread_pool.rs [new file with mode: 0644]
src/main.rs

diff --git a/src/executor/mod.rs b/src/executor/mod.rs
new file mode 100644 (file)
index 0000000..3a293f5
--- /dev/null
@@ -0,0 +1,12 @@
+use std::io;
+
+pub mod thread_pool;
+
+pub fn num_cpus() -> io::Result<usize> {
+    let rc = unsafe { libc::sysconf(libc::_SC_NPROCESSORS_ONLN) };
+    if rc < 0 {
+        Err(io::Error::last_os_error())
+    } else {
+        Ok(rc as usize)
+    }
+}
diff --git a/src/executor/thread_pool.rs b/src/executor/thread_pool.rs
new file mode 100644 (file)
index 0000000..b15285a
--- /dev/null
@@ -0,0 +1,49 @@
+use std::io;
+use std::sync::{Arc, Mutex};
+use std::thread::JoinHandle;
+
+use super::num_cpus;
+
+pub struct ThreadPool {
+    inner: Arc<Inner>,
+}
+
+pub struct Inner {
+    threads: Mutex<Vec<Thread>>,
+}
+
+pub struct Thread {
+    handle: JoinHandle<()>,
+    id: usize,
+}
+
+impl ThreadPool {
+    pub fn new() -> io::Result<Self> {
+        let count = num_cpus()?;
+
+        let inner = Arc::new(Inner {
+            threads: Mutex::new(Vec::new()),
+        });
+
+        let mut threads = Vec::with_capacity(count);
+        for thread_id in 0..count {
+            threads.push(Thread::new(Arc::clone(&inner), thread_id));
+        }
+
+        *inner.threads.lock().unwrap() = threads;
+
+        Ok(ThreadPool { inner })
+    }
+}
+
+impl Thread {
+    fn new(pool: Arc<Inner>, id: usize) -> Self {
+        let handle = std::thread::spawn(move || Self::thread_main(pool, id));
+        Self { handle, id }
+    }
+
+    fn thread_main(pool: Arc<Inner>, thread_id: usize) {
+        let _ = pool;
+        let _ = thread_id;
+    }
+}
index 44d29ee4a1fb2426a836c698d00a33229594b128..8556a9dbd5698bf010a2772c72123c663281e0a3 100644 (file)
@@ -10,6 +10,7 @@ mod macros;
 pub mod apparmor;
 pub mod capability;
 pub mod client;
+pub mod executor;
 pub mod fork;
 pub mod lxcseccomp;
 pub mod nsfd;