SDL_thread_c.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /*
  2. Simple DirectMedia Layer
  3. Copyright (C) 1997-2026 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. #ifndef SDL_thread_c_h_
  20. #define SDL_thread_c_h_
  21. // Need the definitions of SYS_ThreadHandle
  22. #ifdef SDL_THREADS_DISABLED
  23. #include "generic/SDL_systhread_c.h"
  24. #elif defined(SDL_THREAD_PTHREAD)
  25. #include "pthread/SDL_systhread_c.h"
  26. #elif defined(SDL_THREAD_WINDOWS)
  27. #include "windows/SDL_systhread_c.h"
  28. #elif defined(SDL_THREAD_PS2)
  29. #include "ps2/SDL_systhread_c.h"
  30. #elif defined(SDL_THREAD_PSP)
  31. #include "psp/SDL_systhread_c.h"
  32. #elif defined(SDL_THREAD_VITA)
  33. #include "vita/SDL_systhread_c.h"
  34. #elif defined(SDL_THREAD_N3DS)
  35. #include "n3ds/SDL_systhread_c.h"
  36. #elif defined(SDL_THREAD_DOS)
  37. #include "dos/SDL_systhread_c.h"
  38. #else
  39. #error Need thread implementation for this platform
  40. #include "generic/SDL_systhread_c.h"
  41. #endif
  42. #include "../SDL_error_c.h"
  43. // This is the system-independent thread info structure
  44. struct SDL_Thread
  45. {
  46. SDL_ThreadID threadid;
  47. SYS_ThreadHandle handle;
  48. int status;
  49. SDL_AtomicInt state; /* SDL_ThreadState */
  50. SDL_error errbuf;
  51. char *name;
  52. size_t stacksize; // 0 for default, >0 for user-specified stack size.
  53. int(SDLCALL *userfunc)(void *);
  54. void *userdata;
  55. void *data;
  56. SDL_FunctionPointer endfunc; // only used on some platforms.
  57. };
  58. // This is the function called to run a thread
  59. extern void SDL_RunThread(SDL_Thread *thread);
  60. // This is the system-independent thread local storage structure
  61. typedef struct
  62. {
  63. int limit;
  64. #ifdef _MSC_VER
  65. #pragma warning(push)
  66. #pragma warning(disable : 4200) // Flexible array members (C99)
  67. #endif
  68. struct
  69. {
  70. void *data;
  71. void(SDLCALL *destructor)(void *);
  72. } array[];
  73. #ifdef _MSC_VER
  74. #pragma warning(pop)
  75. #endif
  76. } SDL_TLSData;
  77. // This is how many TLS entries we allocate at once
  78. #define TLS_ALLOC_CHUNKSIZE 4
  79. extern void SDL_InitTLSData(void);
  80. extern void SDL_QuitTLSData(void);
  81. /* Generic TLS support.
  82. This is only intended as a fallback if getting real thread-local
  83. storage fails or isn't supported on this platform.
  84. */
  85. extern void SDL_Generic_InitTLSData(void);
  86. extern SDL_TLSData *SDL_Generic_GetTLSData(void);
  87. extern bool SDL_Generic_SetTLSData(SDL_TLSData *data);
  88. extern void SDL_Generic_QuitTLSData(void);
  89. #endif // SDL_thread_c_h_