Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

45 changes: 40 additions & 5 deletions litebox/src/litebox.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use alloc::sync::Arc;

use litebox_broker_local::BrokerLocal;
use litebox_broker_protocol::ProcessId;
use litebox_broker_protocol::message::BrokerNotification;
use litebox_broker_transport::channel::LocalCallChannel;
use litebox_platform::time::TimeProvider;
Expand All @@ -14,6 +15,7 @@ use crate::{
broker,
fd::Descriptors,
sync::{RawSyncPrimitivesProvider, RwLock},
thread::Thread,
};

/// A full LiteBox system.
Expand Down Expand Up @@ -48,16 +50,49 @@ impl<Platform: RawSyncPrimitivesProvider> LiteBox<Platform> {
platform: &'static Platform,
broker_local: BrokerLocal<Channel>,
) -> Self
where
Platform: TimeProvider,
Channel: LocalCallChannel + Send + Sync + 'static,
{
Self::new_with_broker_local_inner(platform, broker_local).0
}

fn new_with_broker_local_inner<Channel>(
platform: &'static Platform,
broker_local: BrokerLocal<Channel>,
) -> (Self, Arc<dyn broker::BrokerControl>)
where
Platform: TimeProvider,
Channel: LocalCallChannel + Send + Sync + 'static,
{
let broker_pollables = Arc::new(broker::BrokerPollableRegistry::new());
let broker_control = Arc::new(broker::BrokerLocalControl::<Platform, Channel>::new(
broker_local,
Arc::clone(&broker_pollables),
));
Self::new_inner(platform, Some(broker_control), broker_pollables)
let broker_control: Arc<dyn broker::BrokerControl> =
Arc::new(broker::BrokerLocalControl::<Platform, Channel>::new(
broker_local,
Arc::clone(&broker_pollables),
));
let litebox = Self::new_inner(
platform,
Some(Arc::clone(&broker_control)),
broker_pollables,
);
(litebox, broker_control)
}

/// Creates a broker-backed process and its negotiated initial thread.
pub fn new_process_with_broker_local<Channel>(
platform: &'static Platform,
broker_local: BrokerLocal<Channel>,
) -> (Self, ProcessId, Thread)
where
Platform: TimeProvider,
Channel: LocalCallChannel + Send + Sync + 'static,
{
let process_id = broker_local.process_id();
let initial_thread_id = broker_local.initial_thread_id();
let (litebox, broker) = Self::new_with_broker_local_inner(platform, broker_local);
let initial_thread = Thread::from_broker(initial_thread_id, broker);
(litebox, process_id, initial_thread)
}

fn new_inner(
Expand Down
4 changes: 4 additions & 0 deletions litebox/src/thread.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ pub struct Thread {
}

impl Thread {
pub(crate) fn from_broker(id: ThreadId, broker: Arc<dyn BrokerControl>) -> Self {
Self { id, broker }
}

/// Returns the assigned thread ID.
#[must_use]
pub const fn id(&self) -> u32 {
Expand Down
9 changes: 2 additions & 7 deletions litebox_broker_core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ impl BrokerCore {
Ok((first, second))
}

/// Allocates and registers one authenticated broker process.
/// Allocates one authenticated process awaiting association activation.
///
/// # Panics
///
Expand All @@ -320,12 +320,7 @@ impl BrokerCore {
.map_err(|_| BrokerError::OutOfMemory)?;
let raw_id = self.ids.lock().allocate()?;
let id = ProcessId(raw_id);
let process = Arc::new(BrokerProcess::new(
self.clone(),
id,
None,
caller_credential,
));
let process = Arc::new(BrokerProcess::new(self.clone(), id, caller_credential));
assert!(
processes.insert(id, Arc::downgrade(&process)).is_none(),
"the ID allocator returned an occupied process ID"
Expand Down
Loading
Loading