RetroArch
Classes | Macros | Typedefs | Functions | Variables
psp_osal.c File Reference
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/time.h>
#include <sys/types.h>
#include <sys/timeb.h>
#include <pspkerror.h>
#include "pte_osal.h"
#include "../../pthread.h"
#include "../helper/tls-helper.h"
Include dependency graph for psp_osal.c:

Classes

struct  pspThreadData
 

Macros

#define MAX_PSP_UID   2048 /* SWAG */
 
#define DEFAULT_STACK_SIZE_BYTES   4096
 
#define PSP_MAX_TLS   32
 
#define PSP_DEBUG(x)   printf(x)
 

Typedefs

typedef struct pspThreadData pspThreadData
 

Functions

static pspThreadDatagetThreadData (SceUID threadHandle)
 
static voidgetTlsStructFromThread (SceUID thid)
 
int pspStubThreadEntry (unsigned int argc, void *argv)
 
pte_osResult pte_osInit (void)
 
pte_osResult pte_osThreadCreate (pte_osThreadEntryPoint entryPoint, int stackSize, int initialPriority, void *argv, pte_osThreadHandle *ppte_osThreadHandle)
 
pte_osResult pte_osThreadStart (pte_osThreadHandle osThreadHandle)
 
pte_osResult pte_osThreadDelete (pte_osThreadHandle handle)
 
pte_osResult pte_osThreadExitAndDelete (pte_osThreadHandle handle)
 
void pte_osThreadExit (void)
 
pte_osResult pte_osThreadWaitForEnd (pte_osThreadHandle threadHandle)
 
pte_osThreadHandle pte_osThreadGetHandle (void)
 
int pte_osThreadGetPriority (pte_osThreadHandle threadHandle)
 
pte_osResult pte_osThreadSetPriority (pte_osThreadHandle threadHandle, int newPriority)
 
pte_osResult pte_osThreadCancel (pte_osThreadHandle threadHandle)
 
pte_osResult pte_osThreadCheckCancel (pte_osThreadHandle threadHandle)
 
void pte_osThreadSleep (unsigned int msecs)
 
int pte_osThreadGetMinPriority (void)
 
int pte_osThreadGetMaxPriority (void)
 
int pte_osThreadGetDefaultPriority (void)
 
pte_osResult pte_osMutexCreate (pte_osMutexHandle *pHandle)
 
pte_osResult pte_osMutexDelete (pte_osMutexHandle handle)
 
pte_osResult pte_osMutexLock (pte_osMutexHandle handle)
 
pte_osResult pte_osMutexTimedLock (pte_osMutexHandle handle, unsigned int timeoutMsecs)
 
pte_osResult pte_osMutexUnlock (pte_osMutexHandle handle)
 
pte_osResult pte_osSemaphoreCreate (int initialValue, pte_osSemaphoreHandle *pHandle)
 
pte_osResult pte_osSemaphoreDelete (pte_osSemaphoreHandle handle)
 
pte_osResult pte_osSemaphorePost (pte_osSemaphoreHandle handle, int count)
 
pte_osResult pte_osSemaphorePend (pte_osSemaphoreHandle handle, unsigned int *pTimeoutMsecs)
 
pte_osResult pte_osSemaphoreCancellablePend (pte_osSemaphoreHandle semHandle, unsigned int *pTimeout)
 
int pte_osAtomicExchange (int *ptarg, int val)
 
int pte_osAtomicCompareExchange (int *pdest, int exchange, int comp)
 
int pte_osAtomicExchangeAdd (int volatile *pAddend, int value)
 
int pte_osAtomicDecrement (int *pdest)
 
int pte_osAtomicIncrement (int *pdest)
 
pte_osResult pte_osTlsSetValue (unsigned int key, void *value)
 
voidpte_osTlsGetValue (unsigned int index)
 
pte_osResult pte_osTlsAlloc (unsigned int *pKey)
 
pte_osResult pte_osTlsFree (unsigned int index)
 
int ftime (struct timeb *tb)
 

Variables

static unsigned int threadDataKey
 
static voidglobalTls
 

Macro Definition Documentation

◆ DEFAULT_STACK_SIZE_BYTES

#define DEFAULT_STACK_SIZE_BYTES   4096

