Skip to content

Commit

Permalink
Major refactoring of Scheduler/Task
Browse files Browse the repository at this point in the history
Highlights:
  * Suspended tasks no longer hog a thread and idle. Instead their
    thread ends and they are moved into a suspended vector inside the
    scheduler itself.
  * Tasks that start in a delayed state (e.g. forks) now no longer use
    a thread with a manual delay. Instead they begin their life in
    suspended state and are picked up by the scheduler tick.
  * Gut the remainder of the complicated dispatch logic that was
    leftover from the old async/tokio version of this code. Intermediate
    result objects (which used to be processed in batch) are gone, and
    actions are immediately acted on. This should be a lot easier to
    read now.

I believe this paves the way for a more testable, robust future.
  • Loading branch information
rdaum committed Jun 26, 2024
1 parent 2a19f32 commit 6cc434e
Show file tree
Hide file tree
Showing 8 changed files with 859 additions and 1,085 deletions.
5 changes: 2 additions & 3 deletions crates/kernel/src/builtins/bf_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ fn bf_notify(bf_args: &mut BfCallState<'_>) -> Result<BfRet, BfErr> {
.map_err(world_state_bf_err)?;

let event = NarrativeEvent::notify_text(bf_args.exec_state.caller(), msg.to_string());

bf_args
.scheduler_sender
.send((
Expand All @@ -81,7 +80,7 @@ fn bf_notify(bf_args: &mut BfCallState<'_>) -> Result<BfRet, BfErr> {
event,
},
))
.expect("scheduler is not listening");
.ok();

// MOO docs say this should return none, but in reality it returns 1?
Ok(Ret(v_int(1)))
Expand Down Expand Up @@ -444,7 +443,7 @@ fn bf_queued_tasks(bf_args: &mut BfCallState<'_>) -> Result<BfRet, BfErr> {
.scheduler_sender
.send((
bf_args.exec_state.task_id,
SchedulerControlMsg::DescribeOtherTasks(send),
SchedulerControlMsg::RequestQueuedTasks(send),
))
.expect("scheduler is not listening");
let tasks = receive.recv().expect("scheduler is not listening");
Expand Down
6 changes: 0 additions & 6 deletions crates/kernel/src/tasks/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@

use crate::tasks::scheduler::TaskResult;
use moor_values::var::{List, Objid};
use std::cell::Cell;
use std::marker::PhantomData;
use std::sync::MutexGuard;
use std::time::SystemTime;

pub mod command_parse;
Expand All @@ -42,9 +39,6 @@ impl TaskHandle {
}
}

pub(crate) type PhantomUnsync = PhantomData<Cell<()>>;
pub(crate) type PhantomUnsend = PhantomData<MutexGuard<'static, ()>>;

/// The minimum set of information needed to make a *resolution* call for a verb.
#[derive(Debug, Clone, Eq, PartialEq)]
pub struct VerbCall {
Expand Down
Loading

0 comments on commit 6cc434e

Please sign in to comment.