-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement From<Runtime(Ref)> for Thread{Local,Safe}
This allows the creation of ThreadLocal and ThreadSafe from the Runtime and RuntimeRef types. This is required for manual creation of actors using ActorFutureBuilder type and customer runtime.
- Loading branch information
1 parent
9aa893c
commit 1c7ee4a
Showing
4 changed files
with
73 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
//! Tests for the access module. | ||
use heph_rt::{Runtime, RuntimeRef, ThreadLocal, ThreadSafe}; | ||
|
||
use crate::util::{assert_send, assert_sync}; | ||
|
||
#[test] | ||
fn thread_safe_is_send_sync() { | ||
assert_send::<ThreadSafe>(); | ||
assert_sync::<ThreadSafe>(); | ||
} | ||
|
||
#[test] | ||
fn thread_local_from_runtime_ref() { | ||
let mut rt = Runtime::new().unwrap(); | ||
rt.run_on_workers(|runtime_ref| { | ||
let thread_local = ThreadLocal::from(runtime_ref); | ||
drop(thread_local); | ||
Ok::<_, !>(()) | ||
}) | ||
.unwrap(); | ||
} | ||
|
||
#[test] | ||
fn thread_local_deref_as_runtime_ref() { | ||
let mut rt = Runtime::new().unwrap(); | ||
rt.run_on_workers(|runtime_ref| { | ||
let mut thread_local = ThreadLocal::from(runtime_ref); | ||
let _runtime_ref: &mut RuntimeRef = &mut *thread_local; | ||
drop(thread_local); | ||
Ok::<_, !>(()) | ||
}) | ||
.unwrap(); | ||
} | ||
|
||
#[test] | ||
fn thread_safe_from_runtime() { | ||
let rt = Runtime::new().unwrap(); | ||
let thread_safe = ThreadSafe::from(&rt); | ||
drop(thread_safe); | ||
drop(rt); | ||
} | ||
|
||
#[test] | ||
fn thread_safe_from_runtime_ref() { | ||
let mut rt = Runtime::new().unwrap(); | ||
rt.run_on_workers(|runtime_ref| { | ||
let thread_safe = ThreadSafe::from(&runtime_ref); | ||
drop(thread_safe); | ||
Ok::<_, !>(()) | ||
}) | ||
.unwrap(); | ||
} |