Now with Atomicity
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
use std::io::{Read, Write};
|
||||
use std::sync::Mutex;
|
||||
use std::rc::Rc;
|
||||
use std::sync::{Mutex, Arc};
|
||||
|
||||
use Result;
|
||||
use block::Block;
|
||||
@@ -32,7 +31,7 @@ pub struct Machine {
|
||||
pub heap: Heap,
|
||||
|
||||
pub stream_in: Box<Read + Send + Sync>,
|
||||
pub stream_out: Rc<Mutex<Write + Send + Sync>>,
|
||||
pub stream_out: Arc<Mutex<Write + Send + Sync>>,
|
||||
|
||||
}
|
||||
|
||||
@@ -45,7 +44,7 @@ impl Machine {
|
||||
block,
|
||||
frame: vec![Frame::new(ANTI_BS_SIZE)],
|
||||
stream_in: Box::new(::std::io::stdin()),
|
||||
stream_out: Rc::new(Mutex::new(::std::io::stdout())),
|
||||
stream_out: Arc::new(Mutex::new(::std::io::stdout())),
|
||||
|
||||
#[cfg(feature = "bonus:network")]
|
||||
net: NetStack::new(),
|
||||
@@ -152,7 +151,7 @@ impl Machine {
|
||||
self.stream_in = instream;
|
||||
}
|
||||
|
||||
pub fn set_output(&mut self, outstream: Rc<Mutex<Write + Send + Sync>>) {
|
||||
pub fn set_output(&mut self, outstream: Arc<Mutex<Write + Send + Sync>>) {
|
||||
self.stream_out = outstream;
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,6 @@
|
||||
extern crate rustijvm;
|
||||
|
||||
use std::rc::Rc;
|
||||
use std::sync::Mutex;
|
||||
use std::sync::{Arc, Mutex};
|
||||
use std::io::{Cursor, Seek, SeekFrom, Read};
|
||||
|
||||
fn steps(machine: &mut rustijvm::Machine, num: usize) {
|
||||
@@ -12,7 +11,7 @@ fn steps(machine: &mut rustijvm::Machine, num: usize) {
|
||||
|
||||
#[test]
|
||||
fn advanced1() {
|
||||
let output: Rc<Mutex<Cursor<Vec<u8>>>> = Rc::new(Mutex::new(Cursor::new(Vec::new())));
|
||||
let output: Arc<Mutex<Cursor<Vec<u8>>>> = Arc::new(Mutex::new(Cursor::new(Vec::new())));
|
||||
let input = Box::new("A".as_bytes());
|
||||
let mut machine = rustijvm::Machine::new_from_file("files/task5/all_regular.ijvm").unwrap();
|
||||
machine.set_input(input);
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
extern crate rustijvm;
|
||||
|
||||
use std::rc::Rc;
|
||||
use std::sync::Mutex;
|
||||
use std::sync::{Arc, Mutex};
|
||||
use std::io::{Cursor, Seek, SeekFrom, Read};
|
||||
|
||||
#[test]
|
||||
fn advanced4_tanenbaum() {
|
||||
let rc = Rc::new(Mutex::new(Cursor::new(Vec::new())));
|
||||
let rc = Arc::new(Mutex::new(Cursor::new(Vec::new())));
|
||||
let mut machine = rustijvm::Machine::new_from_file("files/advanced/Tanenbaum.ijvm").unwrap();
|
||||
machine.set_output(rc.clone());
|
||||
machine.run().unwrap();
|
||||
|
||||
@@ -1,13 +1,12 @@
|
||||
extern crate rustijvm;
|
||||
|
||||
use std::fs::File;
|
||||
use std::rc::Rc;
|
||||
use std::sync::Mutex;
|
||||
use std::sync::{Arc, Mutex};
|
||||
use std::io::{Cursor, Seek, SeekFrom, Read};
|
||||
|
||||
fn run_bfi(file: &str) -> String {
|
||||
let file = File::open(file).expect("Missing bf file");
|
||||
let rc = Rc::new(Mutex::new(Cursor::new(Vec::new())));
|
||||
let rc = Arc::new(Mutex::new(Cursor::new(Vec::new())));
|
||||
let mut machine = rustijvm::Machine::new_from_file("files/bonus/bfi.ijvm").unwrap();
|
||||
machine.set_output(rc.clone());
|
||||
machine.set_input(Box::new(file));
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
extern crate rustijvm;
|
||||
|
||||
use std::io::{Cursor, Read, Seek, SeekFrom};
|
||||
use std::rc::Rc;
|
||||
use std::sync::Mutex;
|
||||
use std::sync::{Arc, Mutex};
|
||||
|
||||
fn steps(machine: &mut rustijvm::Machine, num: usize) {
|
||||
for _ in 0..num {
|
||||
@@ -84,7 +83,7 @@ fn task4_complex_load() {
|
||||
|
||||
#[test]
|
||||
fn task4_iteration_load() {
|
||||
let rc = Rc::new(Mutex::new(Cursor::new(Vec::new())));
|
||||
let rc = Arc::new(Mutex::new(Cursor::new(Vec::new())));
|
||||
|
||||
let mut machine = rustijvm::Machine::new_from_file("files/task4/LoadTest4.ijvm").unwrap();
|
||||
machine.set_output(rc.clone());
|
||||
|
||||
Reference in New Issue
Block a user