27 #include <pthread_np.h>
34 #include <sys/resource.h>
35 #include <sys/syscall.h>
39 #if defined(__LINUX__) || defined(__MACOSX__) || defined(__IPHONEOS__)
42 #define RTLD_DEFAULT NULL
47 #include "SDL_thread.h"
48 #include "../SDL_thread_c.h"
49 #include "../SDL_systhread.h"
51 #include "../../core/android/SDL_android.h"
58 SIGHUP, SIGINT, SIGQUIT, SIGPIPE, SIGALRM, SIGTERM, SIGCHLD, SIGWINCH,
73 #if defined(__MACOSX__) || defined(__IPHONEOS__)
75 static int (*ppthread_setname_np)(
const char*) =
NULL;
76 #elif defined(__LINUX__)
78 static int (*ppthread_setname_np)(pthread_t,
const char*) =
NULL;
86 #if defined(__MACOSX__) || defined(__IPHONEOS__) || defined(__LINUX__)
87 if (!checked_setname) {
88 void *fn = dlsym(RTLD_DEFAULT,
"pthread_setname_np");
89 #if defined(__MACOSX__) || defined(__IPHONEOS__)
90 ppthread_setname_np = (
int(*)(
const char*)) fn;
91 #elif defined(__LINUX__)
92 ppthread_setname_np = (
int(*)(pthread_t,
const char*)) fn;
99 if (pthread_attr_init(&type) != 0) {
100 return SDL_SetError(
"Couldn't initialize pthread attributes");
102 pthread_attr_setdetachstate(&type, PTHREAD_CREATE_JOINABLE);
106 return SDL_SetError(
"Not enough resources to create thread");
119 #if defined(__MACOSX__) || defined(__IPHONEOS__) || defined(__LINUX__)
121 if (ppthread_setname_np !=
NULL) {
122 #if defined(__MACOSX__) || defined(__IPHONEOS__)
123 ppthread_setname_np(name);
124 #elif defined(__LINUX__)
125 ppthread_setname_np(pthread_self(), name);
128 #elif HAVE_PTHREAD_SETNAME_NP
129 pthread_setname_np(pthread_self(), name);
130 #elif HAVE_PTHREAD_SET_NAME_NP
131 pthread_set_name_np(pthread_self(), name);
140 pthread_sigmask(SIG_BLOCK, &mask, 0);
142 #ifdef PTHREAD_CANCEL_ASYNCHRONOUS
146 pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, &oldstate);
170 if (setpriority(PRIO_PROCESS, syscall(SYS_gettid), value) < 0) {
178 struct sched_param sched;
180 pthread_t
thread = pthread_self();
182 if (pthread_getschedparam(thread, &policy, &sched) < 0) {
186 sched.sched_priority = sched_get_priority_min(policy);
188 sched.sched_priority = sched_get_priority_max(policy);
190 int min_priority = sched_get_priority_min(policy);
191 int max_priority = sched_get_priority_max(policy);
192 sched.sched_priority = (min_priority + (max_priority - min_priority) / 2);
194 if (pthread_setschedparam(thread, policy, &sched) < 0) {
204 pthread_join(thread->
handle, 0);
DECLSPEC SDL_threadID SDLCALL SDL_ThreadID(void)
GLint GLenum GLsizei GLsizei GLsizei GLint GLenum GLenum type
unsigned long SDL_threadID
static void * RunThread(void *data)
EGLImageKHR EGLint * name
int SDL_SYS_CreateThread(SDL_Thread *thread, void *args)
int Android_JNI_SetupThread(void)
void SDL_SYS_WaitThread(SDL_Thread *thread)
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
int SDL_SYS_SetThreadPriority(SDL_ThreadPriority priority)
DECLSPEC int SDLCALL SDL_SetError(const char *fmt,...)
static const int sig_list[]
#define SDL_assert(condition)
static SDL_Thread * thread
EGLSurface EGLint void ** value
GLint GLint GLint GLint GLint GLint GLint GLbitfield mask
void SDL_RunThread(void *data)
void SDL_SYS_SetupThread(const char *name)