src/thread/psp/SDL_systhread.c
author Sam Lantinga
Sat, 18 May 2013 14:17:52 -0700
changeset 7191 75360622e65f
parent 7037 3fedf1f25b94
child 7978 70ac84e49797
permissions -rw-r--r--
File style cleanup for the SDL 2.0 release
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
{
slouken@7191
    38
    SDL_RunThread(*(void **) argp);
slouken@7191
    39
    return 0;
kimonline@7009
    40
}
kimonline@7009
    41
kimonline@7009
    42
int SDL_SYS_CreateThread(SDL_Thread *thread, void *args)
kimonline@7009
    43
{
slouken@7191
    44
    SceKernelThreadInfo status;
slouken@7191
    45
    int priority = 32;
kimonline@7009
    46
slouken@7191
    47
    /* Set priority of new thread to the same as the current thread */
slouken@7191
    48
    status.size = sizeof(SceKernelThreadInfo);
slouken@7191
    49
    if (sceKernelReferThreadStatus(sceKernelGetThreadId(), &status) == 0) {
slouken@7191
    50
        priority = status.currentPriority;
slouken@7191
    51
    }
kimonline@7009
    52
slouken@7191
    53
    thread->handle = sceKernelCreateThread("SDL thread", ThreadEntry,
slouken@7191
    54
                           priority, 0x8000,
slouken@7191
    55
                           PSP_THREAD_ATTR_VFPU, NULL);
slouken@7191
    56
    if (thread->handle < 0) {
slouken@7191
    57
        return SDL_SetError("sceKernelCreateThread() failed");
slouken@7191
    58
    }
kimonline@7009
    59
slouken@7191
    60
    sceKernelStartThread(thread->handle, 4, &args);
slouken@7191
    61
    return 0;
kimonline@7009
    62
}
kimonline@7009
    63
kimonline@7009
    64
void SDL_SYS_SetupThread(const char *name)
kimonline@7009
    65
{
slouken@7191
    66
    /* Do nothing. */
kimonline@7009
    67
}
kimonline@7009
    68
kimonline@7009
    69
SDL_threadID SDL_ThreadID(void)
kimonline@7009
    70
{
slouken@7191
    71
    return (SDL_threadID) sceKernelGetThreadId();
kimonline@7009
    72
}
kimonline@7009
    73
kimonline@7009
    74
void SDL_SYS_WaitThread(SDL_Thread *thread)
kimonline@7009
    75
{
slouken@7191
    76
    sceKernelWaitThreadEnd(thread->handle, NULL);
slouken@7191
    77
    sceKernelDeleteThread(thread->handle);
kimonline@7009
    78
}
kimonline@7009
    79
kimonline@7009
    80
void SDL_SYS_KillThread(SDL_Thread *thread)
slouken@7191
    81
{
slouken@7191
    82
    sceKernelTerminateDeleteThread(thread->handle);
kimonline@7009
    83
}
kimonline@7009
    84
kimonline@7009
    85
int SDL_SYS_SetThreadPriority(SDL_ThreadPriority priority)
slouken@7191
    86
{
kimonline@7009
    87
    int value;
slouken@7191
    88
kimonline@7009
    89
    if (priority == SDL_THREAD_PRIORITY_LOW) {
kimonline@7009
    90
        value = 19;
kimonline@7009
    91
    } else if (priority == SDL_THREAD_PRIORITY_HIGH) {
kimonline@7009
    92
        value = -20;
kimonline@7009
    93
    } else {
kimonline@7009
    94
        value = 0;
kimonline@7009
    95
    }
slouken@7191
    96
kimonline@7009
    97
    return sceKernelChangeThreadPriority(sceKernelGetThreadId(),value);
kimonline@7009
    98
kimonline@7009
    99
}
kimonline@7009
   100
kimonline@7009
   101
/* vim: ts=4 sw=4
kimonline@7009
   102
 */