This commit is contained in:
Dennis Schwerdel 2020-12-21 00:13:32 +01:00
parent ff40f47b52
commit 5000066646
4 changed files with 70 additions and 0 deletions

View File

@ -0,0 +1,33 @@
use std::{marker::PhantomData, sync::Arc};
use super::shared::SharedData;
use crate::{
device::Device,
util::{Time, TimeSource}
};
const SYNC_INTERVAL: Time = 1;
pub struct DeviceThread<D: Device, T: TimeSource> {
shared: Arc<SharedData>,
device: D,
next_sync: Time,
_dummy: PhantomData<T>
}
impl<D: Device, T: TimeSource> DeviceThread<D, T> {
fn sync(&mut self) {
// TODO sync
}
pub fn run(mut self) {
loop {
let now = T::now();
if self.next_sync < now {
self.sync();
self.next_sync = now + SYNC_INTERVAL
}
}
}
}

View File

@ -2,6 +2,10 @@
// Copyright (C) 2015-2020 Dennis Schwerdel
// This software is licensed under GPL-3 or newer (see LICENSE.md)
mod device_thread;
mod socket_thread;
mod shared;
use std::{
cmp::{max, min},
collections::HashMap,

1
src/engine/shared.rs Normal file
View File

@ -0,0 +1 @@
pub struct SharedData {}

View File

@ -0,0 +1,32 @@
use std::marker::PhantomData;
use std::sync::Arc;
use super::shared::SharedData;
use crate::net::Socket;
use crate::util::{Time, TimeSource};
const SYNC_INTERVAL: Time = 1;
pub struct SocketThread<S: Socket, T: TimeSource> {
shared: Arc<SharedData>,
socket: S,
next_sync: Time,
_dummy: PhantomData<T>
}
impl<S: Socket, T: TimeSource> SocketThread<S, T> {
fn sync(&mut self) {
//TODO sync
}
pub fn run(mut self) {
loop {
let now = T::now();
if self.next_sync < now {
self.sync();
self.next_sync = now + SYNC_INTERVAL
}
}
}
}