From 96f2d860e40c1439de998d47f74fd859e24de352 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Wed, 20 Mar 2013 14:08:48 -0700 Subject: [PATCH] Revert thread optimization, appears to have broken things. Fixes #1033. This reverts commit ea91632ff5539b356f62bc2c97f3b90290ede703 and commit 543dfcd4d80c93f311c36bc2f0d98757ddd476d5. --- Core/HLE/sceKernelThread.cpp | 58 +++++++++++------------------------- 1 file changed, 17 insertions(+), 41 deletions(-) diff --git a/Core/HLE/sceKernelThread.cpp b/Core/HLE/sceKernelThread.cpp index 763c63676b..5bc7745a35 100644 --- a/Core/HLE/sceKernelThread.cpp +++ b/Core/HLE/sceKernelThread.cpp @@ -431,39 +431,37 @@ public: u32 stackBlock; }; +// std::vector with push_front(), remove(), etc. struct ThreadList { - static const int START_PAD = 0x10; - static const int MIN_PAD = 0x04; - size_t start; std::vector list; - ThreadList() : start(START_PAD) - { - list.resize(START_PAD); - } - inline bool empty() const { - return start == list.size(); + return list.empty(); } inline size_t size() const { - return list.size() - start; + return list.size(); } inline SceUID &front() { - return list[start]; + return list.front(); } inline void push_front(const SceUID threadID) { - if (start > 0) - list[--start] = threadID; + if (empty()) + push_back(threadID); else - list.insert(list.begin(), threadID); + { + size_t oldSize = list.size(); + list.resize(oldSize + 1); + memmove(&list[1], &list[0], oldSize * sizeof(SceUID)); + list[0] = threadID; + } } inline void push_back(const SceUID threadID) @@ -473,46 +471,24 @@ struct ThreadList inline void pop_front() { - ++start; + size_t newSize = list.size() - 1; + list.resize(newSize); + if (newSize > 0) + memmove(&list[0], &list[1], newSize * sizeof(SceUID)); } inline void pop_back() { list.pop_back(); - rebalance(); } inline void remove(const SceUID threadID) { - if (empty()) - return; - if (front() == threadID) - { - ++start; - return; - } - - auto new_end = std::remove(list.begin(), list.end(), threadID); - if (new_end == list.end()) - return; - - list.erase(new_end, list.end()); - rebalance(); - } - - inline void rebalance() - { - if (list.size() < MIN_PAD) - { - size_t diff = START_PAD - list.size(); - start += diff; - list.insert(list.begin(), diff, 0); - } + list.erase(std::remove(list.begin(), list.end(), threadID), list.end()); } void DoState(PointerWrap &p) { - p.Do(start); p.Do(list); } };