Skip to content

Commit

Permalink
Change async priority to current thread'priority if priority = -1.
Browse files Browse the repository at this point in the history
  • Loading branch information
shenweip committed Jan 3, 2020
1 parent 458f8cf commit 44660bd
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 24 deletions.
39 changes: 17 additions & 22 deletions Core/HLE/ThreadQueueList.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,8 @@
#include "Common/ChunkFile.h"

struct ThreadQueueList {
//
static const int INDEX_OFFSET = 1;
// Number of queues (number of priority levels starting at 0.)
static const int NUM_QUEUES = 128 + INDEX_OFFSET;
static const int NUM_QUEUES = 128;
// Initial number of threads a single queue can handle.
static const int INITIAL_CAPACITY = 32;

Expand Down Expand Up @@ -59,9 +57,6 @@ struct ThreadQueueList {
~ThreadQueueList() {
clear();
}
inline int getQueueIdxwithOffset(u32 priority) {
return priority + INDEX_OFFSET;
}

// Only for debugging, returns priority level.
int contains(const SceUID uid) {
Expand All @@ -72,7 +67,7 @@ struct ThreadQueueList {
Queue *cur = &queues[i];
for (int j = cur->first; j < cur->end; ++j) {
if (cur->data[j] == uid)
return i - INDEX_OFFSET;
return i;
}
}

Expand All @@ -94,7 +89,7 @@ struct ThreadQueueList {
inline SceUID pop_first_better(u32 priority) {
Queue *cur = first;
// Don't bother looking past (worse than) this priority.
Queue *stop = &queues[getQueueIdxwithOffset(priority)];
Queue *stop = &queues[priority];
while (cur < stop) {
if (cur->size() > 0)
return cur->data[cur->first++];
Expand All @@ -116,22 +111,22 @@ struct ThreadQueueList {
}

inline void push_front(u32 priority, const SceUID threadID) {
Queue *cur = &queues[getQueueIdxwithOffset(priority)];
Queue *cur = &queues[priority];
cur->data[--cur->first] = threadID;
// If we ran out of room toward the front, add more room for next time.
if (cur->first == 0)
rebalance(priority);
}

inline void push_back(u32 priority, const SceUID threadID) {
Queue *cur = &queues[getQueueIdxwithOffset(priority)];
Queue *cur = &queues[priority];
cur->data[cur->end++] = threadID;
if (cur->full())
rebalance(priority);
}

inline void remove(u32 priority, const SceUID threadID) {
Queue *cur = &queues[getQueueIdxwithOffset(priority)];
Queue *cur = &queues[priority];
_dbg_assert_msg_(SCEKERNEL, cur->next != nullptr, "ThreadQueueList::Queue should already be linked up.");

for (int i = cur->first; i < cur->end; ++i) {
Expand All @@ -152,7 +147,7 @@ struct ThreadQueueList {
}

inline void rotate(u32 priority) {
Queue *cur = &queues[getQueueIdxwithOffset(priority)];
Queue *cur = &queues[priority];
_dbg_assert_msg_(SCEKERNEL, cur->next != nullptr, "ThreadQueueList::Queue should already be linked up.");

if (cur->size() > 1) {
Expand All @@ -172,13 +167,13 @@ struct ThreadQueueList {
first = invalid();
}

inline bool empty(u32 priority) {
const Queue *cur = &queues[getQueueIdxwithOffset(priority)];
inline bool empty(u32 priority) const {
const Queue *cur = &queues[priority];
return cur->empty();
}

inline void prepare(u32 priority) {
Queue *cur = &queues[getQueueIdxwithOffset(priority)];
Queue *cur = &queues[priority];
if (cur->next == nullptr)
link(priority, INITIAL_CAPACITY);
}
Expand Down Expand Up @@ -227,7 +222,7 @@ struct ThreadQueueList {

// Initialize a priority level and link to other queues.
void link(u32 priority, int size) {
_dbg_assert_msg_(SCEKERNEL, queues[getQueueIdxwithOffset(priority)].data == nullptr, "ThreadQueueList::Queue should only be initialized once.");
_dbg_assert_msg_(SCEKERNEL, queues[priority].data == nullptr, "ThreadQueueList::Queue should only be initialized once.");

// Make sure we stay a multiple of INITIAL_CAPACITY.
if (size <= INITIAL_CAPACITY)
Expand All @@ -240,19 +235,19 @@ struct ThreadQueueList {
}

// Allocate the queue.
Queue *cur = &queues[getQueueIdxwithOffset(priority)];
Queue *cur = &queues[priority];
cur->data = (SceUID *)malloc(sizeof(SceUID) * size);
cur->capacity = size;
// Start smack in the middle so it can move both directions.
cur->first = size / 2;
cur->end = size / 2;

for (int i = (int)priority - 1; i >= -1; --i) {
for (int i = (int)priority - 1; i >= 0; --i) {
// This queue is before ours, and points past us.
// We'll have it point to our new queue, inserting into the chain.
if (queues[getQueueIdxwithOffset(i)].next != nullptr) {
cur->next = queues[getQueueIdxwithOffset(i)].next;
queues[getQueueIdxwithOffset(i)].next = cur;
if (queues[i].next != nullptr) {
cur->next = queues[i].next;
queues[i].next = cur;
return;
}
}
Expand All @@ -265,7 +260,7 @@ struct ThreadQueueList {

// Move or allocate as necessary to maintain free space on both sides.
void rebalance(u32 priority) {
Queue *cur = &queues[getQueueIdxwithOffset(priority)];
Queue *cur = &queues[priority];
int size = cur->size();
// Basically full. Time for a larger queue?
if (size >= cur->capacity - 2) {
Expand Down
5 changes: 4 additions & 1 deletion Core/HLE/sceIo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1967,7 +1967,7 @@ static u32 sceIoChdir(const char *dirname) {
}

static int sceIoChangeAsyncPriority(int id, int priority) {
// priority = -1 is valid
// priority = -1 is valid,means the current thread'priority
if (priority != -1 && (priority < 0x08 || priority > 0x77)) {
return hleLogError(SCEIO, SCE_KERNEL_ERROR_ILLEGAL_PRIORITY, "illegal priority %d", priority);
}
Expand All @@ -1977,6 +1977,9 @@ static int sceIoChangeAsyncPriority(int id, int priority) {
return hleLogSuccessI(SCEIO, 0);
}

if (priority == -1)
priority = KernelCurThreadPriority();

u32 error;
FileNode *f = __IoGetFd(id, error);
if (!f) {
Expand Down
6 changes: 5 additions & 1 deletion Core/Loaders.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,11 @@ bool UmdReplace(std::string filepath, char *error) {
case IdentifiedFileType::PSP_ISO:
case IdentifiedFileType::PSP_ISO_NP:
case IdentifiedFileType::PSP_DISC_DIRECTORY:
ReInitMemoryForGameISO(loadedFile);
if (!ReInitMemoryForGameISO(loadedFile)) {
error = "reinit memory failed";
return false;
}

break;
default:
sprintf(error, "Unsupported file type: %i", type);
Expand Down

0 comments on commit 44660bd

Please sign in to comment.