Skip to content

Instantly share code, notes, and snippets.

@smirn0v
Created June 20, 2014 13:55
Show Gist options
  • Save smirn0v/4031d38e7a6b70a8795a to your computer and use it in GitHub Desktop.
Save smirn0v/4031d38e7a6b70a8795a to your computer and use it in GitHub Desktop.
magic
typedef int (*pthread_create_f)(pthread_t * __restrict, const pthread_attr_t * __restrict,
void *(*)(void *), void * __restrict);
static pthread_create_f real_create = NULL;
#include <pthread.h>
#include <dlfcn.h>
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