tma: first pass at TmaServiceManager

This commit is contained in:
Michael Scire 2018-12-05 04:16:48 -08:00
parent bb48e33074
commit bf7dc84893
11 changed files with 595 additions and 22 deletions

View file

@ -52,6 +52,11 @@ u32 TmaTaskList::GetNumSleepingTasks() const {
return count;
}
bool TmaTaskList::IsIdFree(u32 task_id) const {
std::scoped_lock<HosMutex> lk(this->lock);
return GetById(task_id) == nullptr;
}
bool TmaTaskList::SendPacket(bool connected, TmaPacket *packet) {
std::scoped_lock<HosMutex> lk(this->lock);
@ -112,6 +117,36 @@ bool TmaTaskList::ReceivePacket(TmaPacket *packet) {
return task != nullptr;
}
void TmaTaskList::CleanupDoneTasks() {
std::scoped_lock<HosMutex> lk(this->lock);
/* Clean up all tasks in Complete/Canceled state. */
for (u32 i = 0; i < TmaTask::NumPriorities; i++) {
auto it = this->tasks[i].begin();
while (it != this->tasks[i].end()) {
auto task = *it;
switch (task->GetState()) {
case TmaTaskState::InProgress:
it++;
break;
case TmaTaskState::Complete:
case TmaTaskState::Canceled:
it = this->tasks[i].erase(it);
if (task->GetOwnedByTaskList()) {
delete task;
} else {
task->Signal();
}
break;
default:
/* TODO: Panic to fatal? */
std::abort();
}
}
}
}
void TmaTaskList::Add(TmaTask *task) {
std::scoped_lock<HosMutex> lk(this->lock);