src/thread/psp/SDL_systhread.c
author Captain Lex
Sun, 17 Mar 2013 20:07:02 +0800
changeset 7009 161b7b6a5303
child 7037 3fedf1f25b94
permissions -rw-r--r--
Add PSP support
kimonline@7009
     1
/*
kimonline@7009
     2
  Simple DirectMedia Layer
kimonline@7009
     3
  Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
kimonline@7009
     4
kimonline@7009
     5
  This software is provided 'as-is', without any express or implied
kimonline@7009
     6
  warranty.  In no event will the authors be held liable for any damages
kimonline@7009
     7
  arising from the use of this software.
kimonline@7009
     8
kimonline@7009
     9
  Permission is granted to anyone to use this software for any purpose,
kimonline@7009
    10
  including commercial applications, and to alter it and redistribute it
kimonline@7009
    11
  freely, subject to the following restrictions:
kimonline@7009
    12
kimonline@7009
    13
  1. The origin of this software must not be misrepresented; you must not
kimonline@7009
    14
     claim that you wrote the original software. If you use this software
kimonline@7009
    15
     in a product, an acknowledgment in the product documentation would be
kimonline@7009
    16
     appreciated but is not required.
kimonline@7009
    17
  2. Altered source versions must be plainly marked as such, and must not be
kimonline@7009
    18
     misrepresented as being the original software.
kimonline@7009
    19
  3. This notice may not be removed or altered from any source distribution.
kimonline@7009
    20
*/
kimonline@7009
    21
kimonline@7009
    22
kimonline@7009
    23
/* PSP thread management routines for SDL */
kimonline@7009
    24
kimonline@7009
    25
#include <stdio.h>
kimonline@7009
    26
#include <stdlib.h>
kimonline@7009
    27
kimonline@7009
    28
#include "SDL_error.h"
kimonline@7009
    29
#include "SDL_thread.h"
kimonline@7009
    30
#include "../SDL_systhread.h"
kimonline@7009
    31
#include "../SDL_thread_c.h"
kimonline@7009
    32
#include <pspkerneltypes.h>
kimonline@7009
    33
#include <pspthreadman.h>
kimonline@7009
    34
kimonline@7009
    35
kimonline@7009
    36
static int ThreadEntry(SceSize args, void *argp)
kimonline@7009
    37
{
kimonline@7009
    38
	SDL_RunThread(*(void **) argp);
kimonline@7009
    39
	return 0;
kimonline@7009
    40
}
kimonline@7009
    41
kimonline@7009
    42
int SDL_SYS_CreateThread(SDL_Thread *thread, void *args)
kimonline@7009
    43
{
kimonline@7009
    44
	SceKernelThreadInfo status;
kimonline@7009
    45
	int priority = 32;
kimonline@7009
    46
kimonline@7009
    47
	/* Set priority of new thread to the same as the current thread */
kimonline@7009
    48
	status.size = sizeof(SceKernelThreadInfo);
kimonline@7009
    49
	if (sceKernelReferThreadStatus(sceKernelGetThreadId(), &status) == 0) {
kimonline@7009
    50
		priority = status.currentPriority;
kimonline@7009
    51
	}
kimonline@7009
    52
kimonline@7009
    53
	thread->handle = sceKernelCreateThread("SDL thread", ThreadEntry, 
kimonline@7009
    54
					       priority, 0x8000, 
kimonline@7009
    55
					       PSP_THREAD_ATTR_VFPU, NULL);
kimonline@7009
    56
	if (thread->handle < 0) {
kimonline@7009
    57
		SDL_SetError("sceKernelCreateThread() failed");
kimonline@7009
    58
		return -1;
kimonline@7009
    59
	}
kimonline@7009
    60
kimonline@7009
    61
	sceKernelStartThread(thread->handle, 4, &args);
kimonline@7009
    62
	return 0;
kimonline@7009
    63
}
kimonline@7009
    64
kimonline@7009
    65
void SDL_SYS_SetupThread(const char *name)
kimonline@7009
    66
{
kimonline@7009
    67
	/* Do nothing. */
kimonline@7009
    68
}
kimonline@7009
    69
kimonline@7009
    70
SDL_threadID SDL_ThreadID(void)
kimonline@7009
    71
{
kimonline@7009
    72
	return (SDL_threadID) sceKernelGetThreadId();
kimonline@7009
    73
}
kimonline@7009
    74
kimonline@7009
    75
void SDL_SYS_WaitThread(SDL_Thread *thread)
kimonline@7009
    76
{
kimonline@7009
    77
	sceKernelWaitThreadEnd(thread->handle, NULL);
kimonline@7009
    78
	sceKernelDeleteThread(thread->handle);
kimonline@7009
    79
}
kimonline@7009
    80
kimonline@7009
    81
void SDL_SYS_KillThread(SDL_Thread *thread)
kimonline@7009
    82
{ 
kimonline@7009
    83
	sceKernelTerminateDeleteThread(thread->handle);
kimonline@7009
    84
}
kimonline@7009
    85
kimonline@7009
    86
int SDL_SYS_SetThreadPriority(SDL_ThreadPriority priority)
kimonline@7009
    87
{    
kimonline@7009
    88
    int value;
kimonline@7009
    89
    
kimonline@7009
    90
    if (priority == SDL_THREAD_PRIORITY_LOW) {
kimonline@7009
    91
        value = 19;
kimonline@7009
    92
    } else if (priority == SDL_THREAD_PRIORITY_HIGH) {
kimonline@7009
    93
        value = -20;
kimonline@7009
    94
    } else {
kimonline@7009
    95
        value = 0;
kimonline@7009
    96
    }
kimonline@7009
    97
    
kimonline@7009
    98
    return sceKernelChangeThreadPriority(sceKernelGetThreadId(),value);
kimonline@7009
    99
kimonline@7009
   100
}
kimonline@7009
   101
kimonline@7009
   102
/* vim: ts=4 sw=4
kimonline@7009
   103
 */