File tree Expand file tree Collapse file tree 1 file changed +9
-3
lines changed
crates/oxc_allocator/src/pool Expand file tree Collapse file tree 1 file changed +9
-3
lines changed Original file line number Diff line number Diff line change @@ -72,7 +72,8 @@ impl FixedSizeAllocatorPool {
7272 /// # Panics
7373 /// * Panics if the underlying mutex is poisoned.
7474 pub fn get ( & self ) -> Allocator {
75- // Try to get an allocator from the pool
75+ // Try to get an allocator from the pool.
76+ // This is in a block, so that `Mutex` lock is held for the shortest possible time.
7677 let maybe_allocator = {
7778 let mut allocators = self . allocators . lock ( ) . unwrap ( ) ;
7879 allocators. pop ( )
@@ -88,6 +89,7 @@ impl FixedSizeAllocatorPool {
8889
8990 // Pool cannot produce another allocator. Wait for an existing allocator to be returned to the pool.
9091 loop {
92+ // This is in a block, so that `Mutex` lock is held for the shortest possible time
9193 let maybe_allocator = {
9294 let mut allocators = self . available . wait ( self . allocators . lock ( ) . unwrap ( ) ) . unwrap ( ) ;
9395 allocators. pop ( )
@@ -140,8 +142,12 @@ impl FixedSizeAllocatorPool {
140142 FixedSizeAllocator { allocator : ManuallyDrop :: new ( allocator) } ;
141143 fixed_size_allocator. reset ( ) ;
142144
143- let mut allocators = self . allocators . lock ( ) . unwrap ( ) ;
144- allocators. push ( fixed_size_allocator) ;
145+ // This is in a block, so that `Mutex` lock is held for the shortest possible time
146+ {
147+ let mut allocators = self . allocators . lock ( ) . unwrap ( ) ;
148+ allocators. push ( fixed_size_allocator) ;
149+ }
150+
145151 self . available . notify_one ( ) ;
146152 }
147153}
You can’t perform that action at this time.
0 commit comments