Add some dummy code

This commit is contained in:
Pierre Krieger 2015-11-13 12:05:14 +01:00
parent 54b3e1025d
commit 179c3d6dae
3 changed files with 61 additions and 2 deletions

View File

@ -0,0 +1,26 @@
use lock;
unsafe trait BufferLock {
unsafe fn get_id(&self) -> u64;
}
impl<T> BufferLock for T where T: lock::Lock<Buffer> {
}
pub struct Buffer {
id: ,
}
unsafe impl BufferLock for Buffer {
#[inline]
unsafe fn get_id(&self) -> u64 {
self.id
}
}
impl Drop for Buffer {
fn drop(&mut self) {
error::check_result(unsafe { ffi::grDestroyBuffer(self.id) }).unwrap();
}
}

View File

@ -1,3 +1,4 @@
use buffer::BufferLock;
/// Represents a prototype of a command buffer.
///
@ -24,7 +25,7 @@ pub struct CommandBufferBuilder {
device: Arc<Device>,
cmd: Option<ffi::GR_CMD_BUFFER>,
memory_refs: Vec<ffi::GR_MEMORY_REF>,
buffers: Vec<Arc<Buffer>>,
buffers: Vec<Arc<BufferLock>>,
images: Vec<Arc<Image>>,
pipelines: Vec<Arc<Pipeline>>,
}
@ -85,7 +86,7 @@ pub struct CommandBuffer {
device: Arc<Device>,
cmd: ffi::GR_CMD_BUFFER,
memory_refs: Vec<ffi::GR_MEMORY_REF>,
buffers: Vec<Arc<Buffer>>,
buffers: Vec<Arc<BufferLock>>,
images: Vec<Arc<Image>>,
pipelines: Vec<Arc<Pipeline>>,
}

32
src/lock.rs Normal file
View File

@ -0,0 +1,32 @@
use std::sync;
use Fence;
/// Defines a strategy for read-write access and relation with fences.
pub trait Lock<T> {
fn shared_access(&self);
fn exclusive_access(&self);
fn shared_access_until(&self, Fence);
fn exclusive_access_until(&self, Fence);
}
pub struct Mutex<T> {
inner: sync::Mutex<T>,
fence: Option<Fence>,
}
impl<T> Mutex<T> {
pub fn lock(&self) -> Result<MutexLock<T>, MutexlockError> {
self.fence.wait();
let inner = try!(self.inner.lock());
}
}
impl<T> Lock<T> for Mutex<T> {
}
pub struct MutexLock<'a, T> {
inner: sync::LockGuard<'a, T>,
}