zenilib  0.5.3.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
SDL_systhread.c
Go to the documentation of this file.
1 /*
2  Simple DirectMedia Layer
3  Copyright (C) 1997-2013 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 
22 
23 /* PSP thread management routines for SDL */
24 
25 #include <stdio.h>
26 #include <stdlib.h>
27 
28 #include "SDL_error.h"
29 #include "SDL_thread.h"
30 #include "../SDL_systhread.h"
31 #include "../SDL_thread_c.h"
32 #include <pspkerneltypes.h>
33 #include <pspthreadman.h>
34 
35 
36 static int ThreadEntry(SceSize args, void *argp)
37 {
38  SDL_RunThread(*(void **) argp);
39  return 0;
40 }
41 
43 {
44  SceKernelThreadInfo status;
45  int priority = 32;
46 
47  /* Set priority of new thread to the same as the current thread */
48  status.size = sizeof(SceKernelThreadInfo);
49  if (sceKernelReferThreadStatus(sceKernelGetThreadId(), &status) == 0) {
50  priority = status.currentPriority;
51  }
52 
53  thread->handle = sceKernelCreateThread("SDL thread", ThreadEntry,
54  priority, 0x8000,
55  PSP_THREAD_ATTR_VFPU, NULL);
56  if (thread->handle < 0) {
57  return SDL_SetError("sceKernelCreateThread() failed");
58  }
59 
60  sceKernelStartThread(thread->handle, 4, &args);
61  return 0;
62 }
63 
64 void SDL_SYS_SetupThread(const char *name)
65 {
66  /* Do nothing. */
67 }
68 
70 {
71  return (SDL_threadID) sceKernelGetThreadId();
72 }
73 
75 {
76  sceKernelWaitThreadEnd(thread->handle, NULL);
77  sceKernelDeleteThread(thread->handle);
78 }
79 
81 {
82  sceKernelTerminateDeleteThread(thread->handle);
83 }
84 
86 {
87  int value;
88 
89  if (priority == SDL_THREAD_PRIORITY_LOW) {
90  value = 19;
91  } else if (priority == SDL_THREAD_PRIORITY_HIGH) {
92  value = -20;
93  } else {
94  value = 0;
95  }
96 
97  return sceKernelChangeThreadPriority(sceKernelGetThreadId(),value);
98 
99 }
100 
101 /* vim: ts=4 sw=4
102  */
DECLSPEC SDL_threadID SDLCALL SDL_ThreadID(void)
Definition: SDL_systhread.c:48
unsigned long SDL_threadID
Definition: SDL_thread.h:49
#define NULL
Definition: ftobjs.h:61
EGLImageKHR EGLint * name
Definition: eglext.h:284
int SDL_SYS_CreateThread(SDL_Thread *thread, void *args)
Definition: SDL_systhread.c:42
void SDL_SYS_KillThread(SDL_Thread *thread)
Definition: SDL_systhread.c:80
void SDL_SYS_WaitThread(SDL_Thread *thread)
Definition: SDL_systhread.c:60
static int ThreadEntry(SceSize args, void *argp)
Definition: SDL_systhread.c:36
int SDL_SYS_SetThreadPriority(SDL_ThreadPriority priority)
Definition: SDL_systhread.c:54
DECLSPEC int SDLCALL SDL_SetError(const char *fmt,...)
Definition: SDL_error.c:53
static SDL_Thread * thread
SYS_ThreadHandle handle
Definition: SDL_thread_c.h:51
EGLSurface EGLint void ** value
Definition: eglext.h:301
void SDL_RunThread(void *data)
Definition: SDL_thread.c:263
void SDL_SYS_SetupThread(const char *name)
Definition: SDL_systhread.c:42
SDL_ThreadPriority
Definition: SDL_thread.h:59