Skip to content

Commit

Permalink
Fixed OS/2 build
Browse files Browse the repository at this point in the history
  • Loading branch information
slouken committed Jul 11, 2024
1 parent 5511648 commit 532a8c4
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 34 deletions.
7 changes: 0 additions & 7 deletions src/SDL.c
Original file line number Diff line number Diff line change
Expand Up @@ -200,10 +200,6 @@ int SDL_InitSubSystem(Uint32 flags)
SDL_DBus_Init();
#endif

#ifdef SDL_THREAD_OS2
SDL_OS2TLSAlloc(); /* thread/os2/SDL_systls.c */
#endif

#ifdef SDL_VIDEO_DRIVER_WINDOWS
if (flags & (SDL_INIT_HAPTIC | SDL_INIT_JOYSTICK)) {
if (SDL_HelperWindowCreate() < 0) {
Expand Down Expand Up @@ -380,9 +376,6 @@ int SDL_Init(Uint32 flags)
void SDL_QuitSubSystem(Uint32 flags)
{
#if defined(__OS2__)
#ifdef SDL_THREAD_OS2
SDL_OS2TLSFree(); /* thread/os2/SDL_systls.c */
#endif
SDL_OS2Quit();
#endif

Expand Down
46 changes: 19 additions & 27 deletions src/thread/os2/SDL_systls.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,45 +34,22 @@

SDL_TLSData **ppSDLTLSData = NULL;

static ULONG cTLSAlloc = 0;

/* SDL_OS2TLSAlloc() called from SDL_InitSubSystem() */
void SDL_OS2TLSAlloc(void)
void SDL_SYS_InitTLSData(void)
{
ULONG ulRC;

if (cTLSAlloc == 0 || !ppSDLTLSData) {
/* First call - allocate the thread local memory (1 DWORD) */
if (!ppSDLTLSData) {
/* Allocate the thread local memory (1 DWORD) */
ulRC = DosAllocThreadLocalMemory(1, (PULONG *)&ppSDLTLSData);
if (ulRC != NO_ERROR) {
debug_os2("DosAllocThreadLocalMemory() failed, rc = %u", ulRC);
}
}
cTLSAlloc++;
}

/* SDL_OS2TLSFree() called from SDL_QuitSubSystem() */
void SDL_OS2TLSFree(void)
{
ULONG ulRC;

if (cTLSAlloc != 0)
cTLSAlloc--;

if (cTLSAlloc == 0 && ppSDLTLSData) {
/* Last call - free the thread local memory */
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 : *ppSDLTLSData;
return ppSDLTLSData ? *ppSDLTLSData : NULL;
}

int SDL_SYS_SetTLSData(SDL_TLSData *data)
Expand All @@ -84,6 +61,21 @@ int SDL_SYS_SetTLSData(SDL_TLSData *data)
return 0;
}

void SDL_SYS_QuitTLSData(void)
{
ULONG ulRC;

if (ppSDLTLSData) {
/* Free the thread local memory */
ulRC = DosFreeThreadLocalMemory((PULONG)ppSDLTLSData);
if (ulRC != NO_ERROR) {
debug_os2("DosFreeThreadLocalMemory() failed, rc = %u", ulRC);
} else {
ppSDLTLSData = NULL;
}
}
}

#endif /* SDL_THREAD_OS2 */

/* vi: set ts=4 sw=4 expandtab: */

0 comments on commit 532a8c4

Please sign in to comment.