|
1 | 1 | module ThreadSafe |
2 | 2 | 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. |
4 | 5 | # |
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. |
9 | 14 | # |
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. |
12 | 19 | WRITE_LOCK = Mutex.new |
13 | 20 |
|
14 | 21 | def []=(key, value) |
|
0 commit comments