Get or create an in-process lock for a canonicalized repository path.
(&self, canonical_path: &Path)
| 48 | |
| 49 | /// Get or create an in-process lock for a canonicalized repository path. |
| 50 | async fn get_or_create_lock(&self, canonical_path: &Path) -> Arc<Mutex<()>> { |
| 51 | { |
| 52 | let locks = self.repo_locks.read().await; |
| 53 | if let Some(lock) = locks.get(canonical_path) { |
| 54 | return Arc::clone(lock); |
| 55 | } |
| 56 | } |
| 57 | |
| 58 | let mut locks = self.repo_locks.write().await; |
| 59 | |
| 60 | // Double-check: another task may have inserted while we waited for the write lock |
| 61 | if let Some(lock) = locks.get(canonical_path) { |
| 62 | return Arc::clone(lock); |
| 63 | } |
| 64 | |
| 65 | let new_lock = Arc::new(Mutex::new(())); |
| 66 | locks.insert(canonical_path.to_path_buf(), Arc::clone(&new_lock)); |
| 67 | new_lock |
| 68 | } |
| 69 | } |
| 70 | |
| 71 | impl Default for GitSyncManager { |