SDL_thread_c.h 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /*
  2. Simple DirectMedia Layer
  3. Copyright (C) 1997-2016 Sam Lantinga <[email protected]>
  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_PSP
  30. #include "psp/SDL_systhread_c.h"
  31. #elif SDL_THREAD_STDCPP
  32. #include "stdcpp/SDL_systhread_c.h"
  33. #else
  34. #error Need thread implementation for this platform
  35. #include "generic/SDL_systhread_c.h"
  36. #endif
  37. #include "../SDL_error_c.h"
  38. typedef enum SDL_ThreadState
  39. {
  40. SDL_THREAD_STATE_ALIVE,
  41. SDL_THREAD_STATE_DETACHED,
  42. SDL_THREAD_STATE_ZOMBIE,
  43. SDL_THREAD_STATE_CLEANED,
  44. } SDL_ThreadState;
  45. /* This is the system-independent thread info structure */
  46. struct SDL_Thread
  47. {
  48. SDL_threadID threadid;
  49. SYS_ThreadHandle handle;
  50. int status;
  51. SDL_atomic_t state; /* SDL_THREAD_STATE_* */
  52. SDL_error errbuf;
  53. char *name;
  54. size_t stacksize; /* 0 for default, >0 for user-specified stack size. */
  55. void *data;
  56. };
  57. /* This is the function called to run a thread */
  58. extern void SDL_RunThread(void *data);
  59. /* This is the system-independent thread local storage structure */
  60. typedef struct {
  61. unsigned int limit;
  62. struct {
  63. void *data;
  64. void (*destructor)(void*);
  65. } array[1];
  66. } SDL_TLSData;
  67. /* This is how many TLS entries we allocate at once */
  68. #define TLS_ALLOC_CHUNKSIZE 4
  69. /* Get cross-platform, slow, thread local storage for this thread.
  70. This is only intended as a fallback if getting real thread-local
  71. storage fails or isn't supported on this platform.
  72. */
  73. extern SDL_TLSData *SDL_Generic_GetTLSData(void);
  74. /* Set cross-platform, slow, thread local storage for this thread.
  75. This is only intended as a fallback if getting real thread-local
  76. storage fails or isn't supported on this platform.
  77. */
  78. extern int SDL_Generic_SetTLSData(SDL_TLSData *data);
  79. #endif /* _SDL_thread_c_h */
  80. /* vi: set ts=4 sw=4 expandtab: */