mirror of
				https://github.com/PabloMK7/citra.git
				synced 2025-11-04 07:38:47 +00:00 
			
		
		
		
	Kernel: New handle manager
This handle manager more closely mirrors the behaviour of the CTR-OS one. In addition object ref-counts and support for DuplicateHandle have been added. Note that support for DuplicateHandle is still experimental, since parts of the kernel still use Handles internally, which will likely cause troubles if two different handles to the same object are used to e.g. wait on a synchronization primitive.
This commit is contained in:
		
							parent
							
								
									23f2142009
								
							
						
					
					
						commit
						7e2903cb74
					
				
					 13 changed files with 229 additions and 188 deletions
				
			
		| 
						 | 
				
			
			@ -133,7 +133,7 @@ public:
 | 
			
		|||
        case FileCommand::Close:
 | 
			
		||||
        {
 | 
			
		||||
            LOG_TRACE(Service_FS, "Close %s %s", GetTypeName().c_str(), GetName().c_str());
 | 
			
		||||
            Kernel::g_handle_table.Destroy<File>(GetHandle());
 | 
			
		||||
            backend->Close();
 | 
			
		||||
            break;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -189,7 +189,7 @@ public:
 | 
			
		|||
        case DirectoryCommand::Close:
 | 
			
		||||
        {
 | 
			
		||||
            LOG_TRACE(Service_FS, "Close %s %s", GetTypeName().c_str(), GetName().c_str());
 | 
			
		||||
            Kernel::g_handle_table.Destroy<Directory>(GetHandle());
 | 
			
		||||
            backend->Close();
 | 
			
		||||
            break;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -283,7 +283,8 @@ ResultVal<Handle> OpenFileFromArchive(ArchiveHandle archive_handle, const FileSy
 | 
			
		|||
    }
 | 
			
		||||
 | 
			
		||||
    auto file = Common::make_unique<File>(std::move(backend), path);
 | 
			
		||||
    Handle handle = Kernel::g_handle_table.Create(file.release());
 | 
			
		||||
    // TOOD(yuriks): Fix error reporting
 | 
			
		||||
    Handle handle = Kernel::g_handle_table.Create(file.release()).ValueOr(INVALID_HANDLE);
 | 
			
		||||
    return MakeResult<Handle>(handle);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -388,7 +389,8 @@ ResultVal<Handle> OpenDirectoryFromArchive(ArchiveHandle archive_handle, const F
 | 
			
		|||
    }
 | 
			
		||||
 | 
			
		||||
    auto directory = Common::make_unique<Directory>(std::move(backend), path);
 | 
			
		||||
    Handle handle = Kernel::g_handle_table.Create(directory.release());
 | 
			
		||||
    // TOOD(yuriks): Fix error reporting
 | 
			
		||||
    Handle handle = Kernel::g_handle_table.Create(directory.release()).ValueOr(INVALID_HANDLE);
 | 
			
		||||
    return MakeResult<Handle>(handle);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -56,7 +56,8 @@ Manager::~Manager() {
 | 
			
		|||
 | 
			
		||||
/// Add a service to the manager (does not create it though)
 | 
			
		||||
void Manager::AddService(Interface* service) {
 | 
			
		||||
    m_port_map[service->GetPortName()] = Kernel::g_handle_table.Create(service);
 | 
			
		||||
    // TOOD(yuriks): Fix error reporting
 | 
			
		||||
    m_port_map[service->GetPortName()] = Kernel::g_handle_table.Create(service).ValueOr(INVALID_HANDLE);
 | 
			
		||||
    m_services.push_back(service);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -54,7 +54,8 @@ public:
 | 
			
		|||
 | 
			
		||||
    /// Allocates a new handle for the service
 | 
			
		||||
    Handle CreateHandle(Kernel::Object *obj) {
 | 
			
		||||
        Handle handle = Kernel::g_handle_table.Create(obj);
 | 
			
		||||
        // TODO(yuriks): Fix error reporting
 | 
			
		||||
        Handle handle = Kernel::g_handle_table.Create(obj).ValueOr(INVALID_HANDLE);
 | 
			
		||||
        m_handles.push_back(handle);
 | 
			
		||||
        return handle;
 | 
			
		||||
    }
 | 
			
		||||
| 
						 | 
				
			
			@ -62,7 +63,7 @@ public:
 | 
			
		|||
    /// Frees a handle from the service
 | 
			
		||||
    template <class T>
 | 
			
		||||
    void DeleteHandle(const Handle handle) {
 | 
			
		||||
        Kernel::g_handle_table.Destroy<T>(handle);
 | 
			
		||||
        Kernel::g_handle_table.Close(handle);
 | 
			
		||||
        m_handles.erase(std::remove(m_handles.begin(), m_handles.end(), handle), m_handles.end());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue