Skip to content

Commit

Permalink
#151 Created Bastion Utilities crate
Browse files Browse the repository at this point in the history
Created Bastion Utilities Crate
  • Loading branch information
lurk-skywater authored Jan 5, 2020
2 parents 99480f0 + 54884b6 commit ce290f3
Show file tree
Hide file tree
Showing 8 changed files with 107 additions and 12 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
members = [
"bastion",
"bastion-executor",
"bastion-utils",
"lightproc"
]

Expand Down
1 change: 1 addition & 0 deletions bastion-executor/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ maintenance = { status = "actively-developed" }
unstable = ["numanji", "allocator-suite", "jemallocator"]

[dependencies]
bastion-utils = { version = "0.3.2", path = "../bastion-utils" }
crossbeam-utils = "0.7"
crossbeam-channel = "0.4"
crossbeam-epoch = "0.8"
Expand Down
17 changes: 8 additions & 9 deletions bastion-executor/src/blocking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,25 +52,24 @@
//! to even out the load.
use std::collections::VecDeque;

use std::future::Future;
use std::io::ErrorKind;
use std::iter::Iterator;
use std::sync::atomic::{AtomicU64, Ordering};
use std::sync::Mutex;
use std::time::Duration;
use std::{env, thread};

use crossbeam_channel::{bounded, Receiver, Sender};
use lazy_static::lazy_static;

use crate::{load_balancer, placement, utils};
use bastion_utils::math;
use lazy_static::lazy_static;
use lightproc::lightproc::LightProc;
use lightproc::proc_stack::ProcStack;
use lightproc::recoverable_handle::RecoverableHandle;
use std::future::Future;
use std::io::ErrorKind;
use std::iter::Iterator;

use crate::placement::CoreId;

use std::sync::Mutex;
use crate::{load_balancer, placement};

/// If low watermark isn't configured this is the default scaler value.
/// This value is used for the heuristics of the scaler
Expand Down Expand Up @@ -264,7 +263,7 @@ fn create_blocking_thread() {
//
// Generate a simple random number of milliseconds
let rand_sleep_ms = 1000_u64
.checked_add(u64::from(utils::random(10_000)))
.checked_add(u64::from(math::random(10_000)))
.expect("shouldn't overflow");

let _ = thread::Builder::new()
Expand Down
2 changes: 0 additions & 2 deletions bastion-executor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@ pub mod run_queue;
pub mod sleepers;
pub mod worker;

mod utils;

///
/// Prelude of Bastion Executor
pub mod prelude {
Expand Down
19 changes: 19 additions & 0 deletions bastion-utils/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[package]
name = "bastion-utils"
version = "0.3.2"
description = "Utilities for Bastion, the highly-available, fault-tolerant, async communication oriented executor"
authors = [
"Mahmut Bulut <vertexclique@gmail.com>",
"Patrice Billaut <pbillaut@pm.me>",
]
keywords = ["fault-tolerant", "runtime", "actor", "system"]
categories = ["concurrency", "asynchronous"]
homepage = "https://github.com/bastion-rs/bastion"
repository = "https://github.com/bastion-rs/bastion"
documentation = "https://docs.rs/bastion"
license = "Apache-2.0/MIT"
edition = "2018"

[badges]
travis-ci = { repository = "bastion-rs/bastion", branch = "master" }
maintenance = { status = "actively-developed" }
49 changes: 49 additions & 0 deletions bastion-utils/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Bastion Utils

<table align=left style='float: left; margin: 4px 10px 0px 0px; border: 1px solid #000000;'>
<tr>
<td>Latest Release</td>
<td>
<a href="https://crates.io/crates/bastion-utils">
<img alt="Crates.io" src="https://img.shields.io/crates/v/bastion-utils.svg?style=popout-square">
</a>
</td>
</tr>
<tr>
<td></td>
</tr>
<tr>
<td>License</td>
<td>
<a href="https://github.com/bastion-rs/bastion/blob/master/LICENSE">
<img alt="Crates.io" src="https://img.shields.io/crates/l/bastion.svg?style=popout-square">
</a>
</td>
</tr>
<tr>
<td>Build Status</td>
<td>
<a href="https://actions-badge.atrox.dev/bastion-rs/bastion/goto">
<img alt="Build Status" src="https://img.shields.io/endpoint.svg?url=https%3A%2F%2Factions-badge.atrox.dev%2Fbastion-rs%2Fbastion%2Fbadge&style=flat" />
</a>
</td>
</tr>
<tr>
<td>Downloads</td>
<td>
<a href="https://crates.io/crates/lightproc">
<img alt="Crates.io" src="https://img.shields.io/crates/d/bastion-utils.svg?style=popout-square">
</a>
</td>
</tr>
<tr>
<td>Discord</td>
<td>
<a href="https://discord.gg/DqRqtRT">
<img alt="Discord Chat" src="https://img.shields.io/discord/628383521450360842.svg?logo=discord">
</a>
</td>
</tr>
</table>

Utilities for Bastion, the highly-available, fault-tolerant, async communication oriented executor
16 changes: 16 additions & 0 deletions bastion-utils/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//! Bastion Utilities
//!
//! Utilities for Bastion, the highly-available, fault-tolerant, async communication
//! oriented executor.
//!
#![doc(
html_logo_url = "https://raw.githubusercontent.com/bastion-rs/bastion/master/img/bastion-logo.png"
)]
// Discarded lints
#![allow(clippy::if_same_then_else)]
// Force missing implementations
#![warn(missing_docs)]
#![warn(missing_debug_implementations)]

pub mod math;
14 changes: 13 additions & 1 deletion bastion-executor/src/utils.rs → bastion-utils/src/math.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
//! Utility functions for mathematical operations
/// Generates a random number in `0..n`.
pub(crate) fn random(n: u32) -> u32 {
pub fn random(n: u32) -> u32 {
use std::cell::Cell;
use std::num::Wrapping;

Expand All @@ -24,3 +26,13 @@ pub(crate) fn random(n: u32) -> u32 {
((x.0 as u64).wrapping_mul(n as u64) >> 32) as u32
})
}

/// Simple linear Knuth shuffle
pub fn shuffle_linear<T>(v: &mut Vec<T>) -> &mut Vec<T> {
let l = v.len();
for n in 0..l {
let i = random((l - n) as u32) as usize;
v.swap(i, l - n - 1);
}
v
}

0 comments on commit ce290f3

Please sign in to comment.