Skip to content
This repository was archived by the owner on Mar 15, 2022. It is now read-only.

Commit f321ee8

Browse files
committed
Merge pull request #8 from rranelli/use-yard-for-documentation
Use yard for documentation
2 parents 1649896 + dd97283 commit f321ee8

File tree

14 files changed

+404
-243
lines changed

14 files changed

+404
-243
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
.bundle
55
.config
66
/.idea
7-
.yardoc
7+
.yardoc/*
8+
yardoc/*
89
Gemfile.lock
910
InstalledFiles
1011
_yardoc

.yardopts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
--protected
2+
--no-private
3+
--embed-mixins
4+
--output-dir ./yardoc
5+
--markup markdown
6+
--title=Concurrent Ruby
7+
--template default
8+
--template-path ./yard-template
9+
10+
./lib/**/*.rb
11+
-
12+
README.md
13+
LICENSE

Gemfile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,11 @@ source 'https://rubygems.org'
22

33
# Specify your gem's dependencies in thread_safe.gemspec
44
gemspec
5+
6+
group :documentation do
7+
gem 'countloc', '~> 0.4.0', :platforms => :mri, :require => false
8+
gem 'rubycritic', '~> 1.0.2', :platforms => :mri, require: false
9+
gem 'yard', '~> 0.8.7.4', :require => false
10+
gem 'inch', '~> 0.4.6', :platforms => :mri, :require => false
11+
gem 'redcarpet', '~> 3.1.2', platforms: :mri # understands github markdown
12+
end

lib/thread_safe/atomic_reference_cache_backend.rb

Lines changed: 154 additions & 168 deletions
Large diffs are not rendered by default.

lib/thread_safe/mri_cache_backend.rb

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,21 @@
11
module ThreadSafe
22
class MriCacheBackend < NonConcurrentCacheBackend
3-
# We can get away with a single global write lock (instead of a per-instance one) because of the GVL/green threads.
3+
# We can get away with a single global write lock (instead of a per-instance
4+
# one) because of the GVL/green threads.
45
#
5-
# The previous implementation used `Thread.critical` on 1.8 MRI to implement the 4 composed atomic operations (`put_if_absent`, `replace_pair`,
6-
# `replace_if_exists`, `delete_pair`) this however doesn't work for `compute_if_absent` because on 1.8 the Mutex class is itself implemented
7-
# via `Thread.critical` and a call to `Mutex#lock` does not restore the previous `Thread.critical` value (thus any synchronisation clears the
8-
# `Thread.critical` flag and we loose control). This poses a problem as the provided block might use synchronisation on its own.
6+
# The previous implementation used `Thread.critical` on 1.8 MRI to implement
7+
# the 4 composed atomic operations (`put_if_absent`, `replace_pair`,
8+
# `replace_if_exists`, `delete_pair`) this however doesn't work for
9+
# `compute_if_absent` because on 1.8 the Mutex class is itself implemented
10+
# via `Thread.critical` and a call to `Mutex#lock` does not restore the
11+
# previous `Thread.critical` value (thus any synchronisation clears the
12+
# `Thread.critical` flag and we loose control). This poses a problem as the
13+
# provided block might use synchronisation on its own.
914
#
10-
# NOTE: a neat idea of writing a c-ext to manually perform atomic put_if_absent, while relying on Ruby not releasing a GVL while calling
11-
# a c-ext will not work because of the potentially Ruby implemented `#hash` and `#eql?` key methods.
15+
# NOTE: a neat idea of writing a c-ext to manually perform atomic
16+
# put_if_absent, while relying on Ruby not releasing a GVL while calling a
17+
# c-ext will not work because of the potentially Ruby implemented `#hash`
18+
# and `#eql?` key methods.
1219
WRITE_LOCK = Mutex.new
1320

1421
def []=(key, value)

lib/thread_safe/non_concurrent_cache_backend.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
module ThreadSafe
22
class NonConcurrentCacheBackend
3-
# WARNING: all public methods of the class must operate on the @backend directly without calling each other. This is important
4-
# because of the SynchronizedCacheBackend which uses a non-reentrant mutex for perfomance reasons.
3+
# WARNING: all public methods of the class must operate on the @backend
4+
# directly without calling each other. This is important because of the
5+
# SynchronizedCacheBackend which uses a non-reentrant mutex for perfomance
6+
# reasons.
57
def initialize(options = nil)
68
@backend = {}
79
end

lib/thread_safe/synchronized_cache_backend.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ module ThreadSafe
22
class SynchronizedCacheBackend < NonConcurrentCacheBackend
33
require 'mutex_m'
44
include Mutex_m
5-
# WARNING: Mutex_m is a non-reentrant lock, so the synchronized methods are not allowed to call each other.
5+
# WARNING: Mutex_m is a non-reentrant lock, so the synchronized methods are
6+
# not allowed to call each other.
67

78
def [](key)
89
synchronize { super }

lib/thread_safe/synchronized_delegator.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
# array = SynchronizedDelegator.new([]) # thread-safe
1010
#
1111
# A simple `Monitor` provides a very coarse-grained way to synchronize a given
12-
# object, in that it will cause synchronization for methods that have no
13-
# need for it, but this is a trivial way to get thread-safety where none may
14-
# exist currently on some implementations.
12+
# object, in that it will cause synchronization for methods that have no need
13+
# for it, but this is a trivial way to get thread-safety where none may exist
14+
# currently on some implementations.
1515
#
1616
# This class is currently being considered for inclusion into stdlib, via
1717
# https://bugs.ruby-lang.org/issues/8556

lib/thread_safe/util/adder.rb

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
module ThreadSafe
22
module Util
3-
# A Ruby port of the Doug Lea's jsr166e.LondAdder class version 1.8 available in public domain.
4-
# Original source code available here: http://gee.cs.oswego.edu/cgi-bin/viewcvs.cgi/jsr166/src/jsr166e/LongAdder.java?revision=1.8
3+
# A Ruby port of the Doug Lea's jsr166e.LondAdder class version 1.8
4+
# available in public domain.
5+
#
6+
# Original source code available here:
7+
# http://gee.cs.oswego.edu/cgi-bin/viewcvs.cgi/jsr166/src/jsr166e/LongAdder.java?revision=1.8
58
#
69
# One or more variables that together maintain an initially zero
710
# sum. When updates (method +add+) are contended across threads,

lib/thread_safe/util/cheap_lockable.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
module ThreadSafe
22
module Util
3-
# Provides a cheapest possible (mainly in terms of memory usage) +Mutex+ with the +ConditionVariable+ bundled in.
3+
# Provides a cheapest possible (mainly in terms of memory usage) +Mutex+
4+
# with the +ConditionVariable+ bundled in.
45
#
56
# Usage:
67
# class A

0 commit comments

Comments
 (0)