Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ jobs:

- name: Test all features (Linux)
if: matrix.features == '' && runner.os == 'Linux'
run: sudo -E /usr/share/rust/.cargo/bin/cargo test --all-features
run: sudo -E /home/runner/.cargo/bin/cargo test --all-features
# run: sudo -E /usr/share/rust/.cargo/bin/cargo test --all-features

clippy:
name: Run clippy
Expand Down
11 changes: 8 additions & 3 deletions .github/workflows/nightly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,14 @@ jobs:
if: matrix.features == ''
run: cargo build --all-features

- name: Test all features
if: matrix.features == ''
run: cargo test --all-features
- name: Test all features (other)
if: matrix.features == '' && runner.os != 'Linux'
run: cargo test --all-features -- --skip set_deadline_policy

- name: Test all features (Linux)
if: matrix.features == '' && runner.os == 'Linux'
run: sudo -E /home/runner/.cargo/bin/cargo test --all-features
# run: sudo -E /usr/share/rust/.cargo/bin/cargo test --all-features

rustfmt:
name: Format
Expand Down
29 changes: 0 additions & 29 deletions .travis.yml

This file was deleted.

5 changes: 4 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "thread-priority"
version = "0.3.0"
version = "0.4.0"
authors = ["Victor Polevoy <[email protected]>"]
description = "Library for managing threads priority and schedule policies"
repository = "https://github.com/vityafx/thread-priority"
Expand All @@ -11,6 +11,9 @@ keywords = ["thread", "schedule", "priority", "pthread"]
categories = ["concurrency", "asynchronous", "os"]
edition = "2018"

[dependencies]
log = "0.4"

[target.'cfg(unix)'.dependencies]
libc = "0.2"

Expand Down
93 changes: 92 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ so feel free to contribute!
- Linux
- Windows

## Example
## Examples

### Minimal cross-platform examples
Setting current thread's priority to minimum:

```rust,no_run
Expand All @@ -25,5 +27,94 @@ fn main() {
}
```

The same as above but using a specific value:

```rust,no_run
use thread_priority::*;
use std::convert::TryInto;

fn main() {
// The lower the number the lower the priority.
assert!(set_current_thread_priority(ThreadPriority::Crossplatform(0.try_into().unwrap())).is_ok());
}
```

### Windows-specific examples
Set the thread priority to the lowest possible value:

```rust,no_run
use thread_priority::*;

fn main() {
// The lower the number the lower the priority.
assert!(set_current_thread_priority(ThreadPriority::Os(WinAPIThreadPriority::Lowest.into())).is_ok());
}
```

Set the ideal processor for the new thread:

```rust,no_run
use thread_priority::*;

fn main() {
std::thread::spawn(|| {
set_thread_ideal_processor(thread_native_id(), 0);
println!("Hello world!");
});
}
```


### Building a thread using the ThreadBuilderExt trait

```rust,no_run
use thread_priority::*;
use thread_priority::ThreadBuilderExt;

let thread = std::thread::Builder::new()
.name("MyNewThread".to_owned())
.spawn_with_priority(ThreadPriority::Max, |result| {
// This is printed out from within the spawned thread.
println!("Set priority result: {:?}", result);
assert!(result.is_ok());
}).unwrap();
thread.join();
```

### Building a thread using the ThreadBuilder.

```rust,no_run
use thread_priority::*;

let thread = ThreadBuilder::default()
.name("MyThread")
.priority(ThreadPriority::Max)
.spawn(|result| {
// This is printed out from within the spawned thread.
println!("Set priority result: {:?}", result);
assert!(result.is_ok());
}).unwrap();
thread.join();

// Another example where we don't care about the priority having been set.
let thread = ThreadBuilder::default()
.name("MyThread")
.priority(ThreadPriority::Max)
.spawn_careless(|| {
// This is printed out from within the spawned thread.
println!("We don't care about the priority result.");
}).unwrap();
thread.join();
```

### Using ThreadExt trait on the current thread

```rust,no_run
use thread_priority::*;

assert!(std::thread::current().get_priority().is_ok());
println!("This thread's native id is: {:?}", std::thread::current().get_native_id());
```

## License
This project is [licensed under the MIT license](https://github.com/vityafx/thread-priority/blob/master/LICENSE).
Loading
Loading