1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183
|
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
#include "../gsCommon.h"
// Begin of Threading for Revolution
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
gsi_u32 gsiInterlockedIncrement(gsi_u32 * value)
{
BOOL enabled = OSDisableInterrupts();
gsi_u32 ret = ++(*value);
OSRestoreInterrupts(enabled);
// return "ret" rather than "value" here b/c
// value may be modified by another thread
// before we can return it
return ret;
}
gsi_u32 gsiInterlockedDecrement(gsi_u32 * value)
{
BOOL state = OSDisableInterrupts();
gsi_u32 ret = --(*value);
OSRestoreInterrupts(state);
// return "ret" rather than "value" here b/c
// value may be modified by another thread
// before we can return it
return ret;
}
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
int gsiStartThread(GSThreadFunc aThreadFunc, gsi_u32 theStackSize, void *arg, GSIThreadID* theThreadIdOut)
{
char *aStackBase;
if(theStackSize % 32 != 0)
{
OSRoundUp32B(theStackSize);
}
theThreadIdOut->mStack = gsimalloc(theStackSize);
aStackBase = (char *)theThreadIdOut->mStack;
aStackBase += theStackSize;
OSCreateThread(&theThreadIdOut->mThread, aThreadFunc, arg, (void *)aStackBase,
theStackSize, 16, OS_THREAD_ATTR_DETACH);
OSResumeThread(&theThreadIdOut->mThread);
return 0;
}
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
void gsiCancelThread(GSIThreadID theThreadID)
{
OSCancelThread(&theThreadID.mThread);
if(theThreadID.mStack)
{
gsifree(theThreadID.mStack);
theThreadID.mStack = NULL;
}
}
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
void gsiCleanupThread(GSIThreadID theThreadID)
{
if (!OSIsThreadTerminated(&theThreadID.mThread))
OSCancelThread(&theThreadID.mThread);
if(theThreadID.mStack)
{
gsifree(theThreadID.mStack);
theThreadID.mStack = NULL;
}
}
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
gsi_u32 gsiHasThreadShutdown(GSIThreadID theThreadID)
{
BOOL shutdown = OSIsThreadTerminated(&theThreadID.mThread);
if(shutdown == TRUE)
return 1;
return 0;
}
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
void gsiInitializeCriticalSection(GSICriticalSection *theCrit)
{
OSInitMutex(theCrit);
}
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
void gsiEnterCriticalSection(GSICriticalSection *theCrit)
{
OSLockMutex(theCrit);
}
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
void gsiLeaveCriticalSection(GSICriticalSection *theCrit)
{
OSUnlockMutex(theCrit);
}
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
void gsiDeleteCriticalSection(GSICriticalSection *theCrit)
{
GSI_UNUSED(theCrit);
}
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
GSISemaphoreID gsiCreateSemaphore(gsi_i32 theInitialCount, gsi_i32 theMaxCount, char* theName)
{
GSISemaphoreID semaphore;
OSInitSemaphore(&semaphore, theInitialCount);
GSI_UNUSED(theName);
GSI_UNUSED(theMaxCount);
return semaphore;
}
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
gsi_u32 gsiWaitForSemaphore(GSISemaphoreID theSemaphore, gsi_u32 theTimeoutMs)
{
gsi_u32 retval = (unsigned int)OSWaitSemaphore(&theSemaphore);
GSI_UNUSED(theTimeoutMs);
return retval;
}
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
void gsiReleaseSemaphore(GSISemaphoreID theSemaphore, gsi_i32 theReleaseCount)
{
OSSignalSemaphore(&theSemaphore);
GSI_UNUSED(theReleaseCount);
}
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
void gsiCloseSemaphore(GSISemaphoreID theSemaphore)
{
GSI_UNUSED(theSemaphore);
}
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
void gsiExitThread(GSIThreadID theThreadID)
{
GSI_UNUSED(theThreadID);
}
// End of Threading for Revolution
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
|