From d123df26ff1796f4712b10290a3b6647d754a6e3 Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Sun, 4 Aug 2013 21:54:59 -0700 Subject: [PATCH 1/2] std: Fix newsched logging truncation The truncation needs to be done in the console logger in order to catch all the logging output, and because truncation only matters when outputting to the console. --- src/libstd/logging.rs | 10 ---------- src/libstd/rt/logging.rs | 21 +++++++++++++++++---- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/src/libstd/logging.rs b/src/libstd/logging.rs index c662e5997afa6..6e11d14aea9a3 100644 --- a/src/libstd/logging.rs +++ b/src/libstd/logging.rs @@ -85,16 +85,6 @@ pub fn log_type(level: u32, object: &T) { fn newsched_log_str(msg: ~str) { use rt::task::Task; use rt::local::Local; - use str::StrSlice; - use container::Container; - - // Truncate the string - let buf_bytes = 256; - let msg = if msg.len() > buf_bytes { - msg.slice(0, buf_bytes) + "[...]" - } else { - msg - }; unsafe { match Local::try_unsafe_borrow::() { diff --git a/src/libstd/rt/logging.rs b/src/libstd/rt/logging.rs index 11d11daebc254..9056f0d52e09a 100644 --- a/src/libstd/rt/logging.rs +++ b/src/libstd/rt/logging.rs @@ -10,6 +10,7 @@ use either::*; use libc; +use str::StrSlice; pub trait Logger { fn log(&mut self, msg: Either<~str, &'static str>); @@ -35,10 +36,22 @@ impl Logger for StdErrLogger { s } }; - let dbg = ::libc::STDERR_FILENO as ::io::fd_t; - dbg.write_str(s); - dbg.write_str("\n"); - dbg.flush(); + + // Truncate the string + let buf_bytes = 256; + if s.len() > buf_bytes { + let s = s.slice(0, buf_bytes) + "[...]"; + print(s); + } else { + print(s) + }; + + fn print(s: &str) { + let dbg = ::libc::STDERR_FILENO as ::io::fd_t; + dbg.write_str(s); + dbg.write_str("\n"); + dbg.flush(); + } } } From 167bdff04164c92c203c319b730bdc2344dbe089 Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Sun, 4 Aug 2013 21:55:52 -0700 Subject: [PATCH 2/2] std::rt: Schedule more scheduler callbacks to avoid dropping messages --- src/libstd/rt/sched.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/libstd/rt/sched.rs b/src/libstd/rt/sched.rs index a5c8abc2a6c0e..1a75f2569b59e 100644 --- a/src/libstd/rt/sched.rs +++ b/src/libstd/rt/sched.rs @@ -339,8 +339,8 @@ impl Scheduler { let mut this = self; match this.message_queue.pop() { Some(PinnedTask(task)) => { - let mut task = task; this.event_loop.callback(Scheduler::run_sched_once); + let mut task = task; task.give_home(Sched(this.make_handle())); this.resume_task_immediately(task); return None; @@ -351,10 +351,12 @@ impl Scheduler { return this.sched_schedule_task(task); } Some(Wake) => { + this.event_loop.callback(Scheduler::run_sched_once); this.sleepy = false; return Some(this); } Some(Shutdown) => { + this.event_loop.callback(Scheduler::run_sched_once); if this.sleepy { // There may be an outstanding handle on the // sleeper list. Pop them all to make sure that's