mars-research / redleaf

RedLeaf Operating System
118 stars 10 forks source link

Implement `sleep()` #7

Closed tjhu closed 4 years ago

tjhu commented 4 years ago

Implement a Rust equivalent of sleep() in xv6. This is tricky because one cannot lock/unlock a lock in arbitrary places in Rust. A condition variable is probably the closet thing to it, but it requires us to implement our own mutex, our own condition variable, and get them right.

Plan 1

Implement our own std::sync::{Mutex, CondVar}. Maybe we can fork the Mutex from the spin crate, implement CondVar on top of it, and call it for the day. It would be nice to implement it without any unsafe. Here's how it's implemented in Rust stdlib.

tjhu commented 4 years ago

CondVar is implemented in https://github.com/mars-research/redleaf/blob/118864ae2150f2e621cfc0acd3c9fd369e5c8522/src/sync/condvar.rs

Userspace sleepmutex wrapper is implemented here https://github.com/mars-research/redleaf/blob/118864ae2150f2e621cfc0acd3c9fd369e5c8522/sys/lib/libsyscalls/src/sync/sleepmutex.rs