Crate instance_copy_on_write

Crate instance_copy_on_write 

Source
Expand description

An experimental thread access synchronization primitive which is based on CoW Copy-on-Write and also exclusive lock.

By default an RwLock based implementation is used, because the atomics based implementation is still not ready. It can be activated by enabling the feature prefer_atomic.

feature = prefer_atomic

The ICoWRead<DATA> instance with inner value DATA obtained from the ICoW<DATA> is valid even after the inner value was copied and copy was commited back. All readers which will will read the ICoW instance after the commit will receive a ICoWRead<DATA> with updated DATA.

Exclusive copying prevents readers from reading while simple non-exclusive copy allows to access the inner data for reading and further copying. But, the non-exclusive copies are not in sync, so each copy is uniq. The sequential commit of copied data is not yet supported.

The experimental cow_refcell.rs was added to support single-thread mode pure CoW model which is not really usefull, but this is a path to the future async implementation.

  • 
    let val = 
        ICoW::new(TestStruct::new(1, 2));
    
    // read only 
    let read1 = val.read();
    //..
    drop(read1);
    
    // ...
    
    // copy on write NON-exclusively, read is possible
    let mut transaction = val.clone_copy();
    
    transaction.start = 5;
    transaction.stop = 6;
    
    // update, after calling this function, all reades who 
    // read before will still see old version.
    // all reades after, new
    transaction.commit();
    //or
    drop(transaction); // to drop changes
    
    
    // exclusive lock, read is also not possible
    
    let res = val.clone_exclusivly();
    // ..
    // commit changes releasing lock
    commit(val); //or
    drop(val); // to drop changes and release lock
    

Re-exports§

pub use cow_mutex::ICoW;
pub use cow_mutex::ICoWRead;
pub use cow_mutex::ICoWCopy;
pub use cow_mutex::ICoWLock;

Modules§

cow_mutex
A RwLock based copy-on-write.
cow_refcell

Enums§

ICoWError
Errors which may be returned.
ICoWLockTypes
Type of the sync code.

Traits§

ICowType