Skip to content

green: Add a helper macro for booting libgreen #13528

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

Closed
Closed
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
40 changes: 40 additions & 0 deletions src/libgreen/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,19 @@
//! }
//! ```
//!
//! The above code can also be shortened with a macro from libgreen.
//!
//! ```
//! #![feature(phase)]
//! #[phase(syntax)] extern crate green;
//!
//! green_start!(main)
//!
//! fn main() {
//! // run inside of a green pool
//! }
//! ```
//!
//! # Using a scheduler pool
//!
//! ```rust
Expand Down Expand Up @@ -229,6 +242,33 @@ pub mod sleeper_list;
pub mod stack;
pub mod task;

/// A helper macro for booting a program with libgreen
///
/// # Example
///
/// ```
/// #![feature(phase)]
/// #[phase(syntax)] extern crate green;
///
/// green_start!(main)
///
/// fn main() {
/// // running with libgreen
/// }
/// ```
#[macro_export]
macro_rules! green_start( ($f:ident) => (
mod __start {
extern crate green;
extern crate rustuv;

#[start]
fn start(argc: int, argv: **u8) -> int {
green::start(argc, argv, rustuv::event_loop, super::$f)
}
}
) )

/// Set up a default runtime configuration, given compiler-supplied arguments.
///
/// This function will block until the entire pool of M:N schedulers have
Expand Down