◆ MAX_PSP_UID

#define MAX_PSP_UID   2048 /* SWAG */

◆ PSP_DEBUG

#define PSP_DEBUG (   x)    printf(x)

◆ PSP_MAX_TLS

#define PSP_MAX_TLS   32

Typedef Documentation

◆ pspThreadData

typedef struct pspThreadData pspThreadData

Function Documentation

◆ ftime()

int ftime ( struct timeb *  tb)

◆ getThreadData()

static pspThreadData * getThreadData ( SceUID  threadHandle)
static
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getTlsStructFromThread()

static void * getTlsStructFromThread ( SceUID  thid)
static
Here is the caller graph for this function:

◆ pspStubThreadEntry()

int pspStubThreadEntry ( unsigned int  argc,
void argv 
)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ pte_osAtomicCompareExchange()

int pte_osAtomicCompareExchange ( int *  pdest,
int  exchange,
int  comp 
)

Performs an atomic compare-and-exchange oepration on the specified value. That is:

origVal = *pdest
if (*pdest == comp)
then *pdest = exchange
return origVal
Parameters
pdestPointer to the destination value.
exchangeExchange value (value to set destination to if destination == comparand)
compThe value to compare to destination.
Returns
Original value of destination

◆ pte_osAtomicDecrement()

int pte_osAtomicDecrement ( int *  pdest)

Decrements the destination.

origVal = *pdest
*pdest++
return origVal
Parameters
pdestDestination value to decrement
Returns
Original destination value

◆ pte_osAtomicExchange()

int pte_osAtomicExchange ( int *  pTarg,
int  val 
)

Sets the target to the specified value as an atomic operation.

origVal = *ptarg
*ptarg = val
return origVal
Parameters
pTargPointer to the value to be exchanged.
valValue to be exchanged
Returns
original value of destination

◆ pte_osAtomicExchangeAdd()

int pte_osAtomicExchangeAdd ( int volatile *  pdest,
int  value 
)

Adds the value to target as an atomic operation

origVal = *pdest
*pAddend += value
return origVal
Parameters
pdestPointer to the variable to be updated.
valueValue to be added to the variable.
Returns
Original value of destination

◆ pte_osAtomicIncrement()

int pte_osAtomicIncrement ( int *  pdest)

◆ pte_osInit()

pte_osResult pte_osInit ( void  )

Provides a hook for the OSAL to implement any OS specific initialization. This is guaranteed to be called before any other OSAL function.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ pte_osMutexCreate()

pte_osResult pte_osMutexCreate ( pte_osMutexHandle pHandle)

Creates a mutex

Parameters
pHandleSet to the handle of the newly created mutex.
Returns
PTE_OS_OK - Mutex successfully created
PTE_OS_NO_RESOURCESs - Insufficient resources to create mutex
Here is the caller graph for this function:

◆ pte_osMutexDelete()

pte_osResult pte_osMutexDelete ( pte_osMutexHandle  handle)

Deletes a mutex and frees any associated resources.

Parameters
handleHandle of mutex to delete.
Returns
PTE_OS_OK - Mutex successfully deleted.
Here is the caller graph for this function:

◆ pte_osMutexLock()

pte_osResult pte_osMutexLock ( pte_osMutexHandle  handle)

Locks the mutex

Parameters
handleHandle of mutex to lock.
Returns
PTE_OS_OK - Mutex successfully locked.
Here is the caller graph for this function:

◆ pte_osMutexTimedLock()

pte_osResult pte_osMutexTimedLock ( pte_osMutexHandle  handle,
unsigned int  timeoutMsecs 
)

Locks the mutex, returning after timeoutMsecs if the resources is not available. Can be used for polling mutex by using timeoutMsecs of zero.

Parameters
handleHandle of mutex to lock.
timeoutMsecsNumber of milliseconds to wait for resource before returning.
Returns
PTE_OS_OK - Mutex successfully locked.
PTE_OS_TIMEOUT - Timeout expired before lock was obtained.

◆ pte_osMutexUnlock()

pte_osResult pte_osMutexUnlock ( pte_osMutexHandle  handle)

Unlocks the mutex

Parameters
handleHandle of mutex to unlock
Returns
PTE_OS_OK - Mutex successfully unlocked.
Here is the caller graph for this function:

