21 #include "../../SDL_internal.h"
29 #include <pthread_np.h>
36 #include <sys/resource.h>
37 #include <sys/syscall.h>
41 #include "../../core/linux/SDL_dbus.h"
44 #if defined(__LINUX__) || defined(__MACOSX__) || defined(__IPHONEOS__)
47 #define RTLD_DEFAULT NULL
53 #include "../SDL_thread_c.h"
54 #include "../SDL_systhread.h"
56 #include "../../core/android/SDL_android.h"
60 #include <kernel/OS.h>
67 SIGHUP, SIGINT, SIGQUIT, SIGPIPE, SIGALRM, SIGTERM, SIGCHLD, SIGWINCH,
82 #if defined(__MACOSX__) || defined(__IPHONEOS__)
84 static int (*ppthread_setname_np)(
const char*) =
NULL;
85 #elif defined(__LINUX__)
87 static int (*ppthread_setname_np)(pthread_t,
const char*) =
NULL;
95 #if defined(__MACOSX__) || defined(__IPHONEOS__) || defined(__LINUX__)
96 if (!checked_setname) {
97 void *fn = dlsym(RTLD_DEFAULT,
"pthread_setname_np");
98 #if defined(__MACOSX__) || defined(__IPHONEOS__)
99 ppthread_setname_np = (
int(*)(
const char*)) fn;
100 #elif defined(__LINUX__)
101 ppthread_setname_np = (
int(*)(pthread_t,
const char*)) fn;
108 if (pthread_attr_init(&
type) != 0) {
109 return SDL_SetError(
"Couldn't initialize pthread attributes");
111 pthread_attr_setdetachstate(&
type, PTHREAD_CREATE_JOINABLE);
120 return SDL_SetError(
"Not enough resources to create thread");
129 #if !defined(__NACL__)
135 #if defined(__MACOSX__) || defined(__IPHONEOS__) || defined(__LINUX__)
137 if (ppthread_setname_np !=
NULL) {
138 #if defined(__MACOSX__) || defined(__IPHONEOS__)
139 ppthread_setname_np(
name);
140 #elif defined(__LINUX__)
141 ppthread_setname_np(pthread_self(),
name);
144 #elif HAVE_PTHREAD_SETNAME_NP
145 #if defined(__NETBSD__)
146 pthread_setname_np(pthread_self(),
"%s",
name);
148 pthread_setname_np(pthread_self(),
name);
150 #elif HAVE_PTHREAD_SET_NAME_NP
151 pthread_set_name_np(pthread_self(),
name);
152 #elif defined(__HAIKU__)
154 char namebuf[B_OS_NAME_LENGTH];
156 namebuf[
sizeof (namebuf) - 1] =
'\0';
157 rename_thread(find_thread(
NULL), namebuf);
162 #if !defined(__NACL__)
168 pthread_sigmask(SIG_BLOCK, &
mask, 0);
172 #ifdef PTHREAD_CANCEL_ASYNCHRONOUS
176 pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, &oldstate);
195 extern DECLSPEC int SDLCALL SDL_LinuxSetThreadPriorityAndPolicy(
Sint64 threadID,
int sdlPriority,
int schedPolicy);
201 #if __NACL__ || __RISCOS__
205 struct sched_param sched;
208 pthread_t thread = pthread_self();
212 if (pthread_getschedparam(thread, &
policy, &sched) != 0) {
222 pri_policy = SCHED_OTHER;
226 #if defined(__MACOSX__) || defined(__IPHONEOS__) || defined(__TVOS__)
228 pri_policy = SCHED_RR;
231 pri_policy = SCHED_OTHER;
240 pri_policy = SCHED_RR;
246 }
else if (
SDL_strcmp(policyhint,
"other") == 0) {
248 }
else if (
SDL_strcmp(policyhint,
"rr") == 0) {
250 }
else if (
SDL_strcmp(policyhint,
"fifo") == 0) {
261 pid_t linuxTid = syscall(SYS_gettid);
262 return SDL_LinuxSetThreadPriorityAndPolicy(linuxTid, priority,
policy);
266 sched.sched_priority = sched_get_priority_min(
policy);
268 sched.sched_priority = sched_get_priority_max(
policy);
270 int min_priority = sched_get_priority_min(
policy);
271 int max_priority = sched_get_priority_max(
policy);
273 #if defined(__MACOSX__) || defined(__IPHONEOS__) || defined(__TVOS__)
274 if (min_priority == 15 && max_priority == 47) {
277 sched.sched_priority = 45;
279 sched.sched_priority = 37;
284 sched.sched_priority = (min_priority + (max_priority - min_priority) / 2);
286 sched.sched_priority += ((max_priority - min_priority) / 4);
290 if (pthread_setschedparam(thread,
policy, &sched) != 0) {
301 pthread_join(thread->
handle, 0);
307 pthread_detach(thread->
handle);
int Android_JNI_SetupThread(void)
#define SDL_assert(condition)
#define SDL_GetHintBoolean
#define SDL_HINT_THREAD_PRIORITY_POLICY
A string specifying additional information to use with SDL_SetThreadPriority.
#define SDL_HINT_THREAD_FORCE_REALTIME_TIME_CRITICAL
Specifies whether SDL_THREAD_PRIORITY_TIME_CRITICAL should be treated as realtime.
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
GLuint GLuint GLsizei GLenum type
GLuint const GLchar * name
void SDL_RunThread(SDL_Thread *thread)
unsigned long SDL_threadID
@ SDL_THREAD_PRIORITY_TIME_CRITICAL
@ SDL_THREAD_PRIORITY_LOW
@ SDL_THREAD_PRIORITY_HIGH
@ SDL_THREAD_PRIORITY_NORMAL
return Display return Display Bool Bool int int int return Display XEvent Bool(*) XPointer return Display return Display Drawable _Xconst char unsigned int unsigned int return Display Pixmap Pixmap XColor XColor unsigned int unsigned int return Display _Xconst char char int char return Display Visual unsigned int int int char unsigned int unsigned int in i)
void SDL_SYS_SetupThread(const char *name)
int SDL_SYS_CreateThread(SDL_Thread *thread)
void SDL_SYS_DetachThread(SDL_Thread *thread)
int SDL_SYS_SetThreadPriority(SDL_ThreadPriority priority)
void SDL_SYS_WaitThread(SDL_Thread *thread)
SDL_threadID SDL_ThreadID(void)
static const int sig_list[]
static void * RunThread(void *data)
typedef int(__stdcall *FARPROC)()