22 #include "../../SDL_internal.h" 28 #include <pthread_np.h> 35 #include <sys/resource.h> 36 #include <sys/syscall.h> 40 #include "../../core/linux/SDL_dbus.h" 43 #if defined(__LINUX__) || defined(__MACOSX__) || defined(__IPHONEOS__) 46 #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> 68 SIGHUP, SIGINT, SIGQUIT, SIGPIPE, SIGALRM, SIGTERM, SIGCHLD, SIGWINCH,
83 #if defined(__MACOSX__) || defined(__IPHONEOS__) 85 static int (*ppthread_setname_np)(
const char*) =
NULL;
86 #elif defined(__LINUX__) 88 static int (*ppthread_setname_np)(pthread_t,
const char*) =
NULL;
96 #if defined(__MACOSX__) || defined(__IPHONEOS__) || defined(__LINUX__) 97 if (!checked_setname) {
98 void *fn = dlsym(RTLD_DEFAULT,
"pthread_setname_np");
99 #if defined(__MACOSX__) || defined(__IPHONEOS__) 100 ppthread_setname_np = (int(*)(
const char*)) fn;
101 #elif defined(__LINUX__) 102 ppthread_setname_np = (int(*)(pthread_t,
const char*)) fn;
109 if (pthread_attr_init(&type) != 0) {
110 return SDL_SetError(
"Couldn't initialize pthread attributes");
112 pthread_attr_setdetachstate(&type, PTHREAD_CREATE_JOINABLE);
116 pthread_attr_setstacksize(&type, (
size_t) thread->
stacksize);
121 return SDL_SetError(
"Not enough resources to create thread");
130 #if !defined(__NACL__) 136 #if defined(__MACOSX__) || defined(__IPHONEOS__) || defined(__LINUX__) 138 if (ppthread_setname_np !=
NULL) {
139 #if defined(__MACOSX__) || defined(__IPHONEOS__) 140 ppthread_setname_np(name);
141 #elif defined(__LINUX__) 142 ppthread_setname_np(pthread_self(), name);
145 #elif HAVE_PTHREAD_SETNAME_NP 146 #if defined(__NETBSD__) 147 pthread_setname_np(pthread_self(),
"%s", name);
149 pthread_setname_np(pthread_self(), name);
151 #elif HAVE_PTHREAD_SET_NAME_NP 152 pthread_set_name_np(pthread_self(), name);
153 #elif defined(__HAIKU__) 155 char namebuf[B_OS_NAME_LENGTH];
157 namebuf[
sizeof (namebuf) - 1] =
'\0';
158 rename_thread(find_thread(
NULL), namebuf);
163 #if !defined(__NACL__) 169 pthread_sigmask(SIG_BLOCK, &mask, 0);
173 #ifdef PTHREAD_CANCEL_ASYNCHRONOUS 177 pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, &oldstate);
196 pid_t thread = syscall(SYS_gettid);
209 struct sched_param sched;
211 pthread_t thread = pthread_self();
213 if (pthread_getschedparam(thread, &policy, &sched) != 0) {
217 sched.sched_priority = sched_get_priority_min(policy);
219 sched.sched_priority = sched_get_priority_max(policy);
221 int min_priority = sched_get_priority_min(policy);
222 int max_priority = sched_get_priority_max(policy);
223 sched.sched_priority = (min_priority + (max_priority - min_priority) / 2);
225 sched.sched_priority += ((max_priority - min_priority) / 4);
228 if (pthread_setschedparam(thread, policy, &sched) != 0) {
238 pthread_join(thread->
handle, 0);
244 pthread_detach(thread->
handle);
static void * RunThread(void *data)
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
#define SDL_LinuxSetThreadPriority
GLuint const GLchar * name
int Android_JNI_SetupThread(void)
SDL_threadID SDL_ThreadID(void)
void SDL_SYS_WaitThread(SDL_Thread *thread)
int SDL_SYS_SetThreadPriority(SDL_ThreadPriority priority)
GLsizei const GLfloat * value
void SDL_SYS_DetachThread(SDL_Thread *thread)
static const int sig_list[]
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)
#define SDL_assert(condition)
void SDL_RunThread(void *data)
void SDL_SYS_SetupThread(const char *name)
GLuint GLuint GLsizei GLenum type
int SDL_SYS_CreateThread(SDL_Thread *thread, void *args)
unsigned long SDL_threadID