SDL  2.0
SDL_systhread.c
Go to the documentation of this file.
1 /*
2  Simple DirectMedia Layer
3  Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
4 
5  This software is provided 'as-is', without any express or implied
6  warranty. In no event will the authors be held liable for any damages
7  arising from the use of this software.
8 
9  Permission is granted to anyone to use this software for any purpose,
10  including commercial applications, and to alter it and redistribute it
11  freely, subject to the following restrictions:
12 
13  1. The origin of this software must not be misrepresented; you must not
14  claim that you wrote the original software. If you use this software
15  in a product, an acknowledgment in the product documentation would be
16  appreciated but is not required.
17  2. Altered source versions must be plainly marked as such, and must not be
18  misrepresented as being the original software.
19  3. This notice may not be removed or altered from any source distribution.
20 */
21 #include "../../SDL_internal.h"
22 
23 #if SDL_THREAD_PSP
24 
25 /* PSP thread management routines for SDL */
26 
27 #include <stdio.h>
28 #include <stdlib.h>
29 
30 #include "SDL_error.h"
31 #include "SDL_thread.h"
32 #include "../SDL_systhread.h"
33 #include "../SDL_thread_c.h"
34 #include <pspkerneltypes.h>
35 #include <pspthreadman.h>
36 
37 
38 static int ThreadEntry(SceSize args, void *argp)
39 {
40  SDL_RunThread(*(void **) argp);
41  return 0;
42 }
43 
44 int SDL_SYS_CreateThread(SDL_Thread *thread, void *args)
45 {
46  SceKernelThreadInfo status;
47  int priority = 32;
48 
49  /* Set priority of new thread to the same as the current thread */
50  status.size = sizeof(SceKernelThreadInfo);
51  if (sceKernelReferThreadStatus(sceKernelGetThreadId(), &status) == 0) {
52  priority = status.currentPriority;
53  }
54 
55  thread->handle = sceKernelCreateThread(thread->name, ThreadEntry,
56  priority, thread->stacksize ? ((int) thread->stacksize) : 0x8000,
57  PSP_THREAD_ATTR_VFPU, NULL);
58  if (thread->handle < 0) {
59  return SDL_SetError("sceKernelCreateThread() failed");
60  }
61 
62  sceKernelStartThread(thread->handle, 4, &args);
63  return 0;
64 }
65 
66 void SDL_SYS_SetupThread(const char *name)
67 {
68  /* Do nothing. */
69 }
70 
72 {
73  return (SDL_threadID) sceKernelGetThreadId();
74 }
75 
76 void SDL_SYS_WaitThread(SDL_Thread *thread)
77 {
78  sceKernelWaitThreadEnd(thread->handle, NULL);
79  sceKernelDeleteThread(thread->handle);
80 }
81 
82 void SDL_SYS_DetachThread(SDL_Thread *thread)
83 {
84  /* !!! FIXME: is this correct? */
85  sceKernelDeleteThread(thread->handle);
86 }
87 
88 void SDL_SYS_KillThread(SDL_Thread *thread)
89 {
90  sceKernelTerminateDeleteThread(thread->handle);
91 }
92 
94 {
95  int value;
96 
97  if (priority == SDL_THREAD_PRIORITY_LOW) {
98  value = 19;
99  } else if (priority == SDL_THREAD_PRIORITY_HIGH) {
100  value = -10;
101  } else if (priority == SDL_THREAD_PRIORITY_TIME_CRITICAL) {
102  value = -20;
103  } else {
104  value = 0;
105  }
106 
107  return sceKernelChangeThreadPriority(sceKernelGetThreadId(),value);
108 
109 }
110 
111 #endif /* SDL_THREAD_PSP */
112 
113 /* vim: ts=4 sw=4
114  */
SDL_Thread::stacksize
size_t stacksize
Definition: SDL_thread_c.h:62
NULL
#define NULL
Definition: begin_code.h:164
SDL_RunThread
void SDL_RunThread(void *data)
Definition: SDL_thread.c:265
SDL_error.h
SDL_THREAD_PRIORITY_TIME_CRITICAL
@ SDL_THREAD_PRIORITY_TIME_CRITICAL
Definition: SDL_thread.h:63
SDL_ThreadID
SDL_threadID SDL_ThreadID(void)
Definition: SDL_systhread.c:48
SDL_THREAD_PRIORITY_HIGH
@ SDL_THREAD_PRIORITY_HIGH
Definition: SDL_thread.h:62
SDL_SYS_SetupThread
void SDL_SYS_SetupThread(const char *name)
Definition: SDL_systhread.c:42
SDL_SYS_WaitThread
void SDL_SYS_WaitThread(SDL_Thread *thread)
Definition: SDL_systhread.c:60
SDL_Thread
Definition: SDL_thread_c.h:55
SDL_THREAD_PRIORITY_LOW
@ SDL_THREAD_PRIORITY_LOW
Definition: SDL_thread.h:60
SDL_SYS_CreateThread
int SDL_SYS_CreateThread(SDL_Thread *thread, void *args)
Definition: SDL_systhread.c:35
SDL_Thread::name
char * name
Definition: SDL_thread_c.h:61
SDL_thread.h
name
GLuint const GLchar * name
Definition: SDL_opengl_glext.h:660
SDL_SYS_DetachThread
void SDL_SYS_DetachThread(SDL_Thread *thread)
Definition: SDL_systhread.c:66
SDL_SYS_SetThreadPriority
int SDL_SYS_SetThreadPriority(SDL_ThreadPriority priority)
Definition: SDL_systhread.c:54
SDL_threadID
unsigned long SDL_threadID
Definition: SDL_thread.h:49
value
GLsizei const GLfloat * value
Definition: SDL_opengl_glext.h:698
SDL_SetError
#define SDL_SetError
Definition: SDL_dynapi_overrides.h:30
SDL_Thread::handle
SYS_ThreadHandle handle
Definition: SDL_thread_c.h:57
SDL_ThreadPriority
SDL_ThreadPriority
Definition: SDL_thread.h:59