remove GILProtected

This commit is contained in:
Nikolay Kim 2017-06-14 14:15:29 -07:00
parent fdf971c54e
commit b67954fd19
1 changed files with 0 additions and 58 deletions

View File

@ -119,61 +119,3 @@ impl GILGuard {
unsafe { Python::assume_gil_acquired() }
}
}
/// Mutex-like wrapper object for data that is protected by the Python GIL.
///
/// # Example
/// ```
/// use std::cell::Cell;
/// use pyo3::{Python, GILProtected};
///
/// let data = GILProtected::new(Cell::new(0));
///
/// {
/// let gil_guard = Python::acquire_gil();
/// let cell = data.get(gil_guard.python());
/// cell.set(cell.get() + 1);
/// }
/// ```
pub struct GILProtected<T> {
data: T
}
unsafe impl<T: Send> Send for GILProtected<T> { }
/// Because `GILProtected` ensures that the contained data
/// is only accessed while the GIL is acquired,
/// it can implement `Sync` even if the contained data
/// does not.
unsafe impl<T: Send> Sync for GILProtected<T> { }
impl <T> GILProtected<T> {
/// Creates a new instance of `GILProtected`.
#[inline]
#[cfg(feature="nightly")]
pub const fn new(data: T) -> GILProtected<T> {
GILProtected { data: data }
}
/// Creates a new instance of `GILProtected`.
#[inline]
#[cfg(not(feature="nightly"))]
pub fn new(data: T) -> GILProtected<T> {
GILProtected { data: data }
}
/// Returns a shared reference to the data stored in the `GILProtected`.
///
/// Requires a `Python` instance as proof that the GIL is acquired.
#[inline]
pub fn get<'a>(&'a self, _py: Python<'a>) -> &'a T {
&self.data
}
/// Consumes the `GILProtected`, returning the wrapped value.
#[inline]
pub fn into_inner(self) -> T {
self.data
}
}