Skip to content

Instantly share code, notes, and snippets.

@eholk
Created June 6, 2012 20:07
Show Gist options
  • Select an option

  • Save eholk/2884402 to your computer and use it in GitHub Desktop.

Select an option

Save eholk/2884402 to your computer and use it in GitHub Desktop.
task::spawn {|move lock2|
let lock = arc::get(&lock2);
(*lock).lock_cond {|c|
c.wait();
}
}
// lock should be a & reference to one of these:
resource lock_and_signal(lock: rust_cond_lock) {
rustrt::rust_destroy_cond_lock(lock);
}
@eholk

eholk commented Jun 6, 2012

Copy link
Copy Markdown
Author

More details:

impl methods for lock_and_signal {
    fn lock<T>(f: fn() -> T) -> T {
        rustrt::rust_lock_cond_lock(*self);
        let _r = unlock(*self);
        f()
    }

    fn lock_cond<T>(f: fn(condition) -> T) -> T {
        rustrt::rust_lock_cond_lock(*self);
        let _r = unlock(*self);
        f(condition_(*self))
    }
}

impl methods for condition {
    fn wait() {
        rustrt::rust_wait_cond_lock(*self);
    }

    fn signal() -> bool {
        rustrt::rust_signal_cond_lock(*self)
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment