SDL  2.0
SDL_systls.c
Go to the documentation of this file.
1 /*
2  Simple DirectMedia Layer
3  Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
4 
5  This software is provided 'as-is', without any express or implied
6  warranty. In no event will the authors be held liable for any damages
7  arising from the use of this software.
8 
9  Permission is granted to anyone to use this software for any purpose,
10  including commercial applications, and to alter it and redistribute it
11  freely, subject to the following restrictions:
12 
13  1. The origin of this software must not be misrepresented; you must not
14  claim that you wrote the original software. If you use this software
15  in a product, an acknowledgment in the product documentation would be
16  appreciated but is not required.
17  2. Altered source versions must be plainly marked as such, and must not be
18  misrepresented as being the original software.
19  3. This notice may not be removed or altered from any source distribution.
20 */
21 
22 #include "../../SDL_internal.h"
23 
24 #if SDL_THREAD_OS2
25 
26 #include "../../core/os2/SDL_os2.h"
27 
28 #include "SDL_thread.h"
29 #include "../SDL_thread_c.h"
30 
31 #define INCL_DOSPROCESS
32 #define INCL_DOSERRORS
33 #include <os2.h>
34 
35 SDL_TLSData **ppSDLTLSData = NULL;
36 
37 static ULONG cTLSAlloc = 0;
38 
39 /* SDL_OS2TLSAlloc() called from SDL_InitSubSystem() */
40 void SDL_OS2TLSAlloc(void)
41 {
42  ULONG ulRC;
43 
44  if (cTLSAlloc == 0 || ppSDLTLSData == NULL) {
45  /* First call - allocate the thread local memory (1 DWORD) */
46  ulRC = DosAllocThreadLocalMemory(1, (PULONG *)&ppSDLTLSData);
47  if (ulRC != NO_ERROR) {
48  debug_os2("DosAllocThreadLocalMemory() failed, rc = %u", ulRC);
49  }
50  }
51  cTLSAlloc++;
52 }
53 
54 /* SDL_OS2TLSFree() called from SDL_QuitSubSystem() */
55 void SDL_OS2TLSFree(void)
56 {
57  ULONG ulRC;
58 
59  if (cTLSAlloc != 0)
60  cTLSAlloc--;
61 
62  if (cTLSAlloc == 0 && ppSDLTLSData != NULL) {
63  /* Last call - free the thread local memory */
64  ulRC = DosFreeThreadLocalMemory((PULONG)ppSDLTLSData);
65  if (ulRC != NO_ERROR) {
66  debug_os2("DosFreeThreadLocalMemory() failed, rc = %u", ulRC);
67  } else {
68  ppSDLTLSData = NULL;
69  }
70  }
71 }
72 
74 {
75  return (ppSDLTLSData == NULL)? NULL : *ppSDLTLSData;
76 }
77 
79 {
80  if (!ppSDLTLSData)
81  return -1;
82 
83  *ppSDLTLSData = data;
84  return 0;
85 }
86 
87 #endif /* SDL_THREAD_OS2 */
88 
89 /* vi: set ts=4 sw=4 expandtab: */
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: SDL_opengl.h:1974
#define debug_os2(s,...)
Definition: SDL_os2.h:38
#define NULL
Definition: begin_code.h:163
int SDL_SYS_SetTLSData(SDL_TLSData *data)
Definition: SDL_systls.c:33
SDL_TLSData * SDL_SYS_GetTLSData(void)
Definition: SDL_systls.c:27