File tree Expand file tree Collapse file tree 1 file changed +6
-8
lines changed
Expand file tree Collapse file tree 1 file changed +6
-8
lines changed Original file line number Diff line number Diff line change 11use lazy_static:: lazy_static;
22
33use std:: convert:: { AsRef , AsMut } ;
4+ use std:: cell:: RefCell ;
45use std:: collections:: HashMap ;
56use std:: sync:: Mutex ;
67use std:: sync:: atomic:: { AtomicBool , Ordering } ;
@@ -10,9 +11,9 @@ use crate::DType;
1011
1112static USE_POOL : AtomicBool = AtomicBool :: new ( true ) ;
1213thread_local ! {
13- static POOL : Mutex <MemoryPool > = {
14+ static POOL : RefCell <MemoryPool > = {
1415 let m = MemoryPool :: new( ) ;
15- Mutex :: new( m)
16+ RefCell :: new( m)
1617 } ;
1718}
1819
@@ -56,8 +57,7 @@ fn should_use_pool() -> bool {
5657pub fn allocate_vec ( size : usize ) -> MPVec {
5758 if should_use_pool ( ) {
5859 POOL . with ( |p| {
59- let mut pool = p. lock ( )
60- . expect ( "Error accessing memory pool!" ) ;
60+ let mut pool = p. borrow_mut ( ) ;
6161 pool. get ( size)
6262 } )
6363 } else {
@@ -67,17 +67,15 @@ pub fn allocate_vec(size: usize) -> MPVec {
6767
6868pub fn clear_pool ( ) {
6969 POOL . with ( |p| {
70- let mut pool = p. lock ( )
71- . expect ( "Error accessing memory pool!" ) ;
70+ let mut pool = p. borrow_mut ( ) ;
7271 pool. clear ( ) ;
7372 } ) ;
7473}
7574
7675fn return_vec ( v : Vec < DType > ) {
7776 if should_use_pool ( ) {
7877 POOL . with ( |p| {
79- let mut pool = p. lock ( )
80- . expect ( "Error accessing memory pool!" ) ;
78+ let mut pool = p. borrow_mut ( ) ;
8179 pool. ret ( v) ;
8280 } ) ;
8381 }
You can’t perform that action at this time.
0 commit comments