SDL_systls.c 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /*
  2. Simple DirectMedia Layer
  3. Copyright (C) 1997-2024 Sam Lantinga <slouken@libsdl.org>
  4. This software is provided 'as-is', without any express or implied
  5. warranty. In no event will the authors be held liable for any damages
  6. arising from the use of this software.
  7. Permission is granted to anyone to use this software for any purpose,
  8. including commercial applications, and to alter it and redistribute it
  9. freely, subject to the following restrictions:
  10. 1. The origin of this software must not be misrepresented; you must not
  11. claim that you wrote the original software. If you use this software
  12. in a product, an acknowledgment in the product documentation would be
  13. appreciated but is not required.
  14. 2. Altered source versions must be plainly marked as such, and must not be
  15. misrepresented as being the original software.
  16. 3. This notice may not be removed or altered from any source distribution.
  17. */
  18. #include "../../SDL_internal.h"
  19. #ifdef SDL_THREAD_OS2
  20. #include "../../core/os2/SDL_os2.h"
  21. #include "SDL_thread.h"
  22. #include "../SDL_thread_c.h"
  23. #define INCL_DOSPROCESS
  24. #define INCL_DOSERRORS
  25. #include <os2.h>
  26. SDL_TLSData **ppSDLTLSData = NULL;
  27. void SDL_SYS_InitTLSData(void)
  28. {
  29. ULONG ulRC;
  30. if (!ppSDLTLSData) {
  31. /* Allocate the thread local memory (1 DWORD) */
  32. ulRC = DosAllocThreadLocalMemory(1, (PULONG *)&ppSDLTLSData);
  33. if (ulRC != NO_ERROR) {
  34. debug_os2("DosAllocThreadLocalMemory() failed, rc = %u", ulRC);
  35. }
  36. }
  37. }
  38. SDL_TLSData *SDL_SYS_GetTLSData(void)
  39. {
  40. return ppSDLTLSData ? *ppSDLTLSData : NULL;
  41. }
  42. int SDL_SYS_SetTLSData(SDL_TLSData *data)
  43. {
  44. if (!ppSDLTLSData)
  45. return -1;
  46. *ppSDLTLSData = data;
  47. return 0;
  48. }
  49. void SDL_SYS_QuitTLSData(void)
  50. {
  51. ULONG ulRC;
  52. if (ppSDLTLSData) {
  53. /* Free the thread local memory */
  54. ulRC = DosFreeThreadLocalMemory((PULONG)ppSDLTLSData);
  55. if (ulRC != NO_ERROR) {
  56. debug_os2("DosFreeThreadLocalMemory() failed, rc = %u", ulRC);
  57. } else {
  58. ppSDLTLSData = NULL;
  59. }
  60. }
  61. }
  62. #endif /* SDL_THREAD_OS2 */
  63. /* vi: set ts=4 sw=4 expandtab: */