Crates.io | instance-copy-on-write |
lib.rs | instance-copy-on-write |
version | 0.2.2 |
created_at | 2025-09-11 21:50:36.833617+00 |
updated_at | 2025-09-17 22:59:36.360103+00 |
description | A native Rust implementation of the glibc/libc syslog. |
homepage | |
repository | https://codeberg.org/4neko/instance-copy-on-write |
max_upload_size | |
id | 1834643 |
size | 110,709 |
The purpose of this crate to attempt to introduce a CoW method of syncing simpltanious data to shared memory between threads. The create is based on the crossbeam
and atomics
.
The pull requests are now supported because the repository was moved to Codeberg. The alternative way is to send patches over the email to patch[at]4neko.org.
In case if you would like to contribute the code, please use pull request. Your pull request should include:
Description of changes and why it is needed.
Test the pull request.
In case of you prefer email and patch files please consider the following:
For each feature or fix, please send patches separatly.
Please write what your patch is implementing or fixing.
I can read the code and I am able to understand it, so don't write a poem or essay in the description to the patches.
Please test your patch.
Can I use the MPL-2.0 licensed code (crate) in larger project licensed with more permissive license like BSD or MIT.
I want to distribute (outside my organization) executable programs or libraries that I have compiled from someone else's unchanged MPL-licensed source code, either standalone or part of a larger work. What do I have to do?
You must inform the recipients where they can get the source for the MPLed code in the executable program or library you are distributing (i.e., you must comply with Section 3.2). You may distribute any executables you create under a license of your choosing, as long as that license does not interfere with the recipients' rights to the source under the terms of the MPL.
Yes, MPL- and Apache-licensed code can be used with an MIT codebase (so in that sense, they are "compatible"). However, the MPL- / Apache-licensed code remains under its original license. (So although compatible, you cannot relicense someone else's MPL or Apache code into the MIT license.) This means that your final codebase will contain a mix of MPL, Apache, and MIT licensed code. As an example, MPL has weak copyleft, so if you modified an MPL file, that file (including your changes) must remain under the MPL license.
You should use this license if you are located in the EU which gives you more advantages over GPL because in case of any disputes, the license allows you to defend your rights in a European Union country, in this case it will be Spain. It has also been translated into all languages of the EU member states.
Matrix of EUPL compatible open source licences
EUPL-1.2
is incompatiable with GPL
according to GNU ORG
This is a free software license. By itself, it has a copyleft comparable to the GPL's, and incompatible with it.
v 0.2.2. Experimental.
Sources are available under: MPL-2.0 OR EUPL-1.2
There are three types of the locks:
read only borrow
Copy-on-Write writing and storing
exclusive lock
All borrowed instances are valid all the time before drop even if the CoW operation was performed.
After CoW operation completed successfully, all new borrowers will see new value, all previous borrows the previous value.
An exclusive lock can be peroformed only when the instance is not borrowed, the current thread which requests exclusive lock does not borrow the instance. During the exclusive lock no CoW operation is allowed.
It was designed for the short period borrows and locks.
┌─────────────────┐ ┌──────────────┐
│ │ │ start_*() │ ┌────────────────┐
│ borrow() │ │ *copy │ │ lock() │
│ │ │ *clone │ └───────┬────────┘
└───────┬─────────┘ │ *default │ │
│ │ *new │ ┌────────▼────────────┐
LOCKED ────────────── │ ─────────────────┐ └──────┬───────┘ │ ATOMIC │
┌───────▼──────────┐ │ │ │ set_status_PARK │
│ ATOMIC │ │ │ └────────┬────────────┘
│ set_status_borrow│ │ ┌───────▼───────┐ │
└───────┬──────────┘ │ │ R/W ops │ ┌─────── │ ────────────────────── LOCKED
│ │ │ │ │ ┌───────▼──────────────────┐ ┌─────────────────────────┐
┌──────▼────────┐ │ └───────┬───────┘ │ │ check_if │ │ deadlock │
│ │ │ │ │ │ curthread is borrowing ┼──► prevention │
│ CLONE │ │ │ │ │ │ │ NoCowGuardErr::Borrowed │
│ instance │ │ ┌──────▼───────┐ │ └───────┬──────────────────┘ └─────────────────────────┘
│ │ │ │ complete() │ │ │
└──────┬────────┘ │ │ │ │ │
│ │ └──────┬───────┘ │ │
│ │ │ │ ┌──────▼────────────┐
┌───────▼──────────┐ │ │ │ │ │
│ increase refs │ │ ┌───────▼────────────┐ │ │ wait_for │
└───────┬──────────┘ │ │ ATOMIC │ │ │ refs == 1 │
│ │ │ set_status_borrow │ │ │ │
│ │ └───────┬────────────┘ │ └──────┬────────────┘
┌───────▼──────────────┐ │ │ │ │
│ LOCAL_THREAD │ └─────────── │ ───────────┘ │
│ thread_borrow_inc │ ┌──────▼───────────┐ ┌─────▼────────────┐
└───────┬──────────────┘ │ replace_inner │ │ R/W opertaions │
│ │ with new val │ └─────┬────────────┘
│ └──────┬───────────┘ │
│ │ │
┌──────▼────────────┐ │ │
│ ATOMIC │ ┌─────▼──────────┐ ┌────▼───────────┐
│ set_status_OK │ │ drop_borrow │ │ check ├─────────────┐
└───────────────────┘ └─────┬──────────┘ │ is_poisoned() │ │
────────────────────────────────────┐ │ └────┬───────────┘ │
│ │ │ │
│ ┌───────▼────────┐ ┌───────▼─────────┐ ┌─────────▼────────────┐
│ │ ATOMIC │ │ ATOMIC │ │ ATOMIC │
│ │ set_status_OK │ │ set_status_OK │ │ set_status_POISONED │
│ │ │ └─────────────────┘ └──────────────────────┘
│ └────────────────┘
└─────────────────────────────────────────────────────────────────────────────────────
let val =
InstanceCopyOnWrite::new(TestStruct::new(1, 2));
// read only
let borrow1 = val.borrow().unwrap();
//..
drop(borrow1);
// ...
// copy on write
let mut transaction = val.start_copying().unwrap();
transaction.start = 5;
transaction.stop = 6;
// update
transaction.completed(false).unwrap();
// exclusive lock
let res = val.lock();
// ..
drop(val);