◆ pte_osSemaphoreCancellablePend()

pte_osResult pte_osSemaphoreCancellablePend ( pte_osSemaphoreHandle  handle,
unsigned int *  pTimeout 
)

Acquire a semaphore, returning after timeoutMsecs if the semaphore is not available. Can be used for polling a semaphore by using timeoutMsecs of zero. Call must return immediately if pte_osThreadCancel() is called on the thread waiting for the semaphore.

Parameters
handleHandle of semaphore to acquire.
pTimeoutPointer to the number of milliseconds to wait to acquire the semaphore before returning. If set to NULL, wait forever.
Returns
PTE_OS_OK - Semaphore successfully acquired.
PTE_OS_TIMEOUT - Timeout expired before semaphore was obtained.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ pte_osSemaphoreCreate()

pte_osResult pte_osSemaphoreCreate ( int  initialValue,
pte_osSemaphoreHandle pHandle 
)

Creates a semaphore

Parameters
initialValueInitial value of the semaphore
pHandleSet to the handle of the newly created semaphore.
Returns
PTE_OS_OK - Semaphore successfully created
PTE_OS_NO_RESOURCESs - Insufficient resources to create semaphore
Here is the caller graph for this function:

◆ pte_osSemaphoreDelete()

pte_osResult pte_osSemaphoreDelete ( pte_osSemaphoreHandle  handle)

Deletes a semaphore and frees any associated resources.

Parameters
handleHandle of semaphore to delete.
Returns
PTE_OS_OK - Semaphore successfully deleted.
Here is the caller graph for this function:

◆ pte_osSemaphorePend()

pte_osResult pte_osSemaphorePend ( pte_osSemaphoreHandle  handle,
unsigned int *  pTimeout 
)

Acquire a semaphore, returning after timeoutMsecs if the semaphore is not available. Can be used for polling a semaphore by using timeoutMsecs of zero.

Parameters
handleHandle of semaphore to acquire.
pTimeoutPointer to the number of milliseconds to wait to acquire the semaphore before returning. If set to NULL, wait forever.
Returns
PTE_OS_OK - Semaphore successfully acquired.
PTE_OS_TIMEOUT - Timeout expired before semaphore was obtained.
Here is the caller graph for this function:

◆ pte_osSemaphorePost()

pte_osResult pte_osSemaphorePost ( pte_osSemaphoreHandle  handle,
int  count 
)

Posts to the semaphore

Parameters
handleSemaphore to release
countAmount to increment the semaphore by.
Returns
PTE_OS_OK - semaphore successfully released.
Here is the caller graph for this function:

◆ pte_osThreadCancel()

pte_osResult pte_osThreadCancel ( pte_osThreadHandle  threadHandle)

Cancels the specified thread. This should cause pte_osSemaphoreCancellablePend() and for pte_osThreadCheckCancel() to return PTE_OS_INTERRUPTED.

Parameters
threadHandlehandle to the thread to cancel.
Returns
Thread successfully canceled.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ pte_osThreadCheckCancel()

pte_osResult pte_osThreadCheckCancel ( pte_osThreadHandle  threadHandle)

Check if pte_osThreadCancel() has been called on the specified thread.

Parameters
threadHandlehandle of thread to check the state of.
Returns
PTE_OS_OK - Thread has not been cancelled
PTE_OS_INTERRUPTED - Thread has been cancelled.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ pte_osThreadCreate()

pte_osResult pte_osThreadCreate ( pte_osThreadEntryPoint  entryPoint,
int  stackSize,
int  initialPriority,
void argv,
pte_osThreadHandle ppte_osThreadHandle 
)

Creates a new thread. The thread must be started in a suspended state - it will be explicitly started when pte_osThreadStart() is called.

Parameters
entryPointEntry point to the new thread.
stackSizeThe initial stack size, in bytes. Note that this can be considered a minimum - for instance if the OS requires a larger stack space than what the caller specified.
initialPriorityThe priority that the new thread should be initially set to.
argvParameter to pass to the new thread.
ppte_osThreadHandleset to the handle of the new thread.
Returns
PTE_OS_OK - New thread successfully created.
PTE_OS_NO_RESOURCESs - Insufficient resources to create thread
Here is the call graph for this function:
Here is the caller graph for this function:

