From 3b4b00cf5099e3720ae93bff17c7778389b5ff62 Mon Sep 17 00:00:00 2001 From: Yotam Barnoy Date: Tue, 3 Aug 2010 12:29:08 +0000 Subject: PSP: Factored out thread creation routines into PspThreadable class. This should aid in further optimizations. svn-id: r51685 --- backends/platform/psp/display_manager.cpp | 30 ++++++++---------------------- 1 file changed, 8 insertions(+), 22 deletions(-) (limited to 'backends/platform/psp/display_manager.cpp') diff --git a/backends/platform/psp/display_manager.cpp b/backends/platform/psp/display_manager.cpp index a9f33f6091..5037543f12 100644 --- a/backends/platform/psp/display_manager.cpp +++ b/backends/platform/psp/display_manager.cpp @@ -34,7 +34,6 @@ #include "backends/platform/psp/default_display_client.h" #include "backends/platform/psp/cursor.h" #include "backends/platform/psp/pspkeyboard.h" -#include "backends/platform/psp/thread.h" #define USE_DISPLAY_CALLBACK // to use callback for finishing the render #include "backends/platform/psp/display_manager.h" @@ -65,37 +64,24 @@ const OSystem::GraphicsMode DisplayManager::_supportedModes[] = { void MasterGuRenderer::setupCallbackThread() { DEBUG_ENTER_FUNC(); - int thid = sceKernelCreateThread("displayCbThread", guCallbackThread, PRIORITY_DISPLAY_THREAD, STACK_DISPLAY_THREAD, THREAD_ATTR_USER, 0); - PSP_DEBUG_PRINT("Display CB thread id is %x\n", thid); - - // We want to pass the pointer to this, but we'll have to take address of this so use a little trick - MasterGuRenderer *_this = this; - - if (thid >= 0) { - sceKernelStartThread(thid, sizeof(uint32 *), &_this); - } else - PSP_ERROR("failed to create display callback thread\n"); + // start the thread that updates the display + threadCreateAndStart("DisplayCbThread", PRIORITY_DISPLAY_THREAD, STACK_DISPLAY_THREAD); } -// thread that reacts to the callback -int MasterGuRenderer::guCallbackThread(SceSize, void *__this) { +// this function gets called by PspThread when starting the new thread +void MasterGuRenderer::threadFunction() { DEBUG_ENTER_FUNC(); - // Dereferenced the copied value which was this - MasterGuRenderer *_this = *(MasterGuRenderer **)__this; - // Create the callback. It should always get the pointer to MasterGuRenderer - _this->_callbackId = sceKernelCreateCallback("Display Callback", guCallback, _this); - if (_this->_callbackId < 0) { - PSP_ERROR("failed to create display callback\n"); - return -1; + _callbackId = sceKernelCreateCallback("Display Callback", guCallback, this); + if (_callbackId < 0) { + PSP_ERROR("failed to create display callback\n"); } PSP_DEBUG_PRINT("created callback. Going to sleep\n"); - sceKernelSleepThreadCB(); // sleep until we get a callback - return 0; + sceKernelSleepThreadCB(); // sleep until we get a callback } // This callback is called when the render is finished. It swaps the buffers -- cgit v1.2.3