#include "../../SDL_internal.h"
#if SDL_THREAD_OS2
#include "../../core/os2/SDL_os2.h"
#include "SDL_thread.h"
#include "../SDL_thread_c.h"
#define INCL_DOSPROCESS
#define INCL_DOSERRORS
#include <os2.h>
SDL_TLSData **ppSDLTLSData = NULL;
static ULONG cTLSAlloc = 0;
void SDL_OS2TLSAlloc(void)
{
ULONG ulRC;
if (cTLSAlloc == 0 || ppSDLTLSData == NULL) {
ulRC = DosAllocThreadLocalMemory(1, (PULONG *)&ppSDLTLSData);
if (ulRC != NO_ERROR) {
debug_os2("DosAllocThreadLocalMemory() failed, rc = %u", ulRC);
}
}
cTLSAlloc++;
}
void SDL_OS2TLSFree(void)
{
ULONG ulRC;
if (cTLSAlloc != 0)
cTLSAlloc--;
if (cTLSAlloc == 0 && ppSDLTLSData != NULL) {
ulRC = DosFreeThreadLocalMemory((PULONG)ppSDLTLSData);
if (ulRC != NO_ERROR) {
debug_os2("DosFreeThreadLocalMemory() failed, rc = %u", ulRC);
} else {
ppSDLTLSData = NULL;
}
}
}
SDL_TLSData *SDL_SYS_GetTLSData(void)
{
return (ppSDLTLSData == NULL)? NULL : *ppSDLTLSData;
}
int SDL_SYS_SetTLSData(SDL_TLSData *data)
{
if (!ppSDLTLSData)
return -1;
*ppSDLTLSData = data;
return 0;
}
#endif