-
-
Notifications
You must be signed in to change notification settings - Fork 52
aipc, an async ipc library for aero #60
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
pitust
wants to merge
2
commits into
Andy-Python-Programmer:master
Choose a base branch
from
pitust:aipc
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
[workspace] | ||
members = ["apps/*", "servers/*"] | ||
members = ["apps/*", "servers/*", "libs/*"] | ||
|
||
[profile.release] | ||
debug = true |
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,12 @@ | ||
[package] | ||
name = "aipc_test" | ||
version = "0.1.0" | ||
edition = "2021" | ||
authors = ["pitust <[email protected]>"] | ||
|
||
[dependencies] | ||
std = { path = "../../libs/aero_std" } | ||
aero_syscall = { path = "../../../src/aero_syscall" } | ||
aipc = { path = "../../libs/aipc" } | ||
postcard = { version = "0.7.3", features = ["alloc"] } | ||
spin = "0.9" |
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,98 @@ | ||
/* | ||
* Copyright (C) 2021-2022 The Aero Project Developers. | ||
* | ||
* This file is part of The Aero Project. | ||
* | ||
* Aero is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* Aero is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with Aero. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
use core::sync::atomic::{AtomicUsize, Ordering, AtomicBool}; | ||
|
||
use aero_syscall::{sys_fork, sys_exit}; | ||
use aipc::async_runtime::Listener; | ||
|
||
#[aipc::def("TestObj")] | ||
trait TestObj { | ||
async fn create() -> TestObj; | ||
async fn foo(&self); | ||
async fn kill(&self); | ||
} | ||
#[aipc::def("ServerControlObj")] | ||
trait ServerControlObj { | ||
async fn create() -> ServerControlObj; | ||
async fn can_control(&self) -> bool; | ||
async fn quit(&self); | ||
} | ||
|
||
static COUNTER: AtomicUsize = AtomicUsize::new(1); | ||
|
||
struct NoData { | ||
data: usize, | ||
} | ||
|
||
#[aipc::object(TestObjSrv as TestObj)] | ||
impl NoData { | ||
fn create() -> NoData { | ||
return NoData { | ||
data: COUNTER.fetch_add(1, Ordering::SeqCst), | ||
}; | ||
} | ||
fn foo(&self) { | ||
println!("Hello from obj {}!", self.data); | ||
} | ||
} | ||
|
||
static SCS_PERMIT_ONCE: AtomicBool = AtomicBool::new(true); | ||
pub struct ServerControlState { | ||
permitted: bool | ||
} | ||
#[aipc::object(ServerControlSrv as ServerControlObj)] | ||
impl ServerControlState { | ||
pub fn create() -> ServerControlState { | ||
return ServerControlState { | ||
permitted: SCS_PERMIT_ONCE.swap(false, Ordering::SeqCst) | ||
}; | ||
} | ||
pub fn can_control(&self) -> bool { | ||
self.permitted | ||
} | ||
pub fn quit(&self) { | ||
if self.permitted { | ||
println!("[ServerControlSrv] exiting!"); | ||
aipc::async_runtime::spawn(async { | ||
sys_exit(0); | ||
}); | ||
} | ||
} | ||
} | ||
|
||
|
||
fn main() { | ||
let mut rt = aipc::async_runtime::AsyncRuntime::new(); | ||
rt.spawn(async { | ||
let pid = sys_fork().unwrap(); | ||
if pid == 0 { | ||
// server | ||
ServerControlSrv::listen(); | ||
TestObjSrv::listen(); | ||
} else { | ||
// client | ||
let ctl = ServerControlObj::create(pid).await; | ||
let o = TestObj::create(pid).await; | ||
o.foo().await; | ||
ctl.quit().await; | ||
sys_exit(0); | ||
} | ||
}); | ||
rt.run(); | ||
} |
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 |
---|---|---|
|
@@ -7,5 +7,5 @@ authors = ["Anhad Singh <[email protected]>"] | |
[dependencies] | ||
std = { path = "../../libs/aero_std" } | ||
aero_syscall = { path = "../../../src/aero_syscall" } | ||
aero_ipc = { path = "../../libs/aero_ipc" } | ||
aipc = { path = "../../libs/aipc" } | ||
utest-proc = { path = "../utest-proc" } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of constructing a runtime manually at the start of the main function, it would be a much cleaner idea to initialize it lazily in the spawn function instead. So it will look like
apic::spawn(async {})
. In future we; after we get the rust userland port sorted out we can switch to usingtokio
as our async runtime.