Lines Matching full:lock
15 /// The number of shards per sharded lock. Must be a power of two.
18 /// A shard containing a single reader-writer lock.
20 /// The inner reader-writer lock.
21 lock: RwLock<()>, field
25 /// Write operations will lock each shard and store the guard here. These guards get dropped at
30 /// A sharded reader-writer lock.
32 /// This lock is equivalent to [`RwLock`], except read operations are faster and write operations
37 /// and lock it. Write operations need to lock all shards in succession.
39 /// By splitting the lock into shards, concurrent read operations will in most cases choose
43 /// The priority policy of the lock is dependent on the underlying operating system's
50 /// read operation, the lock will not be poisoned.
57 /// let lock = ShardedLock::new(5);
61 /// let r1 = lock.read().unwrap();
62 /// let r2 = lock.read().unwrap();
67 /// // However, only one write lock may be held.
69 /// let mut w = lock.write().unwrap();
72 /// } // Write lock is dropped here.
91 /// Creates a new sharded reader-writer lock.
98 /// let lock = ShardedLock::new(5);
105 lock: RwLock::new(()), in new()
114 /// Consumes this lock, returning the underlying data.
118 /// This method will return an error if the lock is poisoned. A lock gets poisoned when a write
126 /// let lock = ShardedLock::new(String::new());
128 /// let mut s = lock.write().unwrap();
131 /// assert_eq!(lock.into_inner().unwrap(), "modified");
146 /// Returns `true` if the lock is poisoned.
148 /// If another thread can still access the lock, it may become poisoned at any time. A `false`
158 /// let lock = Arc::new(ShardedLock::new(0));
159 /// let c_lock = lock.clone();
163 /// panic!(); // the lock gets poisoned
165 /// assert_eq!(lock.is_poisoned(), true);
168 self.shards[0].lock.is_poisoned() in is_poisoned()
173 /// Since this call borrows the lock mutably, no actual locking needs to take place.
177 /// This method will return an error if the lock is poisoned. A lock gets poisoned when a write
185 /// let mut lock = ShardedLock::new(0);
186 /// *lock.get_mut().unwrap() = 10;
187 /// assert_eq!(*lock.read().unwrap(), 10);
200 /// Attempts to acquire this lock with shared read access.
205 /// writers will acquire the lock first.
209 /// This method will return an error if the lock is poisoned. A lock gets poisoned when a write
217 /// let lock = ShardedLock::new(1);
219 /// match lock.try_read() {
230 match self.shards[shard_index].lock.try_read() { in try_read()
232 lock: self, in try_read()
238 lock: self, in try_read()
250 /// The calling thread will be blocked until there are no more writers which hold the lock.
251 /// There may be other readers currently inside the lock when this method returns. This method
253 /// or writers will acquire the lock first.
259 /// This method will return an error if the lock is poisoned. A lock gets poisoned when a write
264 /// This method might panic when called if the lock is already held by the current thread.
273 /// let lock = Arc::new(ShardedLock::new(1));
274 /// let c_lock = lock.clone();
276 /// let n = lock.read().unwrap();
290 match self.shards[shard_index].lock.read() { in read()
292 lock: self, in read()
297 lock: self, in read()
304 /// Attempts to acquire this lock with exclusive write access.
309 /// writers will acquire the lock first.
313 /// This method will return an error if the lock is poisoned. A lock gets poisoned when a write
321 /// let lock = ShardedLock::new(1);
323 /// let n = lock.read().unwrap();
326 /// assert!(lock.try_write().is_err());
332 // Write-lock each shard in succession. in try_write()
334 let guard = match shard.lock.try_write() { in try_write()
366 lock: self, in try_write()
372 lock: self, in try_write()
380 /// The calling thread will be blocked until there are no more writers which hold the lock.
381 /// There may be other readers currently inside the lock when this method returns. This method
383 /// or writers will acquire the lock first.
389 /// This method will return an error if the lock is poisoned. A lock gets poisoned when a write
394 /// This method might panic when called if the lock is already held by the current thread.
401 /// let lock = ShardedLock::new(1);
403 /// let mut n = lock.write().unwrap();
406 /// assert!(lock.try_read().is_err());
411 // Write-lock each shard in succession. in write()
413 let guard = match shard.lock.write() { in write()
432 lock: self, in write()
437 lock: self, in write()
484 lock: &'a ShardedLock<T>, field
495 unsafe { &*self.lock.value.get() } in deref()
502 .field("lock", &self.lock) in fmt()
515 lock: &'a ShardedLock<T>, field
524 for shard in self.lock.shards.iter().rev() { in drop()
537 .field("lock", &self.lock) in fmt()
552 unsafe { &*self.lock.value.get() } in deref()
558 unsafe { &mut *self.lock.value.get() } in deref_mut()
604 let mut indices = THREAD_INDICES.lock().unwrap(); in drop()
613 let mut indices = THREAD_INDICES.lock().unwrap();