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 1717 * along with Aero. If not, see <https://www.gnu.org/licenses/>.
1818 */
1919
20+ use core:: sync:: atomic:: { AtomicUsize , Ordering } ;
21+
2022use alloc:: vec:: Vec ;
2123use bit_field:: BitField ;
2224use spin:: Once ;
@@ -538,35 +540,31 @@ pub fn get_vm_frames() -> Option<&'static Vec<VmFrame>> {
538540 VM_FRAMES . get ( )
539541}
540542
541- struct VmFrameInner {
542- use_count : usize ,
543- }
544-
545543pub struct VmFrame {
546- lock : Mutex < VmFrameInner > ,
544+ ref_count : AtomicUsize ,
547545}
548546
549547impl VmFrame {
550548 fn new ( ) -> Self {
551549 Self {
552- lock : Mutex :: new ( VmFrameInner { use_count : 0 } ) ,
550+ ref_count : AtomicUsize :: new ( 0 ) ,
553551 }
554552 }
555553
556554 pub fn dec_ref_count ( & self ) {
557- let mut this = self . lock . lock ( ) ;
555+ let ref_count = self . ref_count . load ( Ordering :: SeqCst ) ;
558556
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 ) ;
561559 }
562560 }
563561
564562 pub fn inc_ref_count ( & self ) {
565- self . lock . lock ( ) . use_count += 1 ;
563+ self . ref_count . fetch_add ( 1 , Ordering :: SeqCst ) ;
566564 }
567565
568566 pub fn ref_count ( & self ) -> usize {
569- self . lock . lock ( ) . use_count
567+ self . ref_count . load ( Ordering :: SeqCst )
570568 }
571569}
572570
You can’t perform that action at this time.
0 commit comments