IdManager fix

This commit is contained in:
Nekotekina 2017-01-26 04:03:03 +03:00 committed by Ivan
parent 591a6c8671
commit ee173dc3a2
3 changed files with 31 additions and 48 deletions

View file

@ -737,12 +737,6 @@ struct fs_aio_thread : ppu_thread
struct fs_aio_manager struct fs_aio_manager
{ {
std::shared_ptr<fs_aio_thread> thread; std::shared_ptr<fs_aio_thread> thread;
fs_aio_manager()
: thread(idm::make_ptr<ppu_thread, fs_aio_thread>("FS AIO Thread", 500))
{
thread->run();
}
}; };
s32 cellFsAioInit(vm::cptr<char> mount_point) s32 cellFsAioInit(vm::cptr<char> mount_point)
@ -750,7 +744,13 @@ s32 cellFsAioInit(vm::cptr<char> mount_point)
cellFs.warning("cellFsAioInit(mount_point=%s)", mount_point); cellFs.warning("cellFsAioInit(mount_point=%s)", mount_point);
// TODO: create AIO thread (if not exists) for specified mount point // TODO: create AIO thread (if not exists) for specified mount point
fxm::get_always<fs_aio_manager>(); const auto m = fxm::make<fs_aio_manager>();
if (m)
{
m->thread = idm::make_ptr<ppu_thread, fs_aio_thread>("FS AIO Thread", 500);
m->thread->run();
}
return CELL_OK; return CELL_OK;
} }
@ -772,9 +772,14 @@ s32 cellFsAioRead(vm::ptr<CellFsAio> aio, vm::ptr<s32> id, fs_aio_cb_t func)
// TODO: detect mount point and send AIO request to the AIO thread of this mount point // TODO: detect mount point and send AIO request to the AIO thread of this mount point
const s32 xid = (*id = ++g_fs_aio_id); const auto m = fxm::get<fs_aio_manager>();
const auto m = fxm::get_always<fs_aio_manager>(); if (!m)
{
return CELL_ENXIO;
}
const s32 xid = (*id = ++g_fs_aio_id);
m->thread->cmd_list m->thread->cmd_list
({ ({
@ -793,9 +798,14 @@ s32 cellFsAioWrite(vm::ptr<CellFsAio> aio, vm::ptr<s32> id, fs_aio_cb_t func)
// TODO: detect mount point and send AIO request to the AIO thread of this mount point // TODO: detect mount point and send AIO request to the AIO thread of this mount point
const s32 xid = (*id = ++g_fs_aio_id); const auto m = fxm::get<fs_aio_manager>();
const auto m = fxm::get_always<fs_aio_manager>(); if (!m)
{
return CELL_ENXIO;
}
const s32 xid = (*id = ++g_fs_aio_id);
m->thread->cmd_list m->thread->cmd_list
({ ({

View file

@ -64,39 +64,18 @@ id_manager::id_map::pointer idm::allocate_id(std::pair<u32, u32> types, u32 base
return nullptr; return nullptr;
} }
id_manager::id_map::pointer idm::find_id(u32 type, u32 id)
{
auto& map = g_map[type];
const auto found = map.find(id);
return found == map.end() ? nullptr : std::addressof(*found);
}
id_manager::id_map::pointer idm::find_id(u32 type, u32 true_type, u32 id) id_manager::id_map::pointer idm::find_id(u32 type, u32 true_type, u32 id)
{ {
auto& map = g_map[type]; auto& map = g_map[type];
const auto found = map.find(id); const auto found = map.find(id);
return found == map.end() || found->first.type() != true_type ? nullptr : std::addressof(*found); if (found != map.end() && (type == true_type || found->first.type() == true_type))
{
return std::addressof(*found);
} }
std::shared_ptr<void> idm::delete_id(u32 type, u32 id) return nullptr;
{
auto& map = g_map[type];
const auto found = map.find(id);
std::shared_ptr<void> result;
if (found != map.end())
{
result = std::move(found->second);
map.erase(found);
}
return result;
} }
std::shared_ptr<void> idm::delete_id(u32 type, u32 true_type, u32 id) std::shared_ptr<void> idm::delete_id(u32 type, u32 true_type, u32 id)
@ -107,7 +86,7 @@ std::shared_ptr<void> idm::delete_id(u32 type, u32 true_type, u32 id)
std::shared_ptr<void> result; std::shared_ptr<void> result;
if (found != map.end() && found->first.type() == true_type) if (found != map.end() && (type == true_type || found->first.type() == true_type))
{ {
result = std::move(found->second); result = std::move(found->second);
map.erase(found); map.erase(found);

View file

@ -232,16 +232,10 @@ class idm
// Prepare new ID (returns nullptr if out of resources) // Prepare new ID (returns nullptr if out of resources)
static id_manager::id_map::pointer allocate_id(std::pair<u32, u32> types, u32 base, u32 step, u32 count); static id_manager::id_map::pointer allocate_id(std::pair<u32, u32> types, u32 base, u32 step, u32 count);
// Remove ID and return the object // Remove ID and return the object (additionally check true_type if not equal)
static std::shared_ptr<void> delete_id(u32 type, u32 id);
// Remove ID and return the object (check type)
static std::shared_ptr<void> delete_id(u32 type, u32 true_type, u32 id); static std::shared_ptr<void> delete_id(u32 type, u32 true_type, u32 id);
// Get ID // Get ID (additionally check true_type if not equal)
static id_manager::id_map::pointer find_id(u32 type, u32 id);
// Get ID (check type)
static id_manager::id_map::pointer find_id(u32 type, u32 true_type, u32 id); static id_manager::id_map::pointer find_id(u32 type, u32 true_type, u32 id);
// Allocate new ID and assign the object from the provider() // Allocate new ID and assign the object from the provider()
@ -267,7 +261,7 @@ class idm
} }
catch (...) catch (...)
{ {
delete_id(types.first, place->first.id()); delete_id(types.first, types.first, place->first.id());
throw; throw;
} }
} }
@ -488,7 +482,7 @@ public:
} }
// Get count of objects // Get count of objects
template<typename T, typename Get = T> template<typename T, typename Get = void>
static inline u32 get_count() static inline u32 get_count()
{ {
reader_lock lock(id_manager::g_mutex); reader_lock lock(id_manager::g_mutex);
@ -558,7 +552,7 @@ public:
func(*static_cast<Get*>(found->second.get())); func(*static_cast<Get*>(found->second.get()));
ptr = delete_id(get_type<T>(), id); ptr = delete_id(get_type<T>(), get_type<Get>(), id);
g_map[get_type<T>()].erase(id); g_map[get_type<T>()].erase(id);
} }
@ -595,7 +589,7 @@ public:
return result_type{{found->second, _ptr}, std::move(ret)}; return result_type{{found->second, _ptr}, std::move(ret)};
} }
ptr = delete_id(get_type<T>(), id); ptr = delete_id(get_type<T>(), get_type<Get>(), id);
g_map[get_type<T>()].erase(id); g_map[get_type<T>()].erase(id);
} }