File tree Expand file tree Collapse file tree 1 file changed +9
-11
lines changed
src/aero_kernel/src/mem/paging Expand file tree Collapse file tree 1 file changed +9
-11
lines changed Original file line number Diff line number Diff line change 17
17
* along with Aero. If not, see <https://www.gnu.org/licenses/>.
18
18
*/
19
19
20
+ use core:: sync:: atomic:: { AtomicUsize , Ordering } ;
21
+
20
22
use alloc:: vec:: Vec ;
21
23
use bit_field:: BitField ;
22
24
use spin:: Once ;
@@ -538,35 +540,31 @@ pub fn get_vm_frames() -> Option<&'static Vec<VmFrame>> {
538
540
VM_FRAMES . get ( )
539
541
}
540
542
541
- struct VmFrameInner {
542
- use_count : usize ,
543
- }
544
-
545
543
pub struct VmFrame {
546
- lock : Mutex < VmFrameInner > ,
544
+ ref_count : AtomicUsize ,
547
545
}
548
546
549
547
impl VmFrame {
550
548
fn new ( ) -> Self {
551
549
Self {
552
- lock : Mutex :: new ( VmFrameInner { use_count : 0 } ) ,
550
+ ref_count : AtomicUsize :: new ( 0 ) ,
553
551
}
554
552
}
555
553
556
554
pub fn dec_ref_count ( & self ) {
557
- let mut this = self . lock . lock ( ) ;
555
+ let ref_count = self . ref_count . load ( Ordering :: SeqCst ) ;
558
556
559
- if this . use_count > 0 {
560
- this . use_count -= 1 ;
557
+ if ref_count != 0 {
558
+ self . ref_count . store ( ref_count - 1 , Ordering :: SeqCst ) ;
561
559
}
562
560
}
563
561
564
562
pub fn inc_ref_count ( & self ) {
565
- self . lock . lock ( ) . use_count += 1 ;
563
+ self . ref_count . fetch_add ( 1 , Ordering :: SeqCst ) ;
566
564
}
567
565
568
566
pub fn ref_count ( & self ) -> usize {
569
- self . lock . lock ( ) . use_count
567
+ self . ref_count . load ( Ordering :: SeqCst )
570
568
}
571
569
}
572
570
You can’t perform that action at this time.
0 commit comments