Take a snapshot to accumulate writes until they are committed. Take a write-lock on the data if necessary, but beware it doesn't work well with STM.
(&self)
| 96 | /// Take a snapshot to accumulate writes until they are committed. |
| 97 | /// Take a write-lock on the data if necessary, but beware it doesn't work well with STM. |
| 98 | fn write(&self) -> Self::Tx<'_> { |
| 99 | // Take this lock first, otherwise we might be blocking `data` from anyone being able to commit. |
| 100 | let token = if self.lock_writes { |
| 101 | Some(self.write_token.lock().unwrap()) |
| 102 | } else { |
| 103 | None |
| 104 | }; |
| 105 | Transaction { |
| 106 | backend: self, |
| 107 | data: self.data.lock().unwrap().clone(), |
| 108 | token, |
| 109 | _mode: Write, |
| 110 | } |
| 111 | } |
| 112 | } |
| 113 | |
| 114 | /// A transaction that can be read-only with no write lock taken, |
no outgoing calls