sonic-pi

https://github.com/sonic-pi-net/sonic-pi

C++

Code. Music. Live.

ThreadSafe::AtomicReferenceCacheBackend#internal_replace

Internal versions of the insertion methods, each a
little more complicated than the last. All have
the same basic structure:
 1. If table uninitialized, create
 2. If bin empty, try to CAS new node
 3. If bin stale, use new table
 4. Lock and validate; if valid, scan and add or update

The others interweave other checks and/or alternative actions:
 * Plain +get_and_set+ checks for and performs resize after insertion.
 * compute_if_absent prescans for mapping without lock (and fails to add
   if present), which also makes pre-emptive resize checks worthwhile.

Someday when details settle down a bit more, it might be worth
some factoring to reduce sprawl.

Source | Google | Stack overflow

Edit

git clone [email protected]:sonic-pi-net/sonic-pi.git

cd sonic-pi

open app/server/ruby/vendor/thread_safe/lib/thread_safe/atomic_reference_cache_backend.rb

Contribute

# Make a new branch

git checkout -b -your-name--update-docs-ThreadSafe--AtomicReferenceCacheBackend-internal_replace-for-pr


# Commit to git

git add app/server/ruby/vendor/thread_safe/lib/thread_safe/atomic_reference_cache_backend.rbgit commit -m "better docs for ThreadSafe::AtomicReferenceCacheBackend#internal_replace"


# Open pull request

gem install hub # on a mac you can `brew install hub`

hub fork

git push <your name> -your-name--update-docs-ThreadSafe--AtomicReferenceCacheBackend-internal_replace-for-pr

hub pull-request


# Celebrate!