Skip to content

Instantly share code, notes, and snippets.

@onevcat
Created May 22, 2014 04:30
Show Gist options
  • Save onevcat/9472fd86af5021bdecc9 to your computer and use it in GitHub Desktop.
Save onevcat/9472fd86af5021bdecc9 to your computer and use it in GitHub Desktop.
Workaround for Unity game slowing in iPhone4 + 7.1
//Workaround for Unity game slowing in iPhone4 + 7.1
//Write in main.mm
#include <pthread.h>
#include <dlfcn.h>
typedef int (*pthread_create_f)(pthread_t * __restrict, const pthread_attr_t * __restrict, void *(*)(void *), void * __restrict);
static pthread_create_f real_create = NULL;
extern "C" int pthread_create(pthread_t * __restrict thread, const pthread_attr_t * __restrict attr, void *(*start)(void *), void * __restrict arg)
{
int rc;
if (!real_create)
real_create = (pthread_create_f)dlsym(RTLD_NEXT, "pthread_create");
rc = (*real_create)(thread, attr, start, arg);
struct sched_param param;
int policy;
pthread_getschedparam(*thread, &policy, &param);
pthread_setschedparam(*thread, SCHED_FIFO, &param);
return rc;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment