Skip to content
This repository has been archived by the owner on Nov 26, 2020. It is now read-only.

Commit

Permalink
Pulled native into mainloop
Browse files Browse the repository at this point in the history
There is no runtime system in the standard library now (see
[Rust issue #17325] (rust-lang/rust#17325)),
so the original separation of code specific to the native runtime
has lost its purpose.
  • Loading branch information
mzabaluev committed Nov 23, 2014
1 parent 0f65ed7 commit 99dd120
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 109 deletions.
6 changes: 1 addition & 5 deletions src/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,11 @@ use gtype::GType;

use error;
use mainloop;
use native;
use quark;

pub type GError = error::raw::GError;

pub type GMainContext = mainloop::MainContext;

pub type GMainLoop = native::MainLoop;

pub type GMainLoop = mainloop::MainLoop;
pub type GQuark = quark::Quark;

#[repr(C)]
Expand Down
1 change: 0 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ pub mod error;
pub mod gtype;
pub mod mainloop;
pub mod marker;
pub mod native;
pub mod object;
pub mod quark;
pub mod refcount;
Expand Down
80 changes: 80 additions & 0 deletions src/mainloop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ use ffi;
use marker;
use refcount::Refcount;
use refcount::{RefcountFuncs,RefFunc,UnrefFunc};
use types::FALSE;

use std::kinds::marker as std_marker;

#[repr(C)]
pub struct MainContext {
Expand Down Expand Up @@ -47,3 +50,80 @@ impl Refcount for MainContext {
&MAIN_CONTEXT_REF_FUNCS
}
}

#[repr(C)]
pub struct MainLoop {
marker: marker::SyncObjectMarker
}

pub struct LoopRunner {
l: *mut MainLoop,

// Can't send the runner around due to the thread default stuff
no_send: std_marker::NoSend
}

impl LoopRunner {
pub fn new() -> LoopRunner {
unsafe {
let ctx = ffi::g_main_context_new();
let l = ffi::g_main_loop_new(ctx, FALSE);
ffi::g_main_context_unref(ctx);

LoopRunner { l: l, no_send: std_marker::NoSend }
}
}

pub fn run_after(&self, setup: |&mut MainLoop|) {
unsafe {
let ctx = ffi::g_main_loop_get_context(self.l);
ffi::g_main_context_push_thread_default(ctx);

setup(&mut *self.l);

ffi::g_main_loop_run(self.l);

ffi::g_main_context_pop_thread_default(ctx);
}
}
}

#[unsafe_destructor]
impl Drop for LoopRunner {
fn drop(&mut self) {
unsafe {
ffi::g_main_loop_unref(self.l);
}
}
}

impl MainLoop {

pub fn get_context<'a>(&'a mut self) -> &'a mut MainContext {
unsafe {
&mut *ffi::g_main_loop_get_context(self)
}
}

pub fn quit(&mut self) {
unsafe {
ffi::g_main_loop_quit(self);
}
}
}

type MainLoopRefFunc = unsafe extern "C" fn(p: *mut ffi::GMainLoop) -> *mut ffi::GMainLoop;
type MainLoopUnrefFunc = unsafe extern "C" fn(p: *mut ffi::GMainLoop);

static MAIN_LOOP_REF_FUNCS: RefcountFuncs = (
&ffi::g_main_loop_ref
as *const MainLoopRefFunc as *const RefFunc,
&ffi::g_main_loop_unref
as *const MainLoopUnrefFunc as *const UnrefFunc
);

impl Refcount for MainLoop {
fn refcount_funcs(&self) -> &'static RefcountFuncs {
&MAIN_LOOP_REF_FUNCS
}
}
103 changes: 0 additions & 103 deletions src/native.rs

This file was deleted.

0 comments on commit 99dd120

Please sign in to comment.