◆ pte_osThreadDelete()

pte_osResult pte_osThreadDelete ( pte_osThreadHandle  handle)

Frees resources associated with the specified thread. This is called after the thread has terminated and is no longer needed (e.g. after pthread_join returns). This call will always be made from a different context than that of the target thread.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ pte_osThreadExit()

void pte_osThreadExit ( )

Causes the current thread to stop executing.

Returns
Never returns (thread terminated)
Here is the caller graph for this function:

◆ pte_osThreadExitAndDelete()

pte_osResult pte_osThreadExitAndDelete ( pte_osThreadHandle  handle)

Frees resources associated with the specified thread and then causes the thread to exit. This is called after the thread has terminated and is no longer needed (e.g. after pthread_join returns). This call will always be made from the context of the target thread.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ pte_osThreadGetDefaultPriority()

int pte_osThreadGetDefaultPriority ( )

Returns the priority that should be used if the caller to pthread_create doesn't explicitly set one.

Here is the caller graph for this function:

◆ pte_osThreadGetHandle()

pte_osThreadHandle pte_osThreadGetHandle ( void  )

Returns the handle of the currently executing thread.

Here is the caller graph for this function:

◆ pte_osThreadGetMaxPriority()

int pte_osThreadGetMaxPriority ( )

Returns the maximum allowable priority

Here is the caller graph for this function:

◆ pte_osThreadGetMinPriority()

int pte_osThreadGetMinPriority ( )

Returns the minimum allowable priority

Here is the caller graph for this function:

◆ pte_osThreadGetPriority()

int pte_osThreadGetPriority ( pte_osThreadHandle  threadHandle)

Returns the priority of the specified thread.

◆ pte_osThreadSetPriority()

pte_osResult pte_osThreadSetPriority ( pte_osThreadHandle  threadHandle,
int  newPriority 
)

Sets the priority of the specified thread.

Returns
PTE_OS_OK - thread priority successfully set
Here is the caller graph for this function:

◆ pte_osThreadSleep()

void pte_osThreadSleep ( unsigned int  msecs)

Causes the current thread to sleep for the specified number of milliseconds.

Here is the caller graph for this function:

◆ pte_osThreadStart()

pte_osResult pte_osThreadStart ( pte_osThreadHandle  osThreadHandle)

Starts executing the specified thread.

Parameters
osThreadHandlehandle of the thread to start.
Returns
PTE_OS_OK - thread successfully started.
Here is the caller graph for this function:

◆ pte_osThreadWaitForEnd()

pte_osResult pte_osThreadWaitForEnd ( pte_osThreadHandle  threadHandle)

Waits for the specified thread to end. If the thread has already terminated, this returns immediately.

Parameters
threadHandleHandle fo thread to wait for.
Returns
PTE_OS_OK - specified thread terminated.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ pte_osTlsAlloc()

pte_osResult pte_osTlsAlloc ( unsigned int *  pKey)

Allocates a new TLS key.

Parameters
pKeyOn success will be set to the newly allocated key.
Returns
PTE_OS_OK - TLS key successfully allocated.
PTE_OS_NO_RESOURCESs - Insufficient resources to allocate key (e.g. maximum number of keys reached).
Here is the call graph for this function:
Here is the caller graph for this function:

◆ pte_osTlsFree()

pte_osResult pte_osTlsFree ( unsigned int  key)

Frees the specified TLS key.

Parameters
indexTLS key to free
Returns
PTE_OS_OK - TLS key was successfully freed.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ pte_osTlsGetValue()

void* pte_osTlsGetValue ( unsigned int  key)

Retrieves the thread specific value for the specified key for the currently executing thread. If a value has not been set for this key, NULL should be returned (i.e. TLS values default to NULL).

Parameters
indexThe TLS key for the value.
Returns
The value associated with key for the current thread.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ pte_osTlsSetValue()

pte_osResult pte_osTlsSetValue ( unsigned int  key,
void value 
)

Sets the thread specific value for the specified key for the currently executing thread.

Parameters
indexThe TLS key for the value.
valueThe value to save
Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ globalTls

void* globalTls
static

◆ threadDataKey

unsigned int threadDataKey
static