Skip to content

Commit

Permalink
rgs
Browse files Browse the repository at this point in the history
  • Loading branch information
ZephyrTFA committed Oct 29, 2023
1 parent d8097d3 commit cff7226
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 12 deletions.
2 changes: 0 additions & 2 deletions dmsrc/log.dm

This file was deleted.

3 changes: 3 additions & 0 deletions dmsrc/world.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/world/Del(...)
RUSTG_CALL(RUST_G, "shutdown_rustg")
return ..()
10 changes: 10 additions & 0 deletions src/byond.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ use std::{
slice,
};

use crate::{jobs, log};

static EMPTY_STRING: c_char = 0;
thread_local! {
static RETURN_STRING: RefCell<CString> = RefCell::new(CString::default());
Expand Down Expand Up @@ -84,3 +86,11 @@ byond_fn!(
Some(env!("CARGO_PKG_VERSION"))
}
);

byond_fn!(
fn shutdown_rustg() {
jobs::detach_all();
log::close_all_logs();
Some("1")
}
);
8 changes: 8 additions & 0 deletions src/jobs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ impl Jobs {
id
}

pub fn detach_all(&mut self) {
self.map.clear();
}

fn check(&mut self, id: &str) -> Output {
let entry = match self.map.entry(id.to_owned()) {
Entry::Occupied(occupied) => occupied,
Expand All @@ -62,3 +66,7 @@ pub fn start<F: FnOnce() -> Output + Send + 'static>(f: F) -> JobId {
pub fn check(id: &str) -> String {
JOBS.with(|jobs| jobs.borrow_mut().check(id))
}

pub fn detach_all() {
JOBS.with(|jobs| jobs.borrow_mut().detach_all());
}
17 changes: 7 additions & 10 deletions src/log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,20 +44,17 @@ byond_fn!(fn log_write(path, data, ...rest) {
}).err()
});

byond_fn!(
fn log_close_all() {
FILE_MAP.with(|cell| {
let mut map = cell.borrow_mut();
map.clear();
});
Some("")
}
);

fn open(path: &Path) -> Result<File> {
if let Some(parent) = path.parent() {
fs::create_dir_all(parent)?;
}

Ok(OpenOptions::new().append(true).create(true).open(path)?)
}

pub fn close_all_logs() {
FILE_MAP.with(|cell| {
let mut map = cell.borrow_mut();
map.clear();
})
}

0 comments on commit cff7226

Please sign in to comment.