SDL_thread_c.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /*
  2. Simple DirectMedia Layer
  3. Copyright (C) 1997-2023 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. #include "SDL_thread.h"
  22. /* Need the definitions of SYS_ThreadHandle */
  23. #if SDL_THREADS_DISABLED
  24. #include "generic/SDL_systhread_c.h"
  25. #elif SDL_THREAD_PTHREAD
  26. #include "pthread/SDL_systhread_c.h"
  27. #elif SDL_THREAD_WINDOWS
  28. #include "windows/SDL_systhread_c.h"
  29. #elif SDL_THREAD_PS2
  30. #include "ps2/SDL_systhread_c.h"
  31. #elif SDL_THREAD_PSP
  32. #include "psp/SDL_systhread_c.h"
  33. #elif SDL_THREAD_VITA
  34. #include "vita/SDL_systhread_c.h"
  35. #elif SDL_THREAD_N3DS
  36. #include "n3ds/SDL_systhread_c.h"
  37. #elif SDL_THREAD_STDCPP
  38. #include "stdcpp/SDL_systhread_c.h"
  39. #elif SDL_THREAD_OS2
  40. #include "os2/SDL_systhread_c.h"
  41. #elif SDL_THREAD_NGAGE
  42. #include "ngage/SDL_systhread_c.h"
  43. #else
  44. #error Need thread implementation for this platform
  45. #include "generic/SDL_systhread_c.h"
  46. #endif
  47. #include "../SDL_error_c.h"
  48. typedef enum SDL_ThreadState
  49. {
  50. SDL_THREAD_STATE_ALIVE,
  51. SDL_THREAD_STATE_DETACHED,
  52. SDL_THREAD_STATE_ZOMBIE,
  53. SDL_THREAD_STATE_CLEANED,
  54. } SDL_ThreadState;
  55. /* This is the system-independent thread info structure */
  56. struct SDL_Thread
  57. {
  58. SDL_threadID threadid;
  59. SYS_ThreadHandle handle;
  60. int status;
  61. SDL_atomic_t state; /* SDL_THREAD_STATE_* */
  62. SDL_error errbuf;
  63. char *name;
  64. size_t stacksize; /* 0 for default, >0 for user-specified stack size. */
  65. int(SDLCALL *userfunc)(void *);
  66. void *userdata;
  67. void *data;
  68. void *endfunc; /* only used on some platforms. */
  69. };
  70. /* This is the function called to run a thread */
  71. extern void SDL_RunThread(SDL_Thread *thread);
  72. /* This is the system-independent thread local storage structure */
  73. typedef struct
  74. {
  75. unsigned int limit;
  76. struct
  77. {
  78. void *data;
  79. void(SDLCALL *destructor)(void *);
  80. } array[1];
  81. } SDL_TLSData;
  82. /* This is how many TLS entries we allocate at once */
  83. #define TLS_ALLOC_CHUNKSIZE 4
  84. /* Get cross-platform, slow, thread local storage for this thread.
  85. This is only intended as a fallback if getting real thread-local
  86. storage fails or isn't supported on this platform.
  87. */
  88. extern SDL_TLSData *SDL_Generic_GetTLSData(void);
  89. /* Set cross-platform, slow, thread local storage for this thread.
  90. This is only intended as a fallback if getting real thread-local
  91. storage fails or isn't supported on this platform.
  92. */
  93. extern int SDL_Generic_SetTLSData(SDL_TLSData *data);
  94. #endif /* SDL_thread_c_h_ */
  95. /* vi: set ts=4 sw=4 expandtab: */