My personal project and infrastructure archive
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
Katharina Fey d34f9be764
Cleaning up build files
6 months ago
..
src libkookie: sort tempset modules alphabetically 2 weeks ago
.envrc atomptr: init library with source from netmod-tcp 9 months ago
.gitignore atomptr: init library with source from netmod-tcp 9 months ago
.projectile libkookie: add .projectile files to existing projects 9 months ago
Cargo.toml atomptr: update repository link 7 months ago
LICENSE atomptr: init library with source from netmod-tcp 9 months ago
README.md atomptr: init library with source from netmod-tcp 9 months ago
shell.nix Cleaning up build files 6 months ago

README.md

AtomPtr

A safe, strongly typed (generic) atomic pointer abstraction to build datastructures, and lock-free algorithms on top of. Only uses libstd.

The standard library contains an AtomicPtr type, which by itself isn't very ergonomic to use, because it deals with raw pointers. This library assumes that types can always be heap allocated, wrapping them in a Box<T>, and provides a nicer (and safe!) abstraction for std::sync::atomic::AtomicPtr. Using this crate is fairely self-explanatory:

use atomptr::AtomPtr;

struct MyData { name: String }
let data = MyData { name: "Kookie".into() };

let a = AtomPtr::new(data);
println!("Name is: {}", a.get_ref().name);

let old_ref = a.swap(MyData { name: "Bob".into() });
println!("Name now is: {}, was {}", a.get_ref().name, old_ref.name);

Note that the type that is returned by get_ref and swap is Ref<T>, which means that the old data is not de-allocated after a swap, before this last reference goes out of scope. You can of course always manually call drop() on it.

License

This micro-library is free software, and licensed under the GNU General Public License, version 3.0 or (at your choice), any later version.

Additional Permissions: For Submission to the Apple App Store: Provided that you are otherwise in compliance with the GPLv3 for each covered work you convey (including without limitation making the Corresponding Source available in compliance with Section 6 of the GPLv3), the qaul.net developers also grant you the additional permission to convey through the Apple App Store non-source executable versions of the Program as incorporated into each applicable covered work as Executable Versions only under the Mozilla Public License version 2.0.

A copy of both the GPL-3.0 and MPL-2.0 license texts are included in this repository.