SDL_thread_c.h 3.2 KB

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