gchp / rustbox

Rust implementation of the termbox library
MIT License
469 stars 48 forks source link

Make RustBox threadsafe. #8

Closed pythonesque closed 9 years ago

pythonesque commented 9 years ago

This is the first part of changes to iota. Unfortunately, TermBox itself is not very thread safe.

It is possible that it is thread safe to use it as we were using it before (sort of--I could produce double free assertions pretty easily with the latest version). That is, it may be that polling events on one thread and doing all drawing on another is threadsafe. But it would require careful inspection of the code to determine, and Rust currently lacks a great way of representing that safely that will work equally well in single and multithreaded situations (that is, I don't want single threaded users to deadlock because they accidentally dropped the two components in the wrong order!) I know how to make it work nicely, but it will require &mut references to be Send, which isn't yet possible, which is why I changed iota to be single threaded for now.

In the process, this also makes the wrapper much nicer in general. It now uses RAII to properly deallocate TermBox resources, ensures that you can only ever have one RustBox handle in the program, changes panic!s to Results, uses bitflags, etc.

pythonesque commented 9 years ago

"Rebased". It was actually a lot easier to just manually reapply the changes than try to figure out the merge :P

gchp commented 9 years ago

Left a few comments inline, looks great!