Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 21 additions & 17 deletions PlayTools/PlayLoader.m
Original file line number Diff line number Diff line change
Expand Up @@ -281,25 +281,29 @@ static int pt_usleep(useconds_t time) {
if ([[PlaySettings shared] blockSleepSpamming]) {
int thread_id = pthread_mach_thread_np(pthread_self());
NSNumber *threadKey = @(thread_id);

int thread_sleep_counter = [thread_sleep_counters[threadKey] intValue];
int last_sleep_attempt = [last_sleep_attempts[threadKey] intValue];

if (time == 100000) {
int timestamp = (int)[[NSDate date] timeIntervalSince1970];
// If it sleeps too fast, increase counter
if (timestamp - last_sleep_attempt < 2) {
thread_sleep_counter++;
} else {
thread_sleep_counter = 1;

BOOL exceeded_sleep_limit = NO;
@synchronized (thread_sleep_counters) {
int thread_sleep_counter = [thread_sleep_counters[threadKey] intValue];
int last_sleep_attempt = [last_sleep_attempts[threadKey] intValue];

if (time == 100000) {
int timestamp = (int)[[NSDate date] timeIntervalSince1970];
// If it sleeps too fast, increase counter
if (timestamp - last_sleep_attempt < 2) {
thread_sleep_counter++;
} else {
thread_sleep_counter = 1;
}
last_sleep_attempt = timestamp;
thread_sleep_counters[threadKey] = @(thread_sleep_counter);
last_sleep_attempts[threadKey] = @(last_sleep_attempt);
}
last_sleep_attempt = timestamp;
thread_sleep_counters[threadKey] = @(thread_sleep_counter);
last_sleep_attempts[threadKey] = @(last_sleep_attempt);


exceeded_sleep_limit = thread_sleep_counter > 100;
}
if (thread_sleep_counter > 100) {

if (exceeded_sleep_limit) {
// Stop this thread from spamming usleep calls
NSLog(@"[PC] Thread %i exceeded usleep limit. Seem sus, stopping this "
@"thread FOREVER",
Expand Down
Loading