src/thread/psp/SDL_systhread.c
author Ryan C. Gordon
Mon, 23 Jan 2017 12:06:10 -0500
changeset 10837 c2f241c2f6ad
parent 10737 3406a0f8b041
child 11811 5d94cb6b24d3
permissions -rw-r--r--
audio: Fix same bug as last commit, but for _mm_bslli_si128 vs _mm_slli_si128.
kimonline@7009
     1
/*
kimonline@7009
     2
  Simple DirectMedia Layer
slouken@10737
     3
  Copyright (C) 1997-2017 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
*/
philipp@9328
    21
#include "../../SDL_internal.h"
kimonline@7009
    22
philipp@9329
    23
#if SDL_THREAD_PSP
philipp@9329
    24
kimonline@7009
    25
/* PSP thread management routines for SDL */
kimonline@7009
    26
kimonline@7009
    27
#include <stdio.h>
kimonline@7009
    28
#include <stdlib.h>
kimonline@7009
    29
kimonline@7009
    30
#include "SDL_error.h"
kimonline@7009
    31
#include "SDL_thread.h"
kimonline@7009
    32
#include "../SDL_systhread.h"
kimonline@7009
    33
#include "../SDL_thread_c.h"
kimonline@7009
    34
#include <pspkerneltypes.h>
kimonline@7009
    35
#include <pspthreadman.h>
kimonline@7009
    36
kimonline@7009
    37
kimonline@7009
    38
static int ThreadEntry(SceSize args, void *argp)
kimonline@7009
    39
{
slouken@7191
    40
    SDL_RunThread(*(void **) argp);
slouken@7191
    41
    return 0;
kimonline@7009
    42
}
kimonline@7009
    43
kimonline@7009
    44
int SDL_SYS_CreateThread(SDL_Thread *thread, void *args)
kimonline@7009
    45
{
slouken@7191
    46
    SceKernelThreadInfo status;
slouken@7191
    47
    int priority = 32;
kimonline@7009
    48
slouken@7191
    49
    /* Set priority of new thread to the same as the current thread */
slouken@7191
    50
    status.size = sizeof(SceKernelThreadInfo);
slouken@7191
    51
    if (sceKernelReferThreadStatus(sceKernelGetThreadId(), &status) == 0) {
slouken@7191
    52
        priority = status.currentPriority;
slouken@7191
    53
    }
kimonline@7009
    54
icculus@10145
    55
    thread->handle = sceKernelCreateThread(thread->name, ThreadEntry,
philipp@10151
    56
                           priority, thread->stacksize ? ((int) thread->stacksize) : 0x8000,
slouken@7191
    57
                           PSP_THREAD_ATTR_VFPU, NULL);
slouken@7191
    58
    if (thread->handle < 0) {
slouken@7191
    59
        return SDL_SetError("sceKernelCreateThread() failed");
slouken@7191
    60
    }
kimonline@7009
    61
slouken@7191
    62
    sceKernelStartThread(thread->handle, 4, &args);
slouken@7191
    63
    return 0;
kimonline@7009
    64
}
kimonline@7009
    65
kimonline@7009
    66
void SDL_SYS_SetupThread(const char *name)
kimonline@7009
    67
{
slouken@7191
    68
    /* Do nothing. */
kimonline@7009
    69
}
kimonline@7009
    70
kimonline@7009
    71
SDL_threadID SDL_ThreadID(void)
kimonline@7009
    72
{
slouken@7191
    73
    return (SDL_threadID) sceKernelGetThreadId();
kimonline@7009
    74
}
kimonline@7009
    75
kimonline@7009
    76
void SDL_SYS_WaitThread(SDL_Thread *thread)
kimonline@7009
    77
{
slouken@7191
    78
    sceKernelWaitThreadEnd(thread->handle, NULL);
slouken@7191
    79
    sceKernelDeleteThread(thread->handle);
kimonline@7009
    80
}
kimonline@7009
    81
icculus@7978
    82
void SDL_SYS_DetachThread(SDL_Thread *thread)
icculus@7978
    83
{
icculus@7978
    84
    /* !!! FIXME: is this correct? */
icculus@7978
    85
    sceKernelDeleteThread(thread->handle);
icculus@7978
    86
}
icculus@7978
    87
kimonline@7009
    88
void SDL_SYS_KillThread(SDL_Thread *thread)
slouken@7191
    89
{
slouken@7191
    90
    sceKernelTerminateDeleteThread(thread->handle);
kimonline@7009
    91
}
kimonline@7009
    92
kimonline@7009
    93
int SDL_SYS_SetThreadPriority(SDL_ThreadPriority priority)
slouken@7191
    94
{
kimonline@7009
    95
    int value;
slouken@7191
    96
kimonline@7009
    97
    if (priority == SDL_THREAD_PRIORITY_LOW) {
kimonline@7009
    98
        value = 19;
kimonline@7009
    99
    } else if (priority == SDL_THREAD_PRIORITY_HIGH) {
kimonline@7009
   100
        value = -20;
kimonline@7009
   101
    } else {
kimonline@7009
   102
        value = 0;
kimonline@7009
   103
    }
slouken@7191
   104
kimonline@7009
   105
    return sceKernelChangeThreadPriority(sceKernelGetThreadId(),value);
kimonline@7009
   106
kimonline@7009
   107
}
kimonline@7009
   108
philipp@9329
   109
#endif /* SDL_THREAD_PSP */
philipp@9329
   110
kimonline@7009
   111
/* vim: ts=4 sw=4
kimonline@7009
   112
 */