Skip to content

Commit

Permalink
rtsc3
Browse files Browse the repository at this point in the history
  • Loading branch information
divi255 committed Jul 25, 2024
1 parent 6b404df commit 9638f6b
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 7 deletions.
8 changes: 6 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,12 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: cargo test
run: cargo test --all-features --all-targets
- name: cargo test default
run: cargo test --all-targets
- name: cargo test locking-rt
run: cargo test --no-default-features --all-features -F locking-rt
- name: cargo test locking-rt-safe
run: cargo test --no-default-features --all-features -F locking-rt-safe
fmt:
runs-on: ubuntu-latest
steps:
Expand Down
10 changes: 9 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,20 @@ tracing = "0.1.40"
serde = { version = "1.0.203", features = ["derive"] }
once_cell = "1.19.0"
tokio = { version = "1.38.0", features = ["net", "io-util", "time"], optional = true }
rtsc = "0.2"
rtsc = { path = "/opt/rtsc" }
parking_lot = { version = "0.12.3", optional = true }
parking_lot_rt = { version = "0.12.1", optional = true }

[features]
async = ["tokio"]
full = ["async"]

locking-default = ["dep:parking_lot", "rtsc/parking_lot"]
locking-rt = ["dep:parking_lot_rt"]
locking-rt-safe = []

default = ["locking-default"]

[dev-dependencies]
imageproc = "0.22"
image = "0.23"
Expand Down
9 changes: 9 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,15 @@ pub use server::Server;
use server::StreamServerInner;
use std::net::ToSocketAddrs;

#[cfg(feature = "locking-rt-safe")]
use rtsc::pi::{Condvar, Mutex, RawMutex};

#[cfg(feature = "locking-rt")]
use parking_lot_rt::{Condvar, Mutex, RawMutex};

#[cfg(feature = "locking-default")]
use parking_lot::{Condvar, Mutex, RawMutex};

const DEFAULT_TIMEOUT: Duration = Duration::from_secs(5);

static DEFAULT_SERVER: Lazy<Server> = Lazy::new(|| Server::new(DEFAULT_TIMEOUT));
Expand Down
8 changes: 4 additions & 4 deletions src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,14 @@ use std::{
};

use binrw::{BinRead, BinWrite};
use rtsc::locking::Mutex;
use rtsc::{cell::DataCell, semaphore::Semaphore};
use tracing::{error, trace};

const DEFAULT_MAX_CLIENTS: usize = 16;

use crate::{Error, Format, Frame, Greetings, Stream, StreamInfo, StreamSelect, API_VERSION};

type FrameCell = DataCell<Frame>;
type FrameCell = DataCell<Frame, crate::RawMutex, crate::Condvar>;

struct StreamInternal {
format: Format,
Expand Down Expand Up @@ -65,7 +64,8 @@ impl Server {
/// Run the server
pub fn serve(&self, addr: impl ToSocketAddrs + std::fmt::Debug) -> Result<(), Error> {
trace!(?addr, "starting server");
let semaphore = Semaphore::new(self.inner.max_clients.load(atomic::Ordering::Relaxed));
let semaphore: Semaphore<crate::RawMutex, crate::Condvar> =
Semaphore::new(self.inner.max_clients.load(atomic::Ordering::Relaxed));
let listener = TcpListener::bind(addr)?;
while let Ok((mut socket, addr)) = listener.accept() {
trace!(?addr, "new connection");
Expand All @@ -82,7 +82,7 @@ impl Server {
}

pub(crate) struct StreamServerInner {
streams: Mutex<Vec<StreamInternal>>,
streams: crate::Mutex<Vec<StreamInternal>>,
client_id: atomic::AtomicUsize,
timeout: Duration,
max_clients: atomic::AtomicUsize,
Expand Down

0 comments on commit 9638f6b

Please sign in to comment.