cscg22-gearboy

CSCG 2022 Challenge 'Gearboy'
git clone https://git.sinitax.com/sinitax/cscg22-gearboy
Log | Files | Refs | sfeed.txt

SDL_systhread.c (2881B)


      1/*
      2  Simple DirectMedia Layer
      3  Copyright (C) 1997-2014 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
     36static int ThreadEntry(SceSize args, void *argp)
     37{
     38    SDL_RunThread(*(void **) argp);
     39    return 0;
     40}
     41
     42int SDL_SYS_CreateThread(SDL_Thread *thread, void *args)
     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
     64void SDL_SYS_SetupThread(const char *name)
     65{
     66    /* Do nothing. */
     67}
     68
     69SDL_threadID SDL_ThreadID(void)
     70{
     71    return (SDL_threadID) sceKernelGetThreadId();
     72}
     73
     74void SDL_SYS_WaitThread(SDL_Thread *thread)
     75{
     76    sceKernelWaitThreadEnd(thread->handle, NULL);
     77    sceKernelDeleteThread(thread->handle);
     78}
     79
     80void SDL_SYS_DetachThread(SDL_Thread *thread)
     81{
     82    /* !!! FIXME: is this correct? */
     83    sceKernelDeleteThread(thread->handle);
     84}
     85
     86void SDL_SYS_KillThread(SDL_Thread *thread)
     87{
     88    sceKernelTerminateDeleteThread(thread->handle);
     89}
     90
     91int SDL_SYS_SetThreadPriority(SDL_ThreadPriority priority)
     92{
     93    int value;
     94
     95    if (priority == SDL_THREAD_PRIORITY_LOW) {
     96        value = 19;
     97    } else if (priority == SDL_THREAD_PRIORITY_HIGH) {
     98        value = -20;
     99    } else {
    100        value = 0;
    101    }
    102
    103    return sceKernelChangeThreadPriority(sceKernelGetThreadId(),value);
    104
    105}
    106
    107/* vim: ts=4 sw=4
    108 */