SDL_thread_c.h 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /*
  2. Simple DirectMedia Layer
  3. Copyright (C) 1997-2025 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. #else
  37. #error Need thread implementation for this platform
  38. #include "generic/SDL_systhread_c.h"
  39. #endif
  40. #include "../SDL_error_c.h"
  41. // This is the system-independent thread info structure
  42. struct SDL_Thread
  43. {
  44. SDL_ThreadID threadid;
  45. SYS_ThreadHandle handle;
  46. int status;
  47. SDL_AtomicInt state; /* SDL_ThreadState */
  48. SDL_error errbuf;
  49. char *name;
  50. size_t stacksize; // 0 for default, >0 for user-specified stack size.
  51. int(SDLCALL *userfunc)(void *);
  52. void *userdata;
  53. void *data;
  54. SDL_FunctionPointer endfunc; // only used on some platforms.
  55. };
  56. // This is the function called to run a thread
  57. extern void SDL_RunThread(SDL_Thread *thread);
  58. // This is the system-independent thread local storage structure
  59. typedef struct
  60. {
  61. int limit;
  62. struct
  63. {
  64. void *data;
  65. void(SDLCALL *destructor)(void *);
  66. } array[1];
  67. } SDL_TLSData;
  68. // This is how many TLS entries we allocate at once
  69. #define TLS_ALLOC_CHUNKSIZE 4
  70. extern void SDL_InitTLSData(void);
  71. extern void SDL_QuitTLSData(void);
  72. /* Generic TLS support.
  73. This is only intended as a fallback if getting real thread-local
  74. storage fails or isn't supported on this platform.
  75. */
  76. extern void SDL_Generic_InitTLSData(void);
  77. extern SDL_TLSData *SDL_Generic_GetTLSData(void);
  78. extern bool SDL_Generic_SetTLSData(SDL_TLSData *data);
  79. extern void SDL_Generic_QuitTLSData(void);
  80. #endif // SDL_thread_c